zookeeper3.4集群搭建
机器准备
三台独立的linux主机, 内网IP分别为: 172.31.175.142、172.31.175.143、172.31.175.144
安装jdk8
rpm -ivh jdk-8u181-linux-x64.rpm
配置环境变量
cat << EOF >> /etc/profile export JAVA_HOME=/usr/java/jdk1.8.0_181-amd64 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin EOF source /etc/profile
安装zookeeper3.4
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz #/home/wx为当前用户的主目录 tar -xzvf zookeeper-3.4.13.tar.gz -C /home/wx cd /home/wx mv zookeeper-3.4.13 zookeeper cd zookeeper cp conf/zoo_sample.cfg conf/zoo.cfg
集群配置/运行
在zoo.cfg下指定data路径和server.i节点信息
# 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/wx/zookeeper/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= 172.31.175.142:2888:3888 server.2= 172.31.175.143:2888:3888 server.3= 172.31.175.144:2888:3888
在server.i对应的主机上分别创建myid文件并写入对应标识,如下
echo "1" > ~/zookeeper/data/myid echo "2" > ~/zookeeper/data/myid echo "3" > ~/zookeeper/data/myid
分别启动zkServer
sh ~/zookeeper/bin/zkServer.sh start
查看状态
sh ~/zookeeper/bin/zkServer.sh status
显示结果, 分别为1个leader,2个follower
ZooKeeper JMX enabled by default
Using config: /home/wx/zookeeper/bin/../conf/zoo.cfg
Mode: follower
ZooKeeper JMX enabled by default
Using config: /home/jack/zookeeper/bin/../conf/zoo.cfg
Mode: leader
ZooKeeper JMX enabled by default
Using config: /home/wx/zookeeper/bin/../conf/zoo.cfg
Mode: follower
可以kill掉leader, 然后剩下的两台zk, 会选举产生新的leader.
相关推荐
Kafka 2020-09-18
iamdll 2020-07-29
deyu 2020-07-27
deyu 2020-07-21
Elmo 2020-07-19
deyu 2020-07-07
ZHANGYONGHAO0 2020-07-05
joynet00 2020-06-26
isHooky 2020-06-25
CobingLiu 2020-06-21
CobingLiu 2020-06-16
airfish000 2020-06-14
roddex00 2020-06-12
iamdll 2020-06-11
CobingLiu 2020-06-10
MrZhangAdd 2020-06-09
yixietianxia 2020-06-04