ZooKeeper安装
集群配置
hadoop1 | hadoop2 | hadoop3 | |
Zookeeper ID | 1 | 2 | 3 |
上传ZK
解压缩
[hadoop@hadoop1 ~]$ tar -zxvf /opt/soft/zookeeper-3.4.10.tar.gz -C /opt/module
设置Data路径
[hadoop@hadoop1 ~]$ cd /opt/module/zookeeper-3.4.10/
[hadoop@hadoop1 zookeeper-3.4.10]$ mkdir zkData
设置节点的ID
[hadoop@hadoop1 zookeeper-3.4.10]$ cd zkData
[hadoop@hadoop1 zkData]$ vi myid
[hadoop@hadoop1 zookeeper-3.4.10]$ pwd
/opt/module/zookeeper-3.4.10
[hadoop@hadoop1 zookeeper-3.4.10]$ cd conf
[hadoop@hadoop1 conf]$ cp zoo_sample.cfg zoo.cfg
[hadoop@hadoop1 conf]$ ll
total 16
-rw-rw-r--. 1 hadoop hadoop 535 Mar 23 2017 configuration.xsl
-rw-rw-r--. 1 hadoop hadoop 2161 Mar 23 2017 log4j.properties
-rw-rw-r--. 1 hadoop hadoop 922 May 3 13:55 zoo.cfg
-rw-rw-r--. 1 hadoop hadoop 922 Mar 23 2017 zoo_sample.cfg
[hadoop@hadoop1 conf]$ vi zoo.cfg
设置环境变量
[hadoop@hadoop1 bin]$ sudo vi /etc/profile
[hadoop@hadoop1 bin]$ source /etc/profile
分发
[hadoop@hadoop1 conf]$ xrsync.sh /opt/module/zookeeper-3.4.10/
配置节点ID
将hadoop2、hadoop3的myid分别设置为2和3
分发环境变量
[root@hadoop1 ~]# xrsync.sh /etc/profile
fname=profile
pdir=/etc
------------------- hadoop1 --------------
root@hadoop1's password:
sending incremental file list
sent 44 bytes received 12 bytes 22.40 bytes/sec
total size is 3,699 speedup is 66.05
------------------- hadoop2 --------------
root@hadoop2's password:
sending incremental file list
profile
sent 111 bytes received 71 bytes 72.80 bytes/sec
total size is 3,699 speedup is 20.32
------------------- hadoop3 --------------
root@hadoop3's password:
sending incremental file list
profile
sent 111 bytes received 71 bytes 72.80 bytes/sec
total size is 3,699 speedup is 20.32
[root@hadoop1 ~]# xcall.sh source /etc/profile
--------- hadoop1 ----------
root@hadoop1's password:
--------- hadoop2 ----------
root@hadoop2's password:
--------- hadoop3 ----------
root@hadoop3's password:
[root@hadoop1 ~]#
测试
启动
[hadoop@hadoop1 ~]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@hadoop1 ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
关闭
[hadoop@hadoop1 ~]$ zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[hadoop@hadoop2 zkData]$ jps
1316 Jps
1244 QuorumPeerMain
[hadoop@hadoop2 zkData]$ kill -9 1244
启动ZK脚本
//使用集群脚本
[hadoop@hadoop1 bin]$ zk.sh start
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@hadoop1 bin]$ zk.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
调试日志
[hadoop@hadoop1 bin]$ tail -f zookeeper.out