1、安装Zookeeper集群
1.1解压Zookeeper
[root@master ~]# tar -xzvf /chinaskills/zookeeper-3.4.5.tar.gz -C /usr/local/src/
[root@master ~]# tar -xzvf /chinaskills/zookeeper-3.4.5.tar.gz -C /usr/local/src/
1.2 重命名为zookeeper
[root@master ~]#
mv /usr/local/src/zookeeper-3.4.5 /usr/local/src/zookeeper
mv /usr/local/src/zookeeper-3.4.5 /usr/local/src/zookeeper
1.3 配置环境变量(仅当前用户)
[root@master ~]#
vi /root/.bash_profile
vi /root/.bash_profile
配置内容:
export ZOOKEEPER_HOME=/usr/local/src/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
export ZOOKEEPER_HOME=/usr/local/src/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
1.4 配置zoo.cfg
[root@master ~]#
cp /usr/local/src/zookeeper/conf/zoo_sample.cfg /usr/local/src/zookeeper/conf/zoo.cfg
vi /usr/local/src/zookeeper/conf/zoo.cfg
cp /usr/local/src/zookeeper/conf/zoo_sample.cfg /usr/local/src/zookeeper/conf/zoo.cfg
vi /usr/local/src/zookeeper/conf/zoo.cfg
配置内容:
dataDir=/usr/local/src/zookeeper/data
dataLogDir=/usr/local/src/zookeeper/logs
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
dataDir=/usr/local/src/zookeeper/data
dataLogDir=/usr/local/src/zookeeper/logs
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
1.5 配置myid文件
[root@master ~]#
mkdir /usr/local/src/zookeeper/data
echo "1" > /usr/local/src/zookeeper/data/myid
source /root/.bash_profile
mkdir /usr/local/src/zookeeper/data
echo "1" > /usr/local/src/zookeeper/data/myid
source /root/.bash_profile
1.6 将文件发送给slave1和slave2
scp -r /usr/local/src/zookeeper slave1:/usr/local/src/
scp -r /usr/local/src/zookeeper slave2:/usr/local/src/
scp /root/.bash_profile slave1:/root/
scp /root/.bash_profile slave2:/root/
scp -r /usr/local/src/zookeeper slave1:/usr/local/src/
scp -r /usr/local/src/zookeeper slave2:/usr/local/src/
scp /root/.bash_profile slave1:/root/
scp /root/.bash_profile slave2:/root/
1.7 修改slave1和slave2 myid文件
[root@slave1 ~]#
echo 1 > /usr/local/src/zookeeper/data/myid
source /root/.bash_profile
echo 1 > /usr/local/src/zookeeper/data/myid
source /root/.bash_profile
[root@slave2 ~]#
echo 2 > /usr/local/src/zookeeper/data/myid
source /root/.bash_profile
echo 2 > /usr/local/src/zookeeper/data/myid
source /root/.bash_profile
1.8 启动zookeeper集群
# 分别启动zk集群
[root@master ~]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@slave1 ~]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@slave2 ~]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
# 分别查看zk各个节点的状态
[root@master ~]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@slave1 ~]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@slave2 ~]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Mode: follower
# 分别启动zk集群
[root@master ~]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@slave1 ~]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@slave2 ~]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
# 分别查看zk各个节点的状态
[root@master ~]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@slave1 ~]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@slave2 ~]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/src/zookeeper/bin/../conf/zoo.cfg
Mode: follower