Zookeeper-3.7.1 Cluster Construction
一、Zookeeper-3.7.1 Cluster Construction
1 配置 zoo.cfg
vim /opt/zookeeper-371/conf/zoo.cfg
## 心跳检查的时间 2秒
tickTime=2000
## 初始化时 连接到服务器端的间隔次数,总时间10*2=20秒
initLimit=10
## ZK Leader 和follower 之间通讯的次数,总时间5*2=10秒
syncLimit=5
## 存储内存中数据快照的位置,如果不设置参数,更新事务日志将被存储到默认位置。
dataDir=/opt/zookeeper-371/zkData
## ZK 服务器端的监听端口
clientPort=2181
## ZK 端口号,默认8080
admin.serverPort=9091
## 添加集群信息
server.1=192.168.121.11:2888:3888
server.2=192.168.121.12:2888:3888
server.3=192.168.121.13:2888:3888
## 分发节点
scp /opt/zookeeper-371/conf/zoo.cfg root@192.168.121.12:/opt/zookeeper-371/conf/zoo.cfg
scp /opt/zookeeper-371/conf/zoo.cfg root@192.168.121.13:/opt/zookeeper-371/conf/zoo.cfg
三台机器配置信息都一致的!
2 集群信息
## server.A=B:C:D
## A:节点在集群中的唯一ID,需要与dataDir/myid文件中的内容保持一致,取值范围为1~255
## B:节点的服务器IP地址
## C:集群中Follower节点与Leader 节点之间通信的端口
## D:当集群中的Follower节点宕机或出现故障时,集群进行重新选举Leader时所使用的端口
3 数字与配置文件中的 节点ID 数据一致
## 192.168.121.11
echo 1 > /opt/zookeeper-371/zkData/myid
## 192.168.121.12
echo 2 > /opt/zookeeper-371/zkData/myid
## 192.168.121.13
echo 3 > /opt/zookeeper-371/zkData/myid
4 启动
## 启动
/opt/zookeeper-371/bin/zkServer.sh start
## 状态
/opt/zookeeper-371/bin/zkServer.sh status
## 测试可以使用前台启动
/opt/zookeeper-371/bin/zkServer.sh start-foreground
5 查看状态信息
查看代码
##
[root@master01 zkData]# /opt/zookeeper-371/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-371/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@master01 zkData]# /opt/zookeeper-371/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-371/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
##
[root@localhost conf]# /opt/zookeeper-371/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-371/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost conf]# /opt/zookeeper-371/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-371/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
##
[root@localhost conf]# /opt/zookeeper-371/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-371/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost conf]# /opt/zookeeper-371/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-371/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
6 查看每台节点网络连接情况
[root@master01 ~]# netstat -natp | egrep '(2888|3888)'
tcp6 0 0 192.168.121.11:3888 :::* LISTEN 1627/java
tcp6 0 0 192.168.121.11:3888 192.168.121.13:49952 ESTABLISHED 1627/java
tcp6 0 0 192.168.121.11:3888 192.168.121.12:52270 ESTABLISHED 1627/java
tcp6 0 0 192.168.121.11:56810 192.168.121.13:2888 ESTABLISHED 1627/java
7 创建节点
## 进入客户端
/opt/zookeeper-371/bin/zkCli.sh
## 创建节点
create /iyuyixyz hello
## 查看节点信息
ls -s /iyuyixyz
## stat结构。好比Unix/Linux文件系统中文件的stat结构
stat /iyuyixyz
## 删除一个节点
delete /iyuyixyz
## 看下节点数据是否同步
X、One Step Success
Y、Error message
Z、Related Links
openEuler XXX Cluster Initialization Configuration:https://www.cnblogs.com/huaxiayuyi/p/16899214.html
Installing Zookeeper-3.7.1 openEuler:https://www.cnblogs.com/huaxiayuyi/p/16897875.html