码迷,mamicode.com
首页 > 其他好文 > 详细

8.3.ZooKeeper集群安装配置

时间:2018-06-04 19:16:51      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:directory   主机   修改   ide   dmi   none   数据   /tmp   丢失   

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 root@192.168.232.205:/usr/local/src/ ---(shizhan3:)

scp -r  /usr/local/src/zookeeper root@192.168.232.201:/usr/local/src/ --- (shizhan2)

  9.修改myid:

到shizhan2上:修改myid为:1shizhan3上:修改myid为:2shizhan5上:修改myid为:3

  10.启动每台机器:zkServer.sh start

  11.查看集群状态,主从信息zkServer.sh status

  

 

 

 

 

 

  


 

 

 

半数机制:集群中半数以上机器存活,集群可用。

zookeeper适合装在数台机器上!!!

8.3.ZooKeeper集群安装配置

标签:directory   主机   修改   ide   dmi   none   数据   /tmp   丢失   

原文地址:https://www.cnblogs.com/yaboya/p/9134799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!