下面介绍一下zookeeper单机集群模式环境搭建:
创建目录
/opt/zookeeper/zookeeper1
/opt/zookeeper/zookeeper2
/opt/zookeeper/zookeeper3
以上三个目录为三个zookeeper实例的根目录
/opt/zookeeper/zookeeper1/data
/opt/zookeeper/zookeeper1/datalog
/opt/zookeeper/zookeeper2/data
/opt/zookeeper/zookeeper2/datalog
/opt/zookeeper/zookeeper3/data
/opt/zookeeper/zookeeper3/datalog
创建上述目录分别作为每个实例的数据目录和log目录。
创建每个实例的myid文件:
echo 1 > /opt/zookeeper/zookeeper1/data/myid
echo 2 > /opt/zookeeper/zookeeper2/data/myid
echo 3 > /opt/zookeeper/zookeeper3/data/myid
将下载的zookeeper的文件分别复制到/opt/zookeeper/zookeeper1,/opt/zookeeper/zookeeper2,/opt/zookeeper/zookeeper3目录下。
以zookeeper-3.4.10为例,进入 /opt/zookeeper/zookeeper1/zookeeper-3.4.10/conf目录。
cp zoo_sample.cfg 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=/opt/zookeeper/zookeeper1/data
dataLogDir=/opt/zookeeper/zookeeper1/datalog
# 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=192.168.65.121:2881:3881
server.2=192.168.65.121:2882:3882
server.3=192.168.65.121:2883:3883
并修改实例2和实例三的对应配置文件,这里实例2的端口号为2182,实例三的端口号为2183
分别进入每个实例目录下,执行
bin/zkServer.sh start
启动之后,执行:
bin/zkServer.sh status
查看运行状态