8.3.ZooKeeper集群安装配置
Posted QueryMarsBo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8.3.ZooKeeper集群安装配置相关的知识,希望对你有一定的参考价值。
1.Zookeeper的搭建方式
Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。
单机模式:Zookeeper只运行在一台服务器上,适合测试环境;
伪集群模式:就是在一台物理机上运行多个Zookeeper 实例;
集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble)
Zookeeper通过复制来实现高可用性,只要集合体中半数以上的机器处于可用状态,它就能够保证服务继续(zookeeper集群机制)
Zookeeper集群机制:半数机制:集群中半数以上机器存活,集群可用
2.搭建ZooKeeper服务器集群
搭建要求:
(1) zk服务器集群规模不小于3个节点
(2) 要求各服务器之间系统时间要保持一致
1.解压缩zookeeper到指定目录: tar -zxvf zookeeper-3.4.5.tar.gz -C /usr/local/src
2.重命名:解压后将文件夹,重命名为zookeeper: mv zookeeper-3.4.5 zookeeper
3.修改环境变量:vi /etc/profile
export ZOOKEEPER_HOME=/usr/local/src/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
4.重新编译文件:source /etc/profile
5.修改配置文件:将 /usr/local/src/zookeeper/conf/目录下的zoo_sample.cfg,重命名为zoo.cfg:mv zoo_sample.cfg zoo.cfg
6.在/usr/local/zk/conf目录下,修改文件 vi zoo.cfg,创建data、log目录,并添加如下内容
# 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/local/src/zookeeper/data #文件存放目录,默认设置/tmp/zookeeper临时存放目录,每次重启后会丢失,在这我们自己设一个目录,/usr/local/src/zookeeper/data # the port at which the clients will connect clientPort=2181 # # 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
添加内容:
dataDir=/usr/local/src/zookeeper/data
dataLogDir=/usr/local/src/zookeeper/log server.1=shizhan2:2888:3888 (主机名, 心跳端口、数据端口)201 server.2=shizhan3:2888:3888 205 server.3=shizhan5:2888:3888 207
7.创建myid:在data目录下,创建文件myid:touch myid
8.将集群下发到其他机器上:基于 SSH 协议在网络之间进行安全传输的命令
scp -r /usr/local/src/zookeeper [email protected]:/usr/local/src/ ---(shizhan3:) scp -r /usr/local/src/zookeeper [email protected]:/usr/local/src/ --- (shizhan2)
9.修改myid:
到shizhan2上:修改myid为:1 到shizhan3上:修改myid为:2 到shizhan5上:修改myid为:3
10.启动每台机器:zkServer.sh start
11.查看集群状态,主从信息:zkServer.sh status
半数机制:集群中半数以上机器存活,集群可用。
zookeeper适合装在奇数台机器上!!!
以上是关于8.3.ZooKeeper集群安装配置的主要内容,如果未能解决你的问题,请参考以下文章
带你从头进行RabbitMQ安装集群搭建镜像队列配置和代码验证