Zookeeper3.5.8集群部署
环境说明
准备三台服务器,我这边是虚拟机,分别为:bigdata141、bigdata142、bigdata143
下载安装包
下载链接:Index of /dist/zookeeper/zookeeper-3.5.8
下载完后,上传到其中一台服务器,我这边上传到 bigdata141 的 /data/soft/ 目录下
解压并配置
解压
[root@bigdata141 soft]# tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz
[root@bigdata141 soft]# ll
total 491240
drwxr-xr-x. 7 root root 166 Nov 27 16:24 apache-zookeeper-3.5.8-bin
-rw-r--r--. 1 root root 9394700 Nov 27 15:59 apache-zookeeper-3.5.8-bin.tar.gz
配置
1、进入 zookeeper 下的 conf 目录,复制一份样本配置文件为 zoo.cfg,后面都是修改这份
[root@bigdata141 conf]# cd apache-zookeeper-3.5.8-bin/conf
[root@bigdata141 conf]# cp zoo_sample.cfg zoo.cfg
[root@bigdata141 conf]# vi zoo.cfg
编辑 zoo.cfg 文件,找到 dataDir,这个目录存放的是 zookeeper 的核心数据,最好不要放在 tmp 临时目录下,我这边修改为 /data/soft/apache-zookeeper-3.5.8-bin/data,还要加上 server.0、server.1、server.2 三行
dataDir=/data/soft/apache-zookeeper-3.5.8-bin/data
server.0=bigdata141:2888:3888
server.1=bigdata142:2888:3888
server.2=bigdata143:2888:3888
修改前的完整配置:
# 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=/tmp/zookeeper
# 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
修改后的完整配置:
# 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=/data/soft/apache-zookeeper-3.5.8-bin/data
server.0=bigdata141:2888:3888
server.1=bigdata142:2888:3888
server.2=bigdata143:2888:3888
# 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
2、创建 myid 文件
然后切换到 zookeeper 目录下,创建 data/ 目录并进入、echo 0 覆盖 myid 文件内容
[root@bigdata141 apache-zookeeper-3.5.8-bin]# mkdir data
[root@bigdata141 apache-zookeeper-3.5.8-bin]# cd data/
[root@bigdata141 data]# echo 0 > myid
3、复制安装包到其他节点
切换到 /data/soft 目录,执行以下命令:
[root@bigdata141 soft]# scp -rq apache-zookeeper-3.5.8-bin/ bigdata142:/data/soft/
[root@bigdata141 soft]# scp -rq apache-zookeeper-3.5.8-bin/ bigdata143:/data/soft/
4、修改其他节点配置
修改其他节点 zookeeper 下的 myid 文件
[root@bigdata142 apache-zookeeper-3.5.8-bin]# echo 1 > data/myid
[root@bigdata143 apache-zookeeper-3.5.8-bin]# echo 2 > data/myid
启动zookeeper
在各个节点执行命令:bin/zkServer.sh start
[root@bigdata141 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
查看各个节点 zookeeper 是否启动:jps -l
都有 QuorumPeerMain 进程就表示启动成功
[root@bigdata141 apache-zookeeper-3.5.8-bin]# jps -l
4241 sun.tools.jps.Jps
4195 org.apache.zookeeper.server.quorum.QuorumPeerMain
查看各个节点 zookeeper 状态:bin/zkServer.sh status
可以看到 Mode,142为 leader 主节点,141、143为 follower 从节点
[root@bigdata141 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[root@bigdata142 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
[root@bigdata143 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
停止Zookeeper
各个节点都要执行:bin/zkServer.sh stop
[root@bigdata141 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@bigdata142 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@bigdata143 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED