本文已参与「新人创作礼」活动,一起开启掘金创作之路。
一、 下载软件包
http://archive.apache.org/dist/zookeeper/zookeeper-3.4.10/
二、安装zookeeper
2.1将下载的安装包上传到服务器后解压
tar -xvf zookeeper-3.4.10.tar.gz
2.2把zoo_sample.cfg复制为zoo1.cfg
cp zoo_sample.cfg zoo1.cfg
2.3编辑zoo1.cfg文件
vim zoo1.cfg
2.4添加或修改下面内容
# 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=/etc/zookeeper-3.4.10/data/zk1
dataLogDir=/etc/zookeeper-3.4.10/logs/zk1
# 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=10.19.19.20:2888:3888
server.2=10.19.19.20:2889:3889
server.3=10.19.19.21:2888:3888
dataDIr 和dataLogDir路径自己定义好,并创建好目录文件
2.5进入bin目录启动
./zkServer.sh start
也可以指定配置文件启动
./zkServer.sh start ../conf/zoo1.cfg
2.6查看zookeeper状态
./zkServer.sh status
三、搭建zookeeper集群
3.1同zoo1.cfg,创建zoo2.cfg和zoo3.cfg 按照zoo1.cfg配置修改
注:zoo1.cfg配置文件里dataDir指定的那个目录下创建myid文件,并且指定id,改id为你zoo1.cfg文件中server.1=localhost:2888:3888中的1.只要在myid头部写入1即可
3.2应用启停
进人zookeeper的bin目录下进行启动
启动
./zkServer.sh start ../conf/zoo1.cfg
./zkServer.sh start ../conf/zoo2.cfg
./zkServer.sh start ../conf/zoo3.cfg
停止
./zkServer.sh stop ../conf/zoo1.cfg
./zkServer.sh stop ../conf/zoo2.cfg
./zkServer.sh stop ../conf/zoo3.cfg
查看集群状态
./zkServer.sh status ../conf/zoo1.cfg
./zkServer.sh status ../conf/zoo2.cfg
./zkServer.sh status ../conf/zoo3.cfg
3.3启动遇到的问题
启动zookeeper的时候,报Starting zookeeper ... already running as process 83错误
上面这个错误意思为以作为进程83运行。系统检测到你的zookeeper是在启动的状态的。
删除data/zk2目录下的zookeeper_server.pid文件然后重新执行启动