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

Zookeeper集群搭建

程序员文章站 2024-03-08 10:28:22
...

Zookeeper搭建前提条件:
jdk、SSH互信,如何安装JDK请看《JDK安装》,如何建立服务器互信请看《SSH免密登录配置》

一、准备

这里我们以三台zookeeper来搭建,准备:

1.1 服务器准备:

10.242.167.216  app212
10.242.167.217  app211
10.242.167.218  app210

1.2 zookeeper安装包准备

这次使用的zookeeper版本是zookeeper-3.4.10.tar.gz,可以去zookeeper官网下载地址选择对应版本下载。然后ftp到服务器10.242.167.216(其中任意一台服务器) 的/opt目录下,然后把zookeeper-3.4.10修改为zookeeper

tar -xivf zookeeper-3.4.10.tar.gz -C /opt
mv zookeeper-3.4.10 zookeeper

二、Zookeeper配置

进入zookeeper配置文件目录,然后改变zookeeper配置文件名字,进行配置。

cd /opt/zookeeper/conf/
cp zoo_sample.cfg zoo.cfg
创建目录:
mkdir -p /bak/zk/zk_data
vim zoo.cfg
修改配置:
dataDir=/bak/zk/zk_data
添加配置:
server.1=dbmspreapp212:2888:3888
server.2=dbmspreapp211:2888:3888
server.3=dbmspreapp210:2888:3888
创建空文件用来存储zookeeperId:
touch /bak/zk/zk_data/myid
写入id进myid文件:
echo 1 > /bak/zk/zk_data/myid
拷贝配置好后的zookeeper到其他两个节点:
scp -r /opt/zookeeper app211:/opt
scp -r /opt/zookeeper app210:/opt
在app211和app210上创建目录和文件:
mkdir -p /bak/zk/zk_data
touch /bak/zk/zk_data/myid
修改myid文件
echo 2 > /bak/zk/zk_data/myid
echo 3 > /bak/zk/zk_data/myid
保证zookeeper id不同即可

Zookeeper集群搭建


三、启动zookeeper集群

分别启动三个zookeeper节点,

cd /opt/zookeeper/bin
./zkServer.sh start
./zkServer.sh status

Zookeeper集群搭建

Zookeeper集群搭建
注:三节点,一个leader,两个follower
如果显示两个follower和一个leader说明三节点的zookeeper集群搭建成功
./zkCli.sh 进入zookeeper客户端查看
Zookeeper集群搭建
到此,zookeeper搭建基本完成!


四、附录

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=/bak/zk/zk_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=dbmspreapp212:2888:3888
server.2=dbmspreapp211:2888:3888
server.3=dbmspreapp210:2888:3888