大数据

zookeeper-3.4.12完全分布式搭搭建

2018-11-30  本文已影响0人  57山本无忧

安装JDK

请参考:Linux下快速安装JDK

一、虚拟机环境准备

主机名称 IP
zookeeper1 192.168.200.61
zookeeper2 192.168.200.62
zookeeper3 192.168.200.63
192.168.200.61 zookeeper1
192.168.200.62 zookeeper2
192.168.200.63 zookeeper3

二、创建zk用户以及准备安装环境【3台都执行】

[root@zookeeper1 ~]# useradd zk
[root@zookeeper1 ~]# echo 123456 | passwd --stdin zk
[root@zookeeper1 ~]# mkdir /app
[root@zookeeper1 ~]# chown -R zk:zk /app

三、安装zk【zookeeper1上执行】

[root@zookeeper1 ~]# su - zk

3.1 解压安装

[zk@zookeeper1 ~]$cd /app
[zk@zookeeper1 app]$wget http://archive.apache.org/dist/zookeeper/stable/zookeeper-3.4.12.tar.gz
[zk@zookeeper1 app]$tar zxf zookeeper-3.4.12.tar.gz
[zk@zookeeper1 app]$ln -s zookeeper-3.4.12 zookeeper

3.2 配置环境变量【三台都执行】

[zk@zookeeper1 app]$ echo -e  '##########ZK环境变量配置##########\nexport ZOOKEEPER_HOME=/app/zookeeper\nexport PATH=$ZOOKEEPER_HOME/bin:$PATH' >> /home/zk/.bash_profile
[zk@zookeeper1 app]$ source /home/zk/.bash_profile
[zk@zookeeper1 app]$ tail -3 /home/zk/.bash_profile

3.3 拷贝并配置zoo.cfg

[zk@zookeeper1 app]$ cp /app/zookeeper/conf/zoo_sample.cfg /app/zookeeper/conf/zoo.cfg
[zk@zookeeper1 app]$ mkdir /app/zkDataDir
[zk@zookeeper1 app]$ sed -i 's#dataDir=/tmp/zookeeper#dataDir=/app/zkDataDir#g' /app/zookeeper/conf/zoo.cfg
[zk@zookeeper1 app]$ grep '/app/zkDataDir' /app/zookeeper/conf/zoo.cfg
[zk@zookeeper1 app]$ echo -e 'server.1 = zookeeper1:2888:3888\nserver.2 = zookeeper2:2888:3888\nserver.3 = zookeeper3:2888:3888' >>/app/zookeeper/conf/zoo.cfg 
[zk@zookeeper1 app]$ tail -3 /app/zookeeper/conf/zoo.cfg
[zk@zookeeper1 app]$ grep ^[a-z] /app/zookeeper/conf/zoo.cfg 
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/app/zkDataDir
clientPort=2181
server.1 = zookeeper1:2888:3888
server.2 = zookeeper2:2888:3888
server.3 = zookeeper3:2888:3888

四、分发安装文件

在zookeeper1上执行,将安装文件分发到zookeeper2、zookeeper3主机上

[zk@zookeeper1 app]$ ll /app
total 8
drwxrwxr-x  2 zk zk 4096 Nov 30 15:53 zkDataDir
lrwxrwxrwx  1 zk zk   16 Nov 30 15:40 zookeeper -> zookeeper-3.4.12
drwxr-xr-x 10 zk zk 4096 Mar 27  2018 zookeeper-3.4.12
[zk@zookeeper1 app]$ rsync -lr z* zk@zookeeper2:/app
[zk@zookeeper1 app]$ rsync -lr z* zk@zookeeper3:/app

五、配置zookeeper在集群中的id

[zk@zookeeper1 app]$ echo '1'>/app/zkDataDir/myid
[zk@zookeeper2 app]$ echo '2'>/app/zkDataDir/myid
[zk@zookeeper3 app]$ echo '3'>/app/zkDataDir/myid

六、启动集群

[zk@zookeeper1 ~]$ zkServer.sh start

ZooKeeper JMX enabled by default
Using config: /app/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[zk@zookeeper1 ~]$ zkServer.sh status
...
Mode: follower
[zk@zookeeper2 ~]$ zkServer.sh status
...
Mode: follower
[zk@zookeeper3 ~]$ zkServer.sh status
...
Mode: leader
上一篇下一篇

猜你喜欢

热点阅读