下载解压zookeeper压缩包:zookeeper-3.4.5.tar.gz
# tar -zxvf zookeeper -C/data/zookeeper
# cd /data/zookeeper/conf
# cp zoo_sample.cfgzoo.cfg
# vi zoo.cfg
dataDir=/data/zookeeper/zkData
server.1=Master:2888:3888
server.2=Slave1:2888:3888
server.3=Slave2:2888:3888
然后创建一个tmp文件夹
[root@Master local]#mkdir/data/zookeeper/zkData
再创建一个空文件
[root@Master local]#touch/data/zookeeper/zkData/myid
最后向该文件写入ID
[root@Master local]#echo 1> /data/zookeeper/zkData/myid
将配置好的zookeeper拷贝到其他节点(首先分别在Slave1、Slave2根目录:/data/)
[root@Master local]#scp -r/data/zookeeper/ Slave1:/data/
[root@Master local]#scp -r/data/zookeeper/ Slave2:/data/
注意:修改Slave1、Slave2对应/data/zookeeper/zkData/myid内容
Slave1:
[root@Master local]#echo 2> /data/zookeeper/zkData/myid
Slave2:
[root@Master local]#echo 3> /data/zookeeper/zkData/myid
启动每台三台主机zookeeper服务:
/opt/zookeeper/bin/zkServer.shstart
查看状态:
/opt/zookeeper/bin/zkServer.shstatus
设置开机启动
# touch /etc/rc.d/init.d/zookeeper
# vi/etc/rc.d/init.d/zookeeper
插入以下脚本:
#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
case $1 in
start) su root/data/zookeeper/bin/zkServer.sh start;;
stop) su root /data/zookeeper/bin/zkServer.shstop;;
status) su root/data/zookeeper/bin/zkServer.sh status;;
restart) su root/data/zookeeper/bin/zkServer.sh restart;;
*)echo "require start|stop|status|restart" ;;
esac
退出保存。
验证是否生效:service zookeeperstart/stop
设置开机启动:chkconfig --add zookeeper
查看自启动列表:chkconfig --list