下载并上传
zookeeper-3.5.3-beta.tar.gz
到各个服务器的/soft/zookeeper目录,或者使用wget命令,如下:
cd /soft/zookeeperwget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.3-beta/zookeeper-3.5.3-beta.tar.gztar -xvf zookeeper-3.5.3-beta.tar.gz
在各个服务器上解压zookeeper安装包,并按节点号对zookeeper目录重命名
# 服务器1cp -r zookeeper-3.5.3 zookeeper-3.5.3_1# 服务器2cp -r zookeeper-3.5.3 zookeeper-3.5.3_2# 服务器3cp -r zookeeper-3.5.3 zookeeper-3.5.3_3
在各zookeeper节点目录下创建以下目录
cd /soft/zookeeper/zookeeper-3.5.3_1mkdir datamkdir logscd /soft/zookeeper/zookeeper-3.5.3_2mkdir datamkdir logscd /soft/zookeeper/zookeeper-3.5.3_3mkdir datamkdir logs
将各节点zookeeper/zookeeper-3.5.3_x/conf目录下的zoo_sample.cfg文件拷贝一份,命名为zoo.cfg:
cd /soft/zookeeper/zookeeper-3.5.3_1/confcp zoo_sample.cfg zoo.cfgcd /soft/zookeeper/zookeeper-3.5.3_2/confcp zoo_sample.cfg zoo.cfgcd /soft/zookeeper/zookeeper-3.5.3_3/confcp zoo_sample.cfg zoo.cfg
修改 zoo.cfg 配置文件
ip:192.168.159.128(虚拟机ip)
cd /soft/zookeeper/zookeeper-3.5.3_1/conf# 设置内容如下:tickTime=2000initLimit=10syncLimit=5dataDir=/soft/zookeeper/zookeeper-3.5.3_1/datadataLogDir=/soft/zookeeper/zookeeper-3.5.3_1/logsclientPort=2181server.1=192.168.159.128:2881:3881server.2=192.168.159.128:2882:3882server.3=192.168.159.128:2883:3883# -----------------------------------cd /soft/zookeeper/zookeeper-3.5.3_2/confvi zoo.cfg# 设置内容如下:tickTime=2000initLimit=10syncLimit=5dataDir=/soft/zookeeper/zookeeper-3.5.3_2/datadataLogDir=/soft/zookeeper/zookeeper-3.5.3_2/logsclientPort=2182server.1=192.168.159.128:2881:3881server.2=192.168.159.128:2882:3882server.3=192.168.159.128:2883:3883# -----------------------------------cd /soft/zookeeper/zookeeper-3.5.3_3/confvi zoo.cfg# 设置内容如下:tickTime=2000initLimit=10syncLimit=5dataDir=/soft/zookeeper/zookeeper-3.5.3_3/datadataLogDir=/soft/zookeeper/zookeeper-3.5.3_3/logsclientPort=2183server.1=192.168.159.128:2881:3881server.2=192.168.159.128:2882:3882server.3=192.168.159.128:2883:3883
在dataDir=/soft/zookeeper/zookeeper-3.5.3_x/data下创建 myid 文件
vi /soft/zookeeper/zookeeper-3.5.3_1/data/myid #设置值为1vi /soft/zookeeper/zookeeper-3.5.3_2/data/myid #设置值为2vi /soft/zookeeper/zookeeper-3.5.3_3/data/myid #设置值为3
启动并查看zookeeper:
cd /soft/zookeeper/soft/zookeeper/zookeeper-3.5.3_1/bin/zkServer.sh start/soft/zookeeper/zookeeper-3.5.3_2/bin/zkServer.sh start/soft/zookeeper/zookeeper-3.5.3_3/bin/zkServer.sh start
验证zookeeper启动情况
/soft/zookeeper/zookeeper-3.5.3_1/bin/zkServer.sh status/soft/zookeeper/zookeeper-3.5.3_2/bin/zkServer.sh status/soft/zookeeper/zookeeper-3.5.3_3/bin/zkServer.sh status
- 如果启动成功,三台机器结果类似如下,标红部分为一个leader,两个follower:
[root@centos7 local]# /soft/zookeeper/zookeeper-3.5.3_1/bin/zkServer.sh statusJMX enabled by defaultUsing config: /soft/zookeeper/zookeeper-3.5.3_1/bin/../conf/zoo.cfgMode: "follower"[root@centos7 local]# /soft/zookeeper/zookeeper-3.5.3_2/bin/zkServer.sh statusJMX enabled by defaultUsing config: /soft/zookeeper/zookeeper-3.5.3_2/bin/../conf/zoo.cfgMode: "leader"[root@centos7 local]# /soft/zookeeper/zookeeper-3.5.3_3/bin/zkServer.sh statusJMX enabled by defaultUsing config: /soft/zookeeper/zookeeper-3.5.3_3/bin/../conf/zoo.cfgMode: "follower"
- zookeeper集群搭建成功