一、描述
伪分布式集群就是在一台机器部署多个zk应用,部署之前服务器需要有jdk环境 java -version可以显示相关java信息才可以进行zookeeper搭建
二.步骤

第一步下载好zookeeper-3.4.9.tar.gz
然后解压 tar zxvf zookeeper-3.4.9.tar.gz

[Zookeeper系列003] Zookeeper伪分布式集群搭建_数据结构


进入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=localhost:2187:2887 
server.2=localhost:2188:2888
server.3=localhost: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

通过命令检测是否成功:

zkCli.sh -server localhost:2181, 
localhost:2182, localhost:2183 是否可以连接成功

[Zookeeper系列003] Zookeeper伪分布式集群搭建_hadoop_02