前提说明:
1、zookeeper的使用依赖JDK,所以安装的时候,需要确认你已安装、配置好JDK。JDK安装
2、由于zookeeper的leader选举机制,所以在这里搭建了3台虚拟机
3、zookeeper的版本使用3.4.6版,下载路径
4、确保每台虚拟机配置好ssh协议 配置ssh免密登录
集群搭建
一、设置hosts
设置每台虚拟机的ip-主机名映射
[hadoop01@mini1 ~]$ vim /etc/hosts
192.168.110.111 mini1
192.168.110.112 mini2
192.168.110.113 mini3
[hadoop01@mini1 ~]$ tar zxvf zookeeper-3.4.6.tar.gz
三、进入zookeeper的conf中,将zoo_sample.cfg文件重命名为zoo.cfg,并修改内容
[hadoop01@mini1 zkdata]$ cd ~/zookeeper-3.4.6/conf/
[hadoop01@mini1 conf]$ mv zoo_sample.cfg zoo.cfg
[hadoop01@mini1 conf]$ vim zoo.cfg
修改、添加以下内容:
dataDir=/home/hadoop01/zookeeper-3.4.6/tmp/zkdata #data存储位置,路径确定存在
dataLogDir=/home/hadoop01/zookeeper-3.4.6/tmp/zkdatalog #log日志存储位置,路径确定存在
server.1=mini1:2888:3888 # 和主机名修改为你hosts文件
server.2=mini2:2888:3888
server.3=mini3:2888:3888
四、将myid写入你设置的dataDir路径下
[hadoop01@mini1 ~]$ echo "1" > /home/hadoop01/zookeeper-3.4.6/tmp/zkdata/myid
五、将配置好的文件,发到mini2、mini3虚拟机上
[hadoop01@mini1 ~]$ scp -r zookeeper-3.4.6/ mini2:/$PWD
[hadoop01@mini1 ~]$ scp -r zookeeper-3.4.6/ mini3:/$PWD
六、在mini2、mini3机器上修改myid
[hadoop01@mini2 ~]$ echo "2" > /home/hadoop01/zookeeper-3.4.6/tmp/zkdata/myid #mini2机器上操作
[hadoop01@mini3 ~]$ echo "3" > /home/hadoop01/zookeeper-3.4.6/tmp/zkdata/myid #mini3机器上操作
[hadoop01@mini1 bin]$ ./zkServer.sh start
[hadoop01@mini2 bin]$ ./zkServer.sh start
[hadoop01@mini3 bin]$ ./zkServer.sh start
八、查询每台机器zookeeper的启动状态,发现mini2为领导者,mini1、mini3为小弟
[hadoop01@mini1 bin]$ ./zkServer.sh status
JMX enabled by default
Using config: /home/hadoop01/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
[hadoop01@mini2 bin]$ ./zkServer.sh status
JMX enabled by default
Using config: /home/hadoop01/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader
[hadoop01@mini3 bin]$ ./zkServer.sh status
JMX enabled by default
Using config: /home/hadoop01/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower