温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

zookeeper(1)利用3个机器,搭建zk集群模式

发布时间:2020-06-28 06:56:53 来源:网络 阅读:748 作者:shayang88 栏目:编程语言

背景

最近打算好好学习一下zookeeper,那么第一步就是要搭建一个环境。
单机版的比较简单,这里就不介绍了。
集群版本的,看网上的教程也蛮简单的,但是自己动起手来还是会遇到各种问题,这里做一下记录。

环境介绍

1、3个阿里云服务器,其中2个ECS,1个轻量服务器
2、zookeeper使用最新版本 https://archive.apache.org/dist/zookeeper/stable/apache-zookeeper-3.5.5-bin.tar.gz
3、3台云主机的Java使用jdk1.8版本。

步骤

1、检查各个主机的Java环境是否正常
zookeeper(1)利用3个机器,搭建zk集群模式
2、下载最新版本zookeeper,并解压,3台机器最好采用统一的目录,我采用的目录

/enzi/zk/apache-zookeeper-3.5.5-bin

3、3个机器,分别创建zookeeper的数据目录和日志目录

/enzi/zk/data
/enzi/zk/log

4、进入程序目录下,3个机器操作都一样

/enzi/zk/apache-zookeeper-3.5.5-bin/conf

复制zoo_sample.cfg为zoo.cfg,并修改zoo.cfg内容如下:

# 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=/enzi/zk/data
dataLogDir=/enzi/zk/log
# the port at which the clients will connect
clientPort=2181
#admin.serverPort=8089
# 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=ip1:2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888

quorumListenOnAllIPs=true

5、创建myid文件
分别在对应的data目录下,为自己的服务指定myid,内容就是zoo.cfg里面server.后面的序号,分别是1,2,3,ip1机器下myid内容为1,依次类推。

zookeeper(1)利用3个机器,搭建zk集群模式

6、依次启动3个机器zookeeper服务

bin/zkServer.sh start

如果想看有没有什么错误信息可以使用如下命令,在调试阶段建议使用这个命令。

bin/zkServer.sh start-foreground

7、查看是否启动成功
zookeeper(1)利用3个机器,搭建zk集群模式
mode:follower,代表这个服务是follower节点。
这里server.1是leader节点。

8、使用客户端进行连接,这里采用的windows的客户端

zkCli.cmd -server ip1:2181,ip2:2181,ip3:2181

使用命令,创建临时节点如下
zookeeper(1)利用3个机器,搭建zk集群模式

注意:对于阿里云,因为防火墙或者ECS的安全策略来说,会导致集群之间的接口连接失败。

1、轻量服务器来说需要把2181,2888,3888增加到防火墙上。

2、对于ESC需要把2181,2888,3888的安全规则,入口和出口都设置为允许。

zookeeper(1)利用3个机器,搭建zk集群模式

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI