美文网首页
Zookeeper 集群

Zookeeper 集群

作者: SnorlaxSE | 来源:发表于2017-10-01 12:53 被阅读0次
[root@Server1 local]# tar -zxvf zookeeper-3.4.9.tar.gz 
[root@Server1 local]# mv zookeeper-3.4.9 zookeeper //该重命名步骤纯属为了以后方便,可以省略 
  • 相关参数配置

a) 进入zookeeper目录中,将conf/zoo_sample.cfg拷贝一份命名为 zoo.cfg

 [root@Server1 local]# cd zookeeper 
[root@Server1 zookeeper]# cd conf 
[root@Server1 conf]# cp zoo_sample.cfg zoo.cfg 
[root@Server1 conf]# vim zoo.cfg

b) 修改配置项如下:

# 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/export/software/zookeeper/data
dataLogDir=/usr/export/software/zookeeper/logs

# 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和server.2参数
server.1=192.168.31.108:2888:3888
server.2=192.168.31.112:2888:3888

c) 在/usr/export/software/zookeeper 目录下新建 data和 logs 文件夹,在 data 和 logs 目录下新建 myid 文件

[root@Server1 conf]# mkdir /home/zookeeper/data
[root@Server1 conf]#cd /home/zookeeper/data
[root@Server1 data]# echo 1 >> myid
[root@Server1 data]# mkdir /home/zookeeper/logs
[root@Server1 data]# cd /home/zookeeper/logs
[root@Server1 logs]# echo 1 >> myid 
#注意:这个id是zookeeper的主机标识,每个主机id不同,第一台是1, 第二台是 2,以此类推。此处每台主机配置不同

d) 可以考虑将zookeeper相关命令配置在环境变量中

# vi /etc/profile
#Zookeeper
export ZOOKEEPER_HOME=/usr/export/software/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin

e) 重复以上步骤在其它虚拟机上安装zookeeper(仅修改myid参数)

  • 启动zookeeper
[root@Server1 logs]# cd /usr/local/zookeeper/bin 
[root@Server1 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Starting
zookeeper ... STARTED

  或(已添加环境变量)
[root@Server1 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Starting
zookeeper ... STARTED

逐个启动每台虚拟机中的 zookeeper

  • 查看zookeeper状态
[root@Server1 bin]# ./zkServer.sh status
  或
[root@Server1 ~]# zkServer.sh status

在 zookeeper 集群启动后,查看状态可以看到如下情况:

ZooKeeper JMX enabled by default
Using config: /usr/export/software/zookeeper/bin/../conf/zoo.cfg
Mode: leader

ZooKeeper JMX enabled by default
Using config: /usr/export/software/zookeeper/bin/../conf/zoo.cfg
Mode: follower
  • 关闭 zookeeper
[root@Server1 bin]# ./zkServer.sh stop
  或
[root@Server1 ~]# zkServer.sh stop

相关文章

网友评论

      本文标题:Zookeeper 集群

      本文链接:https://www.haomeiwen.com/subject/fgooextx.html