Zookeeper集群的实现

Posted bixiaoyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zookeeper集群的实现相关的知识,希望对你有一定的参考价值。

Zookeeper官方下载地址:http://mirror.bit.edu.cn/apache/zookeeper/

[[email protected] ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.12/zookeeper-3.4.12.tar.gz

[[email protected] ~]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
[[email protected] ~]# tar zxvf zookeeper-3.4.12.tar.gz -C /usr/local/

[[email protected] ~]# mv /usr/local/zookeeper-3.4.12/ /usr/local/zookeeper

[[email protected] conf]# cp zoo_sample.cfg zoo_sample.cfg.back
[[email protected] conf]# mv zoo_sample.cfg zoo.cfg
[[email protected] conf]# vim zoo.cfg

[[email protected] conf]# egrep -v "#|^$" zoo.cfg

tickTime=2000             #zookeeper使用基本时间单位,以毫秒为单位,用来控制心跳和超时
initLimit=10               #配置zookeeper集群中follower服务器初始化连接到Leader时,能够承受心跳时间间隔数;10*2000=20秒
syncLimit=5                 #配置Leader与Follower之间发送消息,请求和应答时长不能超过心跳LinitLimit时间长度;5*2000=10秒
dataDir=/data/zookeeper     #用于存储快照文件的目录
clientPort=2181              #zookeeper服务进程监听的TCP端口,默认情况下,会监听2181端口
server.1=192.168.37.129:2888:3888     #server.1:表示第几个服务器,IP地址表示本地IP,2888端口是服务器与集群中的Leader服务通信端口;3888端口如果集群中的Leader服务宕机了,需要一个端口来重新进行选举
选出来的新的Leader,而这个端口便是用来执行选举服务器互相通信的端口

 

Ps:以下是其他两台zookeeper配置依次对应即可

vim  zoo.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper
dataLogDir=/var/log/zookeeper/
clientPort=2181

 server.2=192.168.37.130:2888:3888

vim /data/zookeeper/myid 

2

 

vim  zoo.cfg
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/data/zookeeper dataLogDir=/var/log/zookeeper/ clientPort=2181 server.3=192.168.37.131:2888:3888 vim /data/zookeeper/myid 3

[[email protected] conf]# mkdir /data/zookeeper -p

[[email protected] conf]# vim /data/zookeeper/myid      #对应zoo.cfg中的server.1,判断每个zookeeper server的对应关系

1

添加环境变量到系统的/etc/profile,这样在任意路径都可执行“zkServer.sh start”启动命令了

[[email protected] conf]# cat <<EOF>>/etc/profile
> export ZOOKEEPER_HOME=/usr/local/zookeeper
> export PATH=$PATH:$ZOOKEEPER_HOME/bin
> EOF
[[email protected] conf]# source /etc/profile
[[email protected] conf]# zkServer.sh start
ZooKeeper JMX enabled by defaul

[[email protected] conf]# jps      #可通过jps命令(jdk内置命令)验证zookeeeper是够启动

2809 QuorumPeerMain        #Zookeeper启动进程,前面数字表示zookeeper进程PID

[[email protected] conf]# tail /usr/local/zookeeper/conf/zoo
zoo.cfg              zookeeper.out        zoo_sample.cfg.back  
[[email protected] conf]# tail /usr/local/zookeeper/conf/zookeeper.out 
2018-08-12 22:39:28,926 [myid:] - INFO  [main:[email protected]100] - Server environment:os.arch=amd64
2018-08-12 22:39:28,926 [myid:] - INFO  [main:[email protected]100] - Server environment:os.version=3.10.0-862.el7.x86_64
2018-08-12 22:39:28,926 [myid:] - INFO  [main:[email protected]100] - Server environment:user.name=root
2018-08-12 22:39:28,926 [myid:] - INFO  [main:[email protected]100] - Server environment:user.home=/root
2018-08-12 22:39:28,926 [myid:] - INFO  [main:[email protected]100] - Server environment:user.dir=/usr/local/zookeeper/conf
2018-08-12 22:39:28,933 [myid:] - INFO  [main:[email protected]835] - tickTime set to 2000
2018-08-12 22:39:28,937 [myid:] - INFO  [main:[email protected]844] - minSessionTimeout set to -1
2018-08-12 22:39:28,937 [myid:] - INFO  [main:[email protected]853] - maxSessionTimeout set to -1
2018-08-12 22:39:28,942 [myid:] - INFO  [main:[email protected]117] - Using org.apache.zookeeper.server.NioserverCnxnFactory as server connection factory
2018-08-12 22:39:28,945 [myid:] - INFO  [main:[email protected]89] - binding to port 0.0.0.0/0.0.0.0:2181

 
















以上是关于Zookeeper集群的实现的主要内容,如果未能解决你的问题,请参考以下文章

Zookeeper集群的实现

ZooKeeper 集群启动脚本分析

zooKeeper集群搭建

Zookeeper环境搭建 03apache-zookeeper-3.6.0 伪集群版(一台服务器实现三个节点的ZooKeeper集群)

项目方案利用Zookeeper实现集群缓存一致

Zookeeper实现分布式集群监控