单节点配置
- 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=/usr/local/apache-zookeeper/data
# 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
- zkServer.sh start
- zkServer.sh status
2181
为监听客户端连接端口号
Mode
表示为单节点配置

zk集群配置
首先分别准备三台机器ip分别为
机器IP | zk端口号 |
---|---|
192.168.0.1 | 2181 |
192.168.0.2 | 2181 |
192.168.0.3 | 2181 |
每台机器分别zk目录的data目录创建myid文件,内容分别为1,2,3, 且配置文件均为如下内容
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/apache-zookeeper/data
clientPort=2181
server.1=192.168.0.1:2888:3888
server.2=192.168.0.2:2888:3888
server.3=192.168.0.3:2888:3888
若全部启动后,查看状态为未成功,则尝试关闭防火墙
ufw disalbe