ZooKeeper 组件安装配置
1.安装 ZooKeeper
# 准备好ZooKeeper安装包
[root@master software]# tar -xvf apache-zookeeper-3.5.9-bin.tar.gz -C /usr/local/
[root@master software]# cd /usr/local/
[root@master local]# ln -s /usr/local/apache-zookeeper-3.5.9/ /usr/local/zookeeper
[root@master local]# chown hadoop.hadoop -R zookeeper/
2.ZooKeeper 的配置选项
[root@master zookeeper]# su - hadoop
[hadoop@master ~]$ cd /usr/local/zookeeper/
[hadoop@master zookeeper]$ mkdir data logs
# 在每个节点写入该节点的标识编号,每个节点编号不同,master 节点写入 1,slave1 节点写入 2,slave2 节点写入 3。
[hadoop@master zookeeper]$ echo 1 > data/myid
# 修改配置文件 zoo.cfg
[hadoop@master zookeeper]$ cd conf/
[hadoop@master conf]$ cp zoo_sample.cfg zoo.cfg
[hadoop@master conf]$ vim zoo.cfg
dataDir=/usr/local/zookeeper/data
# 在 zoo.cfg 文件末尾追加以下参数配置,表示三个 ZooKeeper 节点的访问端口号
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
# Slave 节点配置
[hadoop@master conf]$ su -
# 从master数据复制到slave1
[root@master ~]# scp -r /usr/local/zookeeper slave1:/usr/local/
# 从master数据复制到slave2
[root@master ~]# scp -r /usr/local/zookeeper slave2:/usr/local/
# 在 slave2 节点上修改 zookeeper 目录的归属用户为 hadoop 用户。
[root@slave2 ~] # chown -R hadoop:hadoop /usr/local/src/zookeeper
# 在 slave1 节点上配置该节点的 myid 为 2。
[root@slave2 ~] # echo 3 > /usr/local/zookeeper/data/myid
# 在 slave1 节点上修改 zookeeper 目录的归属用户为 hadoop 用户。
[root@slave2 ~] # chown -R hadoop:hadoop /usr/local/src/zookeeper
# 在 slave1 节点上配置该节点的 myid 为 2。
[root@slave1 ~] # echo 2 > /usr/local/zookeeper/data/myid
# 在 master、slave1、slave2 三个节点增加环境变量配置。
[root@master ~]# vim /etc/profile
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HIVE_HOME/bin:$ZOOKEEPER_HOME/bin
[root@master ~]# source /etc/profile
3.启动 ZooKeeper
# master 启动
[hadoop@master ~]su – hadoop
[hadoop@master ~]source /etc/profile
# ZooKeeper 启动
[hadoop@master ~] zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START
# slave1 启动
[root@slave1 ~]# su - hadoop
[hadoop@slave1 ~]$ source /etc/profile
[hadoop@slave1 ~]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START
# slave2 启动
[root@slave2 ~]# su - hadoop
[hadoop@slave2 ~]$ source /etc/profile
[hadoop@slave2 ~]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START
#master 节点状态
[hadoop@master ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower # follower 状态
#slave1 节点状态
[hadoop@slave1 ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader # leader 状态
#slave2 节点状态
[hadoop@slave2 ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower # follower 状态