ZooKeeper是一个高可用的分布式数据管理与系统协调框架,使该框架保证了分布式环境中数据的强一致性,也正是基于这样的特性,使得ZooKeeper解决很多分布式问题;

下面为大家介绍如何搭建Zookeeper集群。

使用的是:

CentOS release 6.8 (Final)

网络下载,zookeeper-3.5.2-alpha.tar.gz 版本

上传文件到对应的目录,使用WinSCP上传工具上传文件

[roya@server-3 conf]$ vim zoo.cfg
# The number of milliseconds of each tick
tickTime=2000   心跳间隔周期 毫秒
# The number of ticks that the initial
# synchronization phase can take
initLimit=10  初始连接超时阈值=10*tickTime。指的是follower初始连接leader的超时时间。 如果网络环境不好,适当调大。
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5  连接超时阈值=syncLimit*tickTime。指的是follower和leader做数据交互的超 时时间。如果网络环境不好,适当调大。
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes. 
dataDir=/home/zkdata   数据目录指的是zookeeper znode树的 持久化目录
# the port at which the clients will connect
clientPort=2181    配置的是客户端连接zk服务器的端口号
# 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
#admin.serverPort=8888
server.1=server-1:2888:3888
server.2=server-2:2888:3888
server.3=server-3:2888:3888

 

server对应的IP解析,[roya@server-1 etc]$ 在etc ,hosts下添加对应值

192.168.187.130 server-1

192.168.187.132 server-2

192.168.187.137 server-3

server后的数字是选举id,在选举过程中会用到。注意:数字一定要能比较出大小。

2888 端口原子广播端口,可以自定义 3888 端口选举端口,可以自定义 在home目录下创建zkdata文件,创建myid文件(名字固定),zk 持久化目录可以自行创建,方便管理就好。

 

远程拷贝zk的安装目录到zk2、zk3上

 [root@server-3 /]# scp -r / root@192.168.80.95:/home/zkdata

 [root@server-3 /]# scp -r / root@192.168.80.96:/home/zkdata

拷贝后对,zk2,zk3   /home/zkdata 文件夹下myid做对应修改

三台服务器分别开启端口:

 [root@server-1 /]#   iptables -I INPUT -p tcp --dport 2888 -j ACCEPT

 [root@server-1 /]#  iptables -I INPUT -p tcp --dport 3888 -j ACCEPT

启动zk服务器

[root@server-1 bin]# ./zkServer.sh start

Using config: /home/roya/platform/java/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

恭喜你启动成功!

查看zk状态:

[root@server-1 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/roya/platform/java/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader

Ok 大功告成!

 

posted on 2020-04-08 13:10  W晴空  阅读(184)  评论(0编辑  收藏  举报