Centos7 + Zookeeper 3.4.14 集群搭建教程

系统环境:centos 7.2
Zookeeper:3.4.14

一、配置集群hosts

vim /etc/hosts
# 添加如下内容:
192.168.1.10 hadoop
192.168.1.11 slave1
192.168.1.12 slave2
192.168.1.13 slave3

如果已经配置集群hosts地址,请忽略本步。

二、下载zookeeper

1.1 在windows下载,上传至服务器

下载地址: http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz

1.2 在linux下使用wget下载
cd /usr/local && wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz

三、解压安装

2.1 解压
tar -zxvf zookeeper-3.4.14.tar.gz
2.2 修改目录名称
mv zookeeper-3.4.14.tar.gz zookeeper
2.3 创建配置文件zoo.cfg
cd zookeeper/conf
cp zoo_sample.cfg zoo.cfg
2.4 编辑 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=/var/zookeeper
# 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=hadoop:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
server.4=slave3:2888:3888
2.5 设置集群zookeeper的id
cd /var/zookeeper && echo "1" >> ./myid
2.6 复制配置到其他服务器
scp  -r  /usr/local/zookeeper root@slave1:/usr/local
scp -r /usr/local/zookeeper root@slave2:/usr/local
scp -r /usr/local/zookeeper root@slave3:/usr/local
2.7 修改集群内其他节点的zookeeper的id值

分别按照下列方式修改:

# 节点一配置(192.168.1.11)
ssh slave1 
cd /var/zookeeper && echo "2" >> ./myid
# 节点二配置(192.168.1.12)
ssh slave2
cd /var/zookeeper && echo "3" >> ./myid
# 节点三配置(192.168.1.13)
ssh slave3 
cd /var/zookeeper && echo "4" >> ./myid

四、配置集群节点的Zookeeper环境变量

vi /etc/profile
 
#加入以下内容
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.14
export PATH=$ZOOKEEPER_HOME/bin:$PATH

使环境变量立即生效:

source /etc/profile

五、启动并验证集群

5.1 启动zookeeper

分别在集群4台机器中执行如下命令:

cd /usr/local/zookeeper/bin && ./zkServer.sh
5.2 查看zookeeper状态
./zkServer.sh status

所有节点的Mode结果为:leader或follower 说明集群运行成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

举个栗子の不容易

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值