温故而知新,可以为师矣。
1.集群计划 hostname 分别为m1 c1 c2 这是笔者的大数据测试集群
192.168.1.130 m1
192.168.1.131 c1
192.168.1.132 c2
2.创建安装目录和zk的数据存放目录 原默认数据目录位于/tmp/zookeeper,关机就无了,明显不合理的。
mkdir -p /apps/zk
mkdir -p /apps/zk/zkData
3.上传安装包到 /apps/zk 并解压
tar -zxvf zookeeper-3.4.6.tar.gz
4. 进入解压目录的conf文件夹下,拷贝示例配置文件zoo_sample.cfg 为 zoo.cfg
cp zoo_sample.cfg zoo.cfg
5.修改配置文件 主要是配置数据路径,集群节点信息
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/apps/zk/zkData
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=m1:2888:3888
server.2=c1:2888:3888
server.3=c2:2888:3888
6.并在数据文件创建一个名为myid的文件,笔者三台机器的myid内容分别为1 2 3
7.将m1配置好的zookeepr包复制到其他两台机器上
scp -r zookeeper-3.4.6 c1:$PWD
scp -r zookeeper-3.4.6 c2:$PWD
8.启动zookeeper 在各服务器上执行下面脚本 启动集群
./zookeeper-3.4.6/bin/zkServer.sh start
9.查看各节点的的状态
./zookeeper-3.4.6/bin/zkServer.sh status