Hadoop生态系统搭建(5)—— 分布式协同服务框架 Zookeeper 的安装部署与测试

1. 系统环境

Ubuntu 16.04
vmware
Hadoop 2.7.0
Java 1.8.0_111

master:192.168.19.128
slave1:192.168.19.129
slave2:192.168.19.130

2. 安装部署

1.下载 zookeeper:zookeeper-3.4.6.tar.gz

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

2.各节点配置zookeeper的环境变量。

# config zookeeper
export ZOOKEEPER_HOME=/home/hadoop/software/zookeeper-3.4.6
export PATH=$ZOOKEEPER_HOME/bin:$PATH

3.集群配置。

cd $ZOOKEEPER_HOME/conf
cp zoo_sample.cfg zoo.cfg

配置 zoo.cfg。

# The number of milliseconds of each tick
tickTime=4000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=20
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=8
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/home/hadoop/software/zookeeper-3.4.6/zookeeper-data
dataLogDir=/home/hadoop/software/zookeeper-3.4.6/logs
# 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

# 2888:follower <-> leader; 3888: leadership vote
# server.id=host:port:port 中的第一个port是从机器(follower)连接到主机器(leader)的端口号,第二个port是进行leadership选举的端口号。
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888

创建 zoo.cfg 配置的 dataDir 目录,在dataDir 下创建 myid,myid 文件中的内容只有一行,为本主机对应的id值,zoo.cfg 中配置的 server.id。
如master 的 myid 如下:

1

4.配置好之后scp到其他slave节点的对应位置。

scp -r zookeeper-3.4.6/ hadoop@slave1:/home/hadoop/software/
scp -r zookeeper-3.4.6/ hadoop@slave2:/home/hadoop/software/

5.启动ZooKeeper集群。
各节点依次执行 zkServer.sh start 启动zookeeper服务器

hadoop@master:~/software/zookeeper-3.4.6$ jps
1205 SecondaryNameNode
8427 Jps
1387 ResourceManager
1023 NameNode
hadoop@master:~/software/zookeeper-3.4.6$ zkServer.sh start
JMX enabled by default
Using config: /home/hadoop/software/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
hadoop@master:~/software/zookeeper-3.4.6$ jps
8448 QuorumPeerMain
1205 SecondaryNameNode
8473 Jps
1387 ResourceManager
1023 NameNode
hadoop@master:~/software/zookeeper-3.4.6$ zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/software/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
hadoop@master:~/software/zookeeper-3.4.6$









客户端脚本,连接到ZooKeeper集群上。对于客户端来说,ZooKeeper是一个整体(ensemble),连接到ZooKeeper集群实际上感觉在独享整个集群的服务,所以,可以在任何一个结点上建立到服务集群的连接:

zkCli.sh -server master:2181



手动停止 leader 服务,发现其中一个原 follower 转变为 leader:

zkServer.sh stop






发布了72 篇原创文章 · 获赞 26 · 访问量 31万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览