一、环境准备
下载zookeeper文件,zookeeper下载地址。本次安装部署使用的版本为zookeeper-3.4.9.
三台Linux服务器,配置静态IP,分别为192.168.1.203、192.168.1.204、192.168.1.205
三台服务器均安装好java环境
二、zookeeper安装
解压zookeeper下载文件
cd /Data/servers #软件索要安装的目录
tar -zxvf zookeeper-3.4.9.tar.gz
配置zookeeper
cd /Data/servers/zookeeper-3.4.9/conf #进入到配置文件所在目录
cp zoo_sample.cfg zoo.cfg #复制配置样例文件
vi zoo.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=/tmp/zookeeper //修改前
dataDir=/Data/servers/zookeeper //修改后
# 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.1.203:2888:3888
server.2=192.168.1.204:2888:3888
server.3=192.168.1.205:2888:3888
在每台zookeeper的服务上创建dataDir中配置的目录即/Data/servers/zookeeper
mkdir -p /Data/servers/zookeeper
cd /Data/servers/zookeeper
touch myid
vim myid //设置文件的值为当前服务器在集群中的序号后保存即可
zookeeper启动
cd /Data/servers/zookeeper-3.4.9/bin/
./zkServer.sh start
# 可以使用 ./zkServer.sh start-foreground让其打印出日志输出
三、测试
使用zkCli.sh分别连到三台服务器确认连接正常。// ./zkCli.sh -server 192.168.1.203
在其中一台创建节点,查看其它两台是否同步到创建的节点信息