欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ZooKeeper集群搭建

程序员文章站 2022-05-07 14:29:36
...

一、环境

    Centos7  64位    JDK1.7.0_80     zookeeper-3.4.10.tar.gz

二、安装

1、通过Xshell上传安装包zookeeper-3.4.10.tar.gz至CentOS7服务器目录:/usr/local/src;

2、在/usr/local/src目录下解压缩安装包zookeeper-3.4.10.tar.gz:

cd /usr/local/src
tar -xzvf zookeeper-3.4.10.tar.gz

3、移动解压缩文件包至/usr/local目录下及重命名:

cd /usr/local/src
cp ./zookeeper-3.4.10.tar.gz /usr/local
cd /usr/local
mv ./zookeeper-3.4.10.tar.gz zookeeper

4、配置zookeeper环境变量

vi /etc/profile

内容:

export ZK_HOME=/usr/local/zookeeper
expoer PATH=$PATH:$ZK_HOME/bin

使环境变量生效:

source /etc/profile

5、zookeeper配置文件:

cd /usr/local/zookeeper/conf
cp ./zoo_sample.cfg zoo.cfg 
vi 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=/usr/lib/zookeeper
dataLogDir=/var/log/zookeeper
# 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=slave1:2888:3888
server.2=slave2:2888:3888
server.3=slave3:2888:3888dataDir=/usr/lib/zookeeper
dataLogDir=/var/log/zookeeper
# 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=slave1:2888:3888
server.2=slave2:2888:3888
server.3=slave3:2888:3888

保存退出;

6、配置myid文件:

    进入dataDir目录:

cd /usr/lib/zookeeper
touch ./myid
vi ./myid

slaveX中分别填写1    2    3 ;例如在slave1的myid文件中填写1,保存退出;在slave2的myid文件中填写2,保存退出;在slave3的myid文件中填写3,保存退出;

7、启动集群|关闭集群|查看集群状态:

cd /usr/local/zookeeper/bin
zkServer.sh start; #启动集群
zkServer.sh stop ; #关闭集群
zkServer.sh status; #查看集群状态

ZooKeeper集群搭建

Error信息:

1、zookeeper启动时报错:Error contacting service. It is probably not running.

ZooKeeper集群搭建

解决方案: 
1、查看liunx系统的防火墙是否关闭,查看防火墙状态 service firewalld status 如果没有关闭,就 servicefirewalld stop 关闭防火墙,然后重新启动zookeeper 看是否启用成功。 
2、查看zookeeper文件目录下conf目录下的文件是否有zoo.cfg和zoo_sample.cfg,若zoo.cfg不存在,请复制zoo_sample.cfg为zoo.cfg,编辑zoo.cfg:

ZooKeeper集群搭建
3、查看dataDir=/usr/lib/zookeeper目录下是否存在myid文件,若没有请创建编辑,分别添加1/2/3;

如 server.1=192.168.1.101:2888:3888机器的 myid文件中 填写 1;

    server.1=192.168.1.102:2888:3888机器的 myid文件中 填写 2;

    server.1=192.168.1.103:2888:3888机器的 myid文件中 填写 3;


4、查看日志文件,分析错误原因,针对性的Google、百度解决。