2018/07 作者:ihunter 0 次 0
4、安装zookeeper群集
1)、安装zookeeper程序包
[root@localhost ~]# mkdir /usr/local/zookeeper01
[root@localhost ~]# mkdir /usr/local/zookeeper02
[root@localhost ~]# mkdir /usr/local/zookeeper03
[root@localhost ~]# wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
[root@localhost ~]# tar -zxvf zookeeper-3.4.6.tar.gz
[root@localhost ~]# cp zookeeper-3.4.6/* /usr/local/zookeeper01/
[root@localhost ~]# cp zookeeper-3.4.6/* /usr/local/zookeeper02/
[root@localhost ~]# cp zookeeper-3.4.6/* /usr/local/zookeeper03/
2)、修改配置文件
[root@localhost ~]# mkdir /usr/local/zookeeper01/data/
[root@localhost ~]# mkdir /usr/local/zookeeper02/data/
[root@localhost ~]# mkdir /usr/local/zookeeper03/data/
[root@localhost ~]# mkdir /usr/local/zookeeper01/logs/
[root@localhost ~]# mkdir /usr/local/zookeeper02/logs/
[root@localhost ~]# mkdir /usr/local/zookeeper03/logs/
[root@localhost ~]# touch /usr/local/zookeeper01/data/myid
[root@localhost ~]# touch /usr/local/zookeeper02/data/myid
[root@localhost ~]# touch /usr/local/zookeeper03/data/myid
[root@localhost ~]# echo 1 > /usr/local/zookeeper01/data/myid
[root@localhost ~]# echo 2 > /usr/local/zookeeper01/data/myid
[root@localhost ~]# echo 3 > /usr/local/zookeeper01/data/myid
[root@localhost ~]# mv /usr/local/zookeeper01/conf/zoo_sample.cfg /usr/local/zookeeper01/conf/zoo.cfg
[root@localhost ~]# mv /usr/local/zookeeper02/conf/zoo_sample.cfg /usr/local/zookeeper02/conf/zoo.cfg
[root@localhost ~]# mv /usr/local/zookeeper03/conf/zoo_sample.cfg /usr/local/zookeeper03/conf/zoo.c
fg
[root@localhost ~]# vi /usr/local/zookeeper01/conf/zoo.cfg
修改并追加以下内容:
clientPort=2181
#zookeeper02节点的这个位置为2182,zookeeper03节点的这个位置为2183
dataDir=/usr/local/zookeeper01/data
# zookeeper02和zookeeper03节点要修改成响应的目录。
dataLogDir=/usr/local/zookeeper01/logs
# zookeeper02和zookeeper03节点要修改成响应的目录。
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
按照上面的修改继续修改zookeeper02和zookeeper03的配置项。
3)、依次启动zookeeper节点服务
[root@localhost ~]# /usr/local/zookeeper01/bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper01/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost ~]# /usr/local/zookeeper02/bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper02/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost ~]# /usr/local/zookeeper03/bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper03/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
4)、查看状态
[root@localhost ~]# /usr/local/zookeeper02/bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper02/bin/../conf/zoo.cfg
Mode: leader
[root@localhost ~]# /usr/local/zookeeper01/bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper01/bin/../conf/zoo.cfg
Mode: follower
[root@localhost ~]# /usr/local/zookeeper03/bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper03/bin/../conf/zoo.cfg
Mode: follower