Linux下zookeeper单机、伪分布式、分布式环境搭建(本篇主要介绍分布式用于Hadoop高可用集群)

一般zookeeper的安装部署可以有三种模式,单机模式、伪分布式和分布式,本篇主要介绍单机和分布式的环境安装配置

一、单机模式

1.下载zookeeper-3.4.10.tar.gz 

下载地址:http://mirror.bit.edu.cn/apache/zookeeper/

2.解压zookeeper

tar –zxvf zookeeper-3.4.10.tar.gz

3.在zookeeper-3.4.10目录下新建data,logs两个文件夹。

4.进入zookeeper-3.4.10/conf目录,把zoo_sample.cfg文件复制一份名字改成zoo.cfg。

cp zoo_sample.cfg zoo.cfg

5.修改zoo.cfg文件,需要修改以下几个地方。

dataDir=/usr/local/devtool/zookeeper-3.4.10/data

dataLogDir=/usr/local/devtool/zookeeper-3.4.10/logs

clientPort=2181

6.配置完以后,就可以启动zookeeper服务了,进入zookeeper-3.4.10/bin目录,启动zookeeper服务,没配置环境需要这样启动

./zkServer.sh start
./zkServer.sh stop

7.启动完成后,查看服务状态。

./zkServer.sh status

二、分布式模式

1、下载

http://mirror.bit.edu.cn/apache/zookeeper/

也可以用命令下载

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz  

2、上传 拷贝到另外2台机器

每个机器都先创建了文件夹,也可以只创建一个,另外2个直接拷贝也可以

scp zookeeper-3.4.10.tar.gz hadoop@node4:/home/hadoop/tool/ 

3、解压 、新建文件夹

tar -zxvf zookeeper-3.4.10.tar.gz

在 node3、node4、node5 中的 zookeeper 安装目录下分别创建一个文件data,作为 zookeeper 的 数据文件,并在data目录下创建一个文件 myid 且在文件中写入一个数字,命令如下

#node3、node4、node5中执行

mkdir data

创建文件夹并写入

cd data/
touch myid

echo "1" > /home/hadoop/tool/zookeeper-3.4.10/data/myid	# node3 中执行
echo "2" > /home/hadoop/tool/zookeeper-3.4.10/data/myid	# node4 中执行
echo "3" > /home/hadoop/tool/zookeeper-3.4.10/data/myid	# node5 中执行
cat /home/hadoop/tool/zookeeper-3.4.10/data/myid 	# node3、node4、node5中执行,查看写入是否成功

 

4、修改配置文件

在 zookeeper 安装目录下的 conf 目录下有一个名为 zoo_sample.cfg 的文件,拷贝该文件命名为zoo.cfg,我们需要配置该文件,zookeeper 在启动时会找这个文件作为默认配置文件。执行如下命令

cp zoo_sample.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=/tmp/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

 修改后

# 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=/tmp/zookeeper
# 配置Zookeeper数据存放配置
dataDir=/home/hadoop/tool/zookeeper-3.4.10/data
# 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
# 配置zookeeper集群的主机和ip,1 2 3 表示zookeeper服务的编号
server.1=node3:2888:3888
server.2=node4:2888:3888
server.3=node5:2888:3888

另外2台直接拷贝 

scp zoo.cfg hadoop@node5:/home/hadoop/tool/zookeeper-3.4.10/conf

5、配置环境变量 

vim ~/.bashrc
source ~/.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
export JAVA_HOME=/usr/java/jdk1.8.0_151
export HADOOP_HOME=/usr/local/hadoop        # hadoop的安装目录,替换为你的hadoop的安装目录
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
# Zookeeper Environment Variable
export ZOOKEEPER_HOME=/home/hadoop/tool/zookeeper-3.4.10

export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/sbin:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin

  

6、启动

zkServer.sh start
zkServer.sh stop

猜你喜欢

转载自blog.csdn.net/zjh_746140129/article/details/81981363