下载
1
| wget https://mirrors.cloud.tencent.com/apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
|
安装目录
1 2 3 4 5 6 7 8 9 10 11
| mkdir /opt/zookeeper cd /opt/zookeeper tar -zxvf /opt/zookeeper-3.6.2.tar.gz cp -rf /opt/zookeeper/zookeeper-3.6.2 /opt/zookeeper/zoo-node1 cp -rf /opt/zookeeper/zookeeper-3.6.2 /opt/zookeeper/zoo-node2 cp -rf /opt/zookeeper/zookeeper-3.6.2 /opt/zookeeper/zoo-node3 rm -rf /opt/zookeeper/zookeeper-3.6.2 # 这样,zookeeper的三个节点运行目录分别为: /opt/zookeeper/zoo-node1 /opt/zookeeper/zoo-node2 /opt/zookeeper/zoo-node3
|
配置
zoo.cfg配置文件
zookeeper的运行,需要在conf目录配置zoo.cfg文件。我们可以参考zoo_sample.cfg进行配置。
节点1配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/zoo-node1/data
clientPort=2181
server.1=127.0.0.1:2888:3888 server.2=127.0.0.1:2889:3889 server.3=127.0.0.1:2890:3890
|
节点2配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/zoo-node2/data
clientPort=2182
server.1=127.0.0.1:2888:3888 server.2=127.0.0.1:2889:3889 server.3=127.0.0.1:2890:3890
|
节点3配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/zoo-node3/data
clientPort=2183
server.1=127.0.0.1:2888:3888 server.2=127.0.0.1:2889:3889 server.3=127.0.0.1:2890:3890
|
分别将上述配置文件放置在三个节点对应的conf目录下。另外,需要新建data目录
1 2 3
| mkdir /opt/zookeeper/zoo-node1/data mkdir /opt/zookeeper/zoo-node2/data mkdir /opt/zookeeper/zoo-node3/data
|
myid配置文件
zookeeper还需要在data目录中配置myid文件。myid文件中存放对应节点的序号
1 2 3
| echo '1' > /opt/zookeeper/zoo-node1/data/myid echo '2' > /opt/zookeeper/zoo-node2/data/myid echo '3' > /opt/zookeeper/zoo-node3/data/myid
|
日志路径配置
修改 bin 目录下的zkEnv.sh
将ZOO_LOG_DIR 修改为:ZOO_LOG_DIR="../logs/"
按上述方法分别修改三个节点中的zkEnv.sh文件
启动
1 2 3
| /opt/zookeeper/zoo-node1/bin/zkServer.sh start /opt/zookeeper/zoo-node2/bin/zkServer.sh start /opt/zookeeper/zoo-node2/bin/zkServer.sh start
|
如此分别启动三个节点即可。
启动效果如下:
1 2 3 4
| [root@localhost bin]# /opt/zookeeper/zoo-node1/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/zookeeper/zoo-node1/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
|