linux下搭建zookeeper集群
程序员文章站
2022-05-27 16:41:36
...
linux下搭建zookeeper集群
1、准备
1、下载zookeeper压缩包 (注:下载3.4.14版本,3.5以上运行时会少jar包)
2、系统:centOS7 安装好java环境
3、将压缩包上传到3台服务器上,并解压
4、解压后重命名 zookeeper01 zookeeper02 zookeeper03 (方便观察)
(cp -r zookeeper-3.4.14.jar zookeeper01)
2、配置zookeeper配置文件
1、进入zookeeper里的conf文件,创建并编辑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=/home/soft/zookeeper03/data //数据存放位置
# the port at which the clients will connect
clientPort=2181 //客户端端口号
# 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=192.168.0.211:2881:3881 //3个集群serverip端口等。(server.1表示server名称,192.168.0.211表示ip 2881表示集群内部通讯端口,3881表示选举端口,下面一样。)
server.2=192.168.0.212:2882:3882
server.3=192.168.0.213:2883:3883
2、创建dada目录(不然会启动报错,目录的路径为zoo.cfg里面配置的路径)
mkdir data
3、启动、测试
1、启动:
./bin/zkServer.sh start
注:(windows环境下不需要start)
2、检查是否启动成功
执行jps命令查看
3、测试
其余2台服务器重复执行上述操作并全部启动成功后
执行./zkServer.sh status
以上信息表示集群搭建成功,其中02号服务器(192.168.0.212)为leader,其他2台为follower
4、遇到的问题
1、
问题:下载的zookeeper版本为3.5以上时运行会报以下错误
Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
解释:该错误为找不到主类,是因为3.5以上版本都少了一个zookeeper-***.jar (***表示版本号)
解决:去官网下该版本的jar或者重新下一个3.4.*版本的zookeeper压缩包进行搭建
2、
问题:运行启动命令没有报错但是查看log时发现有如下报错
no route to host
解释:服务器防火墙处于启动状态并且没有开放端口
解决:关闭防火墙或者开放所需端口
上一篇: Centos7上离线编译安装Nginx