zookeeper集群的搭建
环境:
centos7 hmaster 192.168.0.107
centos7 hnode1 192.168.0.108
centos7 hnode2 192.168.0.109
版本:zookeeper-3.8.0
myid配置:
192.168.0.107 1
192.168.0.108 2
192.168.0.109 3
1.下载安装包
https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz
2.解压并进行配置文件的修改
将压缩包放在/usr/local/lib/目录下
cd /usr/local/lib/
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz
cd apache-zookeeper-3.8.0-bin
mkdir data
cd conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
添加集群的节点ip和端口,并配置dataDir
server.1=192.168.0.107:2888:3888
server.2=192.168.0.108:2888:3888
server.3=192.168.0.109:2888:3888
dataDir=/usr/local/lib/apache-zookeeper-3.8.0-bin/data
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/local/lib/apache-zookeeper-3.8.0-bin/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.
#
# https://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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=192.168.0.107:2888:3888
server.2=192.168.0.108:2888:3888
server.3=192.168.0.109:2888:3888
3.创建myid
myid的值是zoo.cfg文件里定义的server.A项A的值,三台机器分别为1,2,3
cd ../data
vim myid
4.配置环境变量
vim /etc/profile
export ZOOKEEPER_HOME=/usr/local/lib/apache-zookeeper-3.8.0-bin
export PATH=$PATH:$ZOOKEEPER_HOME/bin
source /etc/profile
5.启动zookeeper
#测试环境变量
echo $ZOOKEEPER_HOME
# 启动集群,每台机器都要启动
zkServer.sh start