Zookeeper集群环境搭建

Zookeeper集群环境搭建

本集群是采用3台机器进行搭建zookeeper分布式协调框架,3台机器分别为server01,server02,server03

1、下载

进入zookeeper下载页面:

https://www.apache.org/dyn/closer.cgi/zookeeper/

下载相应的tar.gz包。如:zookeeper-3.4.5.tar.gz

zookeeper-3.4.5.tar.gz上传到linux机器上的hadoop用户,/hadoop目录。

scp  zookeeper-3.4.5.tar.gz  hadoop@server01:/hadoop

先在server01中配置好后,在分发到server02server03机器上。

2、解压

进入/hadoop目录

cd /hadoop

解压zookeeper-3.4.5.tar.gz

tar -zxvf zookeeper-3.4.5.tar.gz

将解压后的zookeeper-3.4.5目录改为zookeeper目录

mv  zookeeper-3.4.5  zookeeper

3、配置zookeeper的zoo.cfg文件

进入zookeeper/conf目录

cd ./zookeeper/conf/

zoo_sample.cfg文件复制为zoo.cfg文件

cp zoo.cfg.sample zoo.cfg

编辑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=/hadoop/zookeeper/data
dataLogDir=/hadoop/zookeeper/log
# the port at which the clients will connect
clientPort=2181

server.1=server01:2888:3888
server.2=server02:2888:3888
server.3=server03:2888:3888
#
# 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

zookeeper目录下创建data目录和log目录

# 进入zookeeper目录
cd /hadoop/zookeeper

mkdir data

mkdir log

4、配置myid(重要)

进入data目录

cd ./data

将1写入myid文件

echo 1 > myid

每台机器中的myid不能重复,不然会导致zookeeper起来后,又挂掉。

5、将zookeeper的文件夹,分发到其他机器

# 将zookeeper目录分发到server02机器上的/hadoop目录
scp -r /hadoop/zookeeper hadoop@server02:/hadoop


# 将zookeeper目录分发到server03机器上的/hadoop目录
scp -r /hadoop/zookeeper hadoop@server03:/hadoop

6、修改每一台机器的myid(重要)

将server02机器上的myid改为2

进入zookeeper/data目录,编辑myid文件,将1改为2

将server03机器上的myid改为3

进入zookeeper/data目录,编辑myid文件,将1改为3

7、每台机器上配置环境变量

每一台机器上都配置环境变量

vim /etc/profile

将环境变量写入

export ZOOKEEPER_HOME=/hadoop/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin

使用source,使环境变量生效

source /etc/profile

8、启动zookeeper

在每一台机器上执行zookeeper启动命令:

zkServer.sh start

建议使用Xshell等工具,在多个会话窗口同时执行该命令

Zookeeper集群环境搭建_第1张图片

9、查看zookeeper集群状态

使用以下命令,查看zookeeper的状态

zkServer.sh status

Zookeeper集群环境搭建_第2张图片

你可能感兴趣的:(zookeeper,大数据)