CentOS下zookeeper集群搭建

系统环境

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

机器列表和hosts配置

# cat /etc/hosts
11.0.10.8 prod-ckk-zookeeper-01
11.0.10.9 prod-ckk-zookeeper-02
11.0.10.10 prod-ckk-zookeeper-03

安装JDK

# yum install java-1.8.0-openjdk.x86_64

下载解压zookeeper-3.4.9

# wget -c https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
# tar -zxvf zookeeper-3.4.9.tar.gz -C /usr/local/

生成配置文件,及配置文件修改

# cd /usr/local/zookeeper-3.4.9/
# pwd
/usr/local/zookeeper-3.4.9/conf
# cp zoo_sample.cfg zoo.cfg
# grep -v ^# zoo.cfg 
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/usr/local/zookeeper-3.4.9/logs
dataDir=/usr/local/zookeeper-3.4.9/data
clientPort=2181
server.1=prod-ckk-zookeeper-01:2888:3888
server.2=prod-ckk-zookeeper-02:2888:3888
server.3=prod-ckk-zookeeper-03:2888:3888

建立zookeeper data和logs目录

# mkdir -p /usr/local/zookeeper-3.4.9/{logs,data}

dataDir路径中创建myid文件,三台机器均要执行

# echo "1" > /usr/local/zookeeper-3.4.9/data/myid
# echo "2" > /usr/local/zookeeper-3.4.9/data/myid
# echo "3" > /usr/local/zookeeper-3.4.9/data/myid

启动Zookeeper

# /usr/local/zookeeper-3.4.9/bin/zkServer.sh start

查看集群状态

# /usr/local/zookeeper-3.4.9/bin/zkServer.sh status

如下:

server01:

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

server02:

# /usr/local/zookeeper-3.4.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: leader

server03:

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

完成,谢谢

posted @ 2017-05-23 11:05  threegun  阅读(151)  评论(0编辑  收藏  举报