Centos7 + Zookeeper 3.4.14 集群搭建教程

目录

    • 一、配置集群hosts
    • 二、下载zookeeper
        • 1.1 在windows下载,上传至服务器
        • 1.2 在linux下使用wget下载
    • 三、解压安装
        • 2.1 解压
        • 2.2 修改目录名称
        • 2.3 创建配置文件zoo.cfg
        • 2.4 编辑 zoo.cfg 编辑以下内容
        • 2.5 设置集群zookeeper的id
        • 2.6 复制配置到其他服务器
        • 2.7 修改集群内其他节点的zookeeper的id值
    • 四、配置集群节点的Zookeeper环境变量
    • 五、启动并验证集群
        • 5.1 启动zookeeper
        • 5.2 查看zookeeper状态

系统环境: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 说明集群运行成功

你可能感兴趣的:(大数据存储)