首页  

zookeeper集群搭建     所属分类 zookeeper 浏览量 4113
单机 4个节点 ,一个是观察者
每个节点 使用不同的端口
单机伪集群


三个端口作用
给cline端提供服务的端口
集群内通讯  (leader)
leader选举


dataDir=/Users/dugang/soft/apps/zkcluster/z1/data/
clientPort=2182

server.1=127.0.0.1:3182:4182
server.2=127.0.0.1:3183:4183
server.3=127.0.0.1:3184:4184
server.4=127.0.0.1:3185:4185:observer

4个节点
2182 3182 4182
2183 3183 4183
2184 3184 4184
2185 3185 4185


nohup ./zkServer.sh  start & 

Caused by: java.lang.IllegalArgumentException: /Users/dugang/soft/apps/zkcluster/z1/data/myid file is missing
Caused by: java.lang.IllegalArgumentException: serverid z1 is not a number
java.lang.RuntimeException: My id 0 not in the peer list

server.N   N 和 myid内容一致


启动第一个节点 

z1/bin

./zkServer.sh start

ZooKeeper JMX enabled by default
Using config: /Users/dugang/soft/apps/zkcluster/z1/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

查看状态
./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /Users/dugang/soft/apps/zkcluster/z1/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
只启动了一个节点 ,集群还没启动好 

echo stat |nc 127.0.0.1 2182
This ZooKeeper instance is not currently serving requests

netstat -an|grep 2182
tcp46      0      0  *.2182                 *.*                    LISTEN     
netstat -an|grep 3182
3182 是该节点成为leader才启动的端口

netstat -an|grep 4182
tcp4       0      0  127.0.0.1.4182         *.*                    LISTEN   

2182 给客户端提供服务的端口
3182 成为leader监听的端口
4182 leader选举端口


启动第二个节点
z2/bin
./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /Users/dugang/soft/apps/zkcluster/z2/bin/../conf/zoo.cfg
Mode: leader

第二个节点成为leader
第4个节点 observer ,不参与选举 ,
2个节点 就能选出leader 

leader选举规则
优先选zxid值最大的zk服务器,如果多个zk服务器拥有最新的zxid值,则取sid值最大的zk服务器
sid 就是 zk节点编号 myid


netstat -an|grep 2183
tcp46      0      0  *.2183                 *.*                    LISTEN     
dugang:bin dugang$ netstat -an|grep 3183
tcp4       0      0  127.0.0.1.3183         127.0.0.1.50047        ESTABLISHED
tcp4       0      0  127.0.0.1.50047        127.0.0.1.3183         ESTABLISHED
tcp4       0      0  127.0.0.1.3183         *.*                    LISTEN     
dugang:bin dugang$ netstat -an|grep 4183
tcp4       0      0  127.0.0.1.4183         *.*                    LISTEN 

节点2 成为leader , 监听 3183端口 


启动 第3 第4 个节点

z3/bin
./zkServer.sh start

./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /Users/dugang/soft/apps/zkcluster/z3/bin/../conf/zoo.cfg
Mode: follower


z4/bin

./zkServer.sh start


./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /Users/dugang/soft/apps/zkcluster/z4/bin/../conf/zoo.cfg
Mode: observer



Mode
leader follower  observer


监控 4字命令 和 jmx

 zookeeper常用运维命令 

重要的 4字命令 
stat srvr cons

Three of the more interesting commands: 
"stat" gives some general information about the server and connected clients, 
while "srvr" and "cons" give extended details on server and connections respectively.





./zkCli.sh   -server 127.0.0.1:2183

echo conf|nc localhost 2183
clientPort=2183
dataDir=/Users/dugang/soft/apps/zkcluster/z2/data/version-2
dataLogDir=/Users/dugang/soft/apps/zkcluster/z2/data/version-2
tickTime=2000
maxClientCnxns=60
minSessionTimeout=4000
maxSessionTimeout=40000
serverId=2
initLimit=10
syncLimit=5
electionAlg=3
electionPort=4183
quorumPort=3183
peerType=0





使用 jvisualvm 查看 jmx 信息 mbeans org.apache.ZookeeperService 集群成员列表 角色(follower leader observer)节点下 的 QuorumAddress 指向 leader
kafka集群搭建 dubbo实例

上一篇     下一篇
clickhouse SQL

clickhouse基础

clickhouse存储层与计算层

互联网广告术语解释

linux sort 命令

Java黑科技VirtualMachine