安装
https://archive.apache.org/dist/zookeeper/zookeeper-3.5.7/
命令
bin/zkServer.sh start
bin/zkServer.sh stop
bin/zkServer.sh status
bin/zkCli.sh
ll /
quit
各个配置项的含义:
tickTime:每个时钟周期的毫秒数。ZooKeeper使用一个内部时钟来跟踪时间,这个配置项定义了时钟周期的长度。
initLimit:初始同步阶段可以花费的时钟周期数。当ZooKeeper启动时,它会进行一次初始化同步,这个配置项定义了同步阶段可以花费的最大时钟周期数。
syncLimit:发送请求和接收确认之间可以经过的时钟周期数。当集群中的ZooKeeper服务器之间进行数据同步时,这个配置项定义了可以经过的最大时钟周期数。
dataDir:快照文件存储的目录路径。ZooKeeper会定期将其数据写入快照文件,以便在重启时恢复数据。
clientPort:客户端连接的端口号。ZooKeeper提供一个用于客户端连接的固定端口,可以通过该端口与ZooKeeper集群进行通信。
# 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=/export/server/zookeeper/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=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
服务器编号
在 zkData中,vim myid 1
一个集群中的 ZooKeeper 服务器配置文件中的一个配置项。在这个配置项中:
server.A 是一个标识符,用于标识特定的服务器。
B:C:D 表示服务器的地址和端口。
具体来说,B 是服务器的 IP 地址或主机名,C 是服务器之间通信所使用的端口,D 是服务器之间的领导权(对于 ZooKeeper 中的选举过程)。
启动停止状态脚本
vim zookeeper/bin/zk.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start"){
echo " =================== 启动zookeeper集群 ==================="
for host in node1 node2 node3
do
echo =============== $host ===============
ssh $host /export/server/zookeeper/bin/zkServer.sh start
done
}
;;
"stop"){
echo " =================== 关闭zookeeper集群 ==================="
for host in node1 node2 node3
do
echo =============== $host ===============
ssh $host /export/server/zookeeper/bin/zkServer.sh stop
done
}
;;
"status"){
echo " =================== 查看zookeeper集群状态 ==================="
for host in node1 node2 node3
do
echo =============== $host ===============
ssh $host /export/server/zookeeper/bin/zkServer.sh status
done
}
;;
esac
xsync同步分发到其他服务
sudo /home/hadoop/bin/xsync /export/server/apache-zookeeper-3.5.7-bin
ln -s apache-zookeeper-3.5.7-bin zookeeper
sudo /home/hadoop/bin/xsync /export/server/zookeeper/bin/zk.sh
修改所有的服务id