CentOS 7.x下zookeeper安装

  • A+
所属分类:服务器架构

一、说明

Zookeeper官方地址:http://zookeeper.apache.org/
国内(清华大学源)下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/

1.1、zookeeper说明

在Zookeeper的官网上有这么一句话:ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.

这大概描述了Zookeeper主要可以干哪些事情:配置管理,名字服务,提供分布式同步以及集群管理。

1.2、zookeeper集群特性介绍

整个集群只要有超过集群数量一半的zookeeper工作是正常的,那么整个集群对外就是可用的,加入有两台服务器作一个zookeeper集群,只要有任何一台故障或宕机,那么这个zookeeper集群就不可用了,因为剩下的一台没有超过集群一半的数量,但是假如有三台zookeeper组成一个集群,那么损坏一台还剩两台,大于三台的一半,集群就是可用的状态,所以大部分的zookeeper集群数量都是用奇数

二、开始安装

2.1、环境说明

# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

服务器基础优化请参考:https://www.zhuimengren.co/suiji/933.html

2.2、安装JDK

JDK下载地址:https://www.oracle.com/technetwork/java/javase/downloads/index.html

# yum install -y jdk-8u151-linux-x64.tar.gz

2.3、安装与配置zookeeper集群

本文是用的多实例创建的zookeeper集群

# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
# tar xf zookeeper-3.4.14.tar.gz
# mkdir -p /usr/local/zookeeper 
# cp zookeeper-3.4.14 /usr/local/zookeeper/zk-01
# cp zookeeper-3.4.14 /usr/local/zookeeper/zk-02
# cp zookeeper-3.4.14 /usr/local/zookeeper/zk-03
# mkdir -p /usr/local/zookeeper/zk-{01..03}/{data,logs}
# cd /usr/local/zookeeper/zk-01/conf
# cp zoo_sample.cfg zoo.cfg

# grep -E -v -n "^#|^$" zoo.cfg     #zookeeper配置文件
2:tickTime=2000
5:initLimit=10
8:syncLimit=5
12:dataDir=/usr/local/zookeeper/data
13:dataLogDir=/usr/local/zookeeper/logs
15:clientPort=2181
17:server.1=192.168.56.11:2888:3888
18:server.2=192.168.56.11:2889:3889
19:server.3=192.168.56.11:2890:3890

#cp -a zoo.cfg /usr/local/zookeeper/zk-0{2..3}/conf/

2.4、启动集群

# cd /usr/local/zookeeper/zk-01/bin/ && ./zkServer.sh start
# cd /usr/local/zookeeper/zk-02/bin/ && ./zkServer.sh start
# cd /usr/local/zookeeper/zk-03/bin/ && ./zkServer.sh start

2.5、查看状态

一个leader和两个follower是正常的

# cd /usr/local/zookeeper/zk-01
# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper/zookeeper-12181/bin/../conf/zoo.cfg
Mode: follower             #follower

# ../zk-02/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper/zookeeper-12182/bin/../conf/zoo.cfg
Mode: leader            #leader

# ../zk-03/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper/zookeeper-12183/bin/../conf/zoo.cfg
Mode: follower               #follower

至此,一个三个节点的zookeeper集群就搭建完了,如果是三台机器搭建的话就自行改改配置即可!!

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: