zookeeper 配置单点和集群安装,启动和关闭

zookeeper一般用来在分布式服务中充当协调者的角色。安装采用的zookeeper版本是3.4.14。先来看单机部署安装说明:
下载zookeeper安装包:

wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz

下载后进行解压缩:

tar -xzvf zookeeper-3.4.14.tar.gz

下面进行zk的配置:

cd zookeeper-3.4.14/conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg

zoo.cfg中默认配置如下:

#ZK中的一个时间单元。ZK中所有时间都是以这个时间单元为基础,进行整数倍配置的。
tickTime=2000
#foollower启动并同步leader数据允许的最大消耗时间,这里是tickTime的整数倍的意思,即时间为 10*tickTime
initLimit=10
#Leader与follower心跳超时时间,超过这个时间,leader认为follower已经下线,tickTime*5
syncLimit=5
#zk存储数据文件夹
dataDir=/tmp/zookeeper
#客户端连接端口
clientPort=2181

先按照默认配置启动:

sh bin/zkServer.sh start 

执行后看到:
Using config: /usr/service/zookeeper-3.4.14/bin/…/conf/zoo.cfg
Starting zookeeper … STARTED

[root@gs-server-7697 zookeeper-3.4.14]# ps -ef|grep zookeeper
root     64655     1  2 11:46 pts/1    00:00:00 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/service/zookeeper-3.4.14/bin/../zookeeper-server/target/classes:/usr/service/zookeeper-3.4.14/bin/../build/classes:/usr/service/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/*.jar:/usr/service/zookeeper-3.4.14/bin/../build/lib/*.jar:/usr/service/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/usr/service/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/usr/service/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/usr/service/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/usr/service/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/usr/service/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/usr/service/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/usr/service/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/usr/service/zookeeper-3.4.14/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /usr/service/zookeeper-3.4.14/bin/../conf/zoo.cfg
root     64714 60127  0 11:46 pts/1    00:00:00 grep zookeeper

表示服务已经启动起来。
停止zk:

[root@gs-server-7697 zookeeper-3.4.14]# sh bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/service/zookeeper-3.4.14/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

zk停止


zookeeper集群配置:

# 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=/usr/service/zookeeper-3.4.14/data
# 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.201.83.207:2888:3888
server.2=10.202.82.49:2888:3888
server.3=10.202.43.113:2888:3888

server.X=A:B:C 其中X是标识一个zk服务的唯一ID标识, A是该server所在的IP地址. B配置该server和集群中的leader交换消息所使用的端口. C配置选举leader时所使用的端口.

接着在上述三个zk所在服务器,dataDir中写入myid文件,与server.X对应一致。

echo 1 > data/myid
echo 2 > data/myid
echo 3 > data/myid

在三台服务器分别执行如下命令,启动zk:

sh bin/zkServer.sh start

启动完成后查看各节点状态:

sh bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/service/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: leader
ZooKeeper JMX enabled by default
Using config: /usr/service/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower

ZooKeeper JMX enabled by default
Using config: /usr/service/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: followe

至此,zookeeper启动成功

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值