安装Zookeeper-3.5.8
下载zookeeper-3.5.8。选用apache-zookeeper-3.5.8-bin.tar.gz。在物理机下载完之后,通过ftp服务,将压缩包发送至虚拟机。我习惯放在~/目录下,然后就地解压。配置Zookeeper1、查看配置文件夹:[xiaoguan@master zookeeper-3.5.8-bin]$ cd conf[xiaoguan@master conf]$ lsconfig
下载zookeeper-3.5.8。选用apache-zookeeper-3.5.8-bin.tar.gz。
在物理机下载完之后,通过ftp服务,将压缩包发送至虚拟机。我习惯放在~/目录下,然后就地解压,这样不会涉及到权限的问题。
一、配置Zookeeper
1、查看配置文件夹:
[xiaoguan@master zookeeper-3.5.8-bin]$ cd conf
[xiaoguan@master conf]$ ls
configuration.xsl log4j.properties zoo_sample.cfg
[xiaoguan@master conf]$
[xiaoguan@slave1 ~]$ ./zookeeper-3.5.8-bin/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[xiaoguan@slave1 ~]$
2、生成配置文件
[xiaoguan@master conf]$ cp zoo_sample.cfg zoo.cfg
[xiaoguan@master conf]$ ls
configuration.xsl log4j.properties zoo.cfg zoo_sample.cfg
[xiaoguan@master conf]$
3、编辑配置文件
# do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/home/xiaoguan/zookeeper-3.5.8/data dataLogDir=/home/xiaoguan/zookeeper-3.5.8/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
server.1=192.168.48.135:4001:4002
server.2=192.168.48.136:4001:4002
server.3=192.168.48.137:4001:4002
说明:
- dataDir和dataLogDir需要在启动之前就创建好。
- clientPort 为 zookeeper的服务端口。
- server.0、server.1、server.2 为 zk 集群中三个结的信息,定义格式为 hostname:port1:port2,其中 port1 是 node 间通信使用的端口,port2 是node 选举使用的端口,需确保三台主机的这两个端口都是互通的。
二、更改日志配置
Zookeeper 默认会将控制台信息输出到启动路径下的 zookeeper.out 中,通过如下方法,可以让Zookeeper 输出按尺寸切分的日志文件:
1)修改/opt/zookeeper-3.4.12/conf/log4j.properties文件,将zookeeper.root.logger=INFO, CONSOLE改为zookeeper.root.logger=INFO, ROLLINGFILE
2)修改/opt/zookeeper-3.4.12/bin/zkEnv.sh文件,将ZOO_LOG4J_PROP=“INFO,CONSOLE” 改为ZOO_LOG4J_PROP=“INFO,ROLLINGFILE”
三、在master主机的 dataDir 路径下创建一个文件名为 myid 的文件
myid的内容为为该 zk 节点的编号:编号在zoo.cfg文件最后server.id。id就是编号。
server.1=192.168.48.135:4001:4002 master编号为1
server.2=192.168.48.136:4001:4002 slave编号为2
server.3=192.168.48.137:4001:4002 slave1编号为3
[xiaoguan@master zookeeper-3.5.8-bin]$ cd data
[xiaoguan@master data]$ ls
[xiaoguan@master data]$ touch myid
[xiaoguan@master data]$ vi myid
[xiaoguan@master data]$ more myid
1
四、将配置好的zookeeper发送至slave结点
[xiaoguan@master ~]$ ls
Desktop hadoop-2.7.2 Pictures spark-2.4.6-bin-hadoop2.7 zookeeper-3.5.8
Documents hadoopdata Public Templates 桌面
Downloads Music scala-2.13.2 Videos
[xiaoguan@master ~]$ scp -r zookeeper-3.5.8-bin/ xiaoguan@slave:~/
[xiaoguan@master ~]$ scp -r zookeeper-3.5.8-bin/ xiaoguan@slave1:~/
然后修改下slave的myid文件:
[xiaoguan@master ~]$ ssh slave
Last login: Thu Jun 18 23:29:01 2020 from master
[xiaoguan@slave ~]$ ls
Desktop hadoop-2.7.2 Pictures spark-2.4.6-bin-hadoop2.7 zookeeper-3.5.8
Documents hadoopdata Public Templates 桌面
Downloads Music scala-2.13.2 Videos
[xiaoguan@slave ~]$ vi zookeeper-3.5.8-bin/data/myid
[xiaoguan@slave ~]$ more zookeeper-3.5.8-bin/data/myid
2
[xiaoguan@slave ~]$ logout
Connection to slave closed.
[xiaoguan@master ~]$ ssh slave1
Last login: Thu Jun 18 21:40:17 2020 from master
[xiaoguan@slave1 ~]$ vi zookeeper-3.5.8-bin/data/myid
[xiaoguan@slave1 ~]$ more zookeeper-3.5.8-bin/data/myid
3
五、启动zookeeper
在每个结点上执行./zkServer.sh start
。该命令再zookeeper的bin目录下。然后使用jps命令可以看到两个进程:
[xiaoguan@master logs]$ jps
3440 QuorumPeerMain
3737 Jps
[xiaoguan@slave1 ~]$ jps
3317 QuorumPeerMain
3687 Jps
[xiaoguan@slave ~]$ jps
3851 Jps
3423 QuorumPeerMain
在每个结点上都有查看一下,每个结点上都有两个进程。这样集群就启动成功了。
六、查看集群的状态
使用命令./zkServer.sh status
。如下,可以看到master和slave是follower,而slave1是leader。
[xiaoguan@master bin]$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/…/conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[xiaoguan@master bin]$ ssh slave
Last login: Fri Jun 19 12:59:07 2020 from master
[xiaoguan@slave ~]$ ./zookeeper-3.5.8-bin/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/…/conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[xiaoguan@slave ~]$ logout
Connection to slave closed.
[xiaoguan@master bin]$ ssh slave1
Last login: Fri Jun 19 12:58:43 2020 from master
[xiaoguan@slave1 ~]$ ./zookeeper-3.5.8-bin/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/…/conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
七、检查集群的高可用性
首先关掉集群中的leader也就是slave1:
[xiaoguan@slave1 ~]$ ./zookeeper-3.5.8-bin/bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/…/conf/zoo.cfg
Stopping zookeeper … STOPPED
然后查看集群的状态:
[xiaoguan@master zookeeper-3.5.8-bin]$ ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/…/conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
[xiaoguan@master zookeeper-3.5.8-bin]$ ssh slave
Last login: Fri Jun 19 13:07:52 2020 from master
[xiaoguan@slave ~]$ ./zookeeper-3.5.8-bin/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/…/conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[xiaoguan@slave ~]$
可以看到,此时Master被选为leader。然后再次打开slave1结点,此时slave1应该为follower:
[xiaoguan@slave1 ~]$ ./zookeeper-3.5.8-bin/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/…/conf/zoo.cfg
Starting zookeeper … STARTED
[xiaoguan@slave1 ~]$ ./zookeeper-3.5.8-bin/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/xiaoguan/zookeeper-3.5.8-bin/bin/…/conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[xiaoguan@slave1 ~]$
此时,Zookeeper 集群的安装及高可用性验证已完成!
参考
更多推荐
所有评论(0)