zookeeper3.4.14集群搭建
0 前置条件
主机gcw1,gcw2,gcw3
- JDK
1 zk下载
2 上传解压
[root@gcw2 src]# tar -zxvf zookeeper-3.4.14.tar.gz -C /opt/app/
3 配置文件修改
三台主机同样配置
[root@gcw3 src]# cd /opt/app/zookeeper-3.4.14/conf/
[root@gcw3 conf]# cp zoo_sample.cfg zoo.cfg
[root@gcw3 conf]# vi zoo.cfg
# 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/zookeeper/zd
# 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=gcw1:2888:3888
server.2=gcw2:2888:3888
server.3=gcw3:2888:3888
4 myid文件创建
去到dataDir=/data/zookeeper/zd
目录下根据配置创建
server.1=gcw1:2888:3888
server.2=gcw2:2888:3888
server.3=gcw3:2888:3888
例如主机gcw1
[root@gcw1 src]# cd /data/zookeeper/zd
[root@gcw1 zd]# vi myid
[root@gcw1 zd]# cat myid
1
例如主机gcw2
[root@gcw2 conf]# cd /data/zookeeper/zd
[root@gcw2 zd]# clear
[root@gcw2 zd]# vi myid
[root@gcw2 zd]# cat myid
2
例如主机gcw3
[root@gcw3 conf]# cd /data/zookeeper/zd/
[root@gcw3 zd]# vi myid
[root@gcw3 zd]# cat myid
3
5 创建软连接&环境变量
三台主机都需要配置
[root@gcw3 app]# cd /opt/app/
[root@gcw3 app]# ln -s zookeeper-3.4.14/ zookeeper
[root@gcw3 app]# pwd
/opt/app
环境变量 vi /etc/profile
export ZK_HOME=/opt/app/zookeeper
export PATH=$PATH:$ZK_HOME/bin
环境变量生效
[root@gcw2 conf]# source /etc/profile
6 启动测试
启动命令 zkServer.sh start
状态查看 zkServer.sh status
注意:集群启动时至少启动半数以上zk状态才会显示正常,比如我的3台主机,至少须启动2台
[root@gcw2 app]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@gcw2 app]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo.cfg
Mode: leader