zookeeper集群搭建

zookeeper版本

下载地址:http://archive.apache.org/dist/zookeeper/zookeeper-3.5.8/
在这里插入图片描述

服务器准备

1.集群至少准备3台服务器
2.例如:

192.168.1.1
192.168.1.2
192.168.1.3

解压文件

tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz

修改配置文件

进入安装目录下的conf文件夹,修改zoo_example.cfg文件名

mv zoo_example.cfg zoo.cfg

修改后结构如下:
在这里插入图片描述
编辑zoo.cfg文件

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
# 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=/opt/zookeeper/data
# the port at which the clients will connect
clientPort=2181
#set admin server port
admin.serverPort=8081
# 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.0=192.168.1.1:2888:3888
server.1=192.168.1.2:2888:3888
server.2=192.168.1.3:2888:3888

在zoo.cfg中dataDir中的目录(/opt/zookeeper/data)下创建文件

touch myid
vim myid

myid的内容与zoo.cfg的server后所带的数字相对应,
在这里插入图片描述

例如:192.168.1.1 myid的内容就应该是0
在这里插入图片描述
修改环境变量:

vim /etc/profile

在末尾加上

#set zookeeper environment
export ZK_HOME=/opt/apache-zookeeper-3.5.8
export PATH=$PATH:$ZK_HOME/bin

刷新并验证环境变量

source /etc/profile
echo $PATH

在这里插入图片描述

启动zookeeper

zkServer.sh start

如果遇到权限启动错误

ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.5.8/bin/ ../config/zoo.cfg
Starting zookeeper ... zkServer.sh: line 149: /opt/zookeeper/zookeeper_server.pid : Permission denied

修改zookeeper安装目录权限

chmod -R 777 zookeeper-3.5.8/

启动检查

通过命令检查zookeeper启动状态
zkServer.sh status

在这里插入图片描述
mode为 follower或leader则启动成功

如果启动失败,查看日志
#切换到安装目录/opt/apache-zookeeper-3.5.8/logs
cd /opt/apache-zookeeper-3.5.8/logs
#查看错误日志
vim zookeeper-root-server-host-192-168-1-1.out
这里列出一种错误情况(端口占用:8080)

在这里插入图片描述
端口占用可通过zoo.cfg中admin.serverPort属性修改,此处已改为8081

启动集群

在每台服务器上都执行以上操作,最后执行命令

#启动服务
zkServer.sh start

#验证服务
zkServer.sh status
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值