搭建采用zookeeper-3.4.12.tar.gz包
三台服务器分别是
10.4.7.111
10.4.7.112
10.4.7.113
然后在三台服务器分别安装zookeeper
解压到user/local下
tar -zxvf zookeeper-3.4.12.tar.gz -C /usr/local mv /usr/local/zookeeper-3.4.12 /usr/local/zookeeper
修改配置文件
cp /usr/local/zookeeper/conf/zoo_sample.cfg
/usr/local/zookeeper/conf/zoo.cfg
vim /usr/local/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/data
clientPort=2181
server.1=10.4.7.111:2888:3888
server.2=10.4.7.112:2888:3888
server.3=10.4.7.113:2888:3888
创建数据存储目录
mkdir -p /usr/local/zookeeper/data
创建myid文件, id 与 zoo.cfg 中的序号对应
#在192.168.2.158机器上执行
echo 1 > /usr/local/zookeeper/data/myid
#在192.168.2.152机器上执行
echo 2 > /usr/local/zookeeper/data/myid
#在192.168.2.150机器上执行
echo 3 > /usr/local/zookeeper/data/myid
配置环境变量
vim /etc/profile
在最后加上
export ZK_HOME=/usr/local/zookeeper export PATH=$ZK_HOME/bin:$PATH
分别启动
zkServer.sh start
查看状态
[root@masterexample data]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
关闭防火墙,否则看不到节点状态
systemctl stop firewalld
重新启动
[root@masterexample data]# zkServer.sh restart
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... no zookeeper to stop (could not find file /usr/local/zookeeper/data/zookeeper_server.pid)
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED