## Zookeeper搭建集群 ##
1.准备
操作系统:CentOS-7
环境:JDK8
安装包:zookeeper-3.4.10.tar
2.搭建zookeeper集群
1)解压二进制包
# tar zxvf zookeeper-3.4.9.tar.gz
# mv zookeeper-3.4.9 zookeeper
2)拷贝配置文件
# cd zookeeper
# cd conf
# cp zoo_sample.cfg zoo.cfg
3)配置
# 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=/root/zookeeper/data
dataLogDir=/root/zookeeper/logs
# 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.0=192.168.6.128:4001:4002
server.1=192.168.6.129:4001:4002
server.2=192.168.6.130:4001:4002
3.创建myid文件
分别在三台主机的 dataDir 路径下创建一个文件名为 myid 的文件,文件内容为该 zk 节点的编号。例如,在第一台主机上建立的 myid 文件内容是 0,第二台是 1。
4.启动zookeeper
# cd bin
# ./zkServer.sh start
5.查看zookeeper服务
# cd bin
# ./zkServer.sh status
说明集群搭建完毕