1、说明
伪分布式集群就是在一台机器部署多个zk应用,部署之前服务器需要有jdk环境 java -version可以显示相关java信息才可以进行zookeeper搭建
2、步骤
下载源码:zookeeper-3.4.9.tar.gz
解压:tar zxvf zookeeper-3.4.9.tar.gz
进入zk中的conf目录下输入cp zoo-sample.cfg zoo1.cfg cp zoo-sample.cfg zoo2.cfg、cp zoo-sample.cfg zoo3.cfg
分别对zoo1、2、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=/apps/servers/data/d_1
dataLogDir=/apps/servers/logs/logs_1
# the port at which the clients will connect
clientPort=2181
#不同zoo.cfg修改自己的属性和端口号
# 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.1.3:2187:2887
server.2=192.168.1.4:2188:2888
server.3=192.168.1.5:2189:2889
修改之后分别创建data目录和日志目录
mkdir /apps/servers/data/d_1
Mkdir /apps/servers/data/d_1
mkdir /apps/servers/data/d_1
mkdir /apps/servers/logs/logs_1
mkdir /apps/servers/logs/logs_1
mkdir /apps/servers/logs/logs_1
echo "1" > /apps/servers/data/d_1/myid
echo "2" >/apps/servers/data/d_2/myid
echo "3" >/apps/servers/data/d_3/myid
进入bin目录下输入命令 分别进行启动
zkServer.sh start ../conf/zoo1.cfg
zkServer.sh start ../conf/zoo2.cfg
zkServer.sh start ../conf/zoo3.cfg
通过命令检测是否成功:
注意防火墙和配置是否成功,这个是部署成功的关键
zkServer.sh status或者zkCli.sh -server localhost:2181, localhost:2182, localhost:2183 是否可以连接成功
如果不能连接上查看下日志