- 先像第一台一样配置2台服务器
- 在zkData文件夹下新建文件myid
- 内容是这个服务器的唯一标识,第一台1,第二台2,第三台3(自定义想用什么数字表示都可以)
- 打开zoo.cfg配置文件,添加集群配置:
server.128=192.168.59.128:2888:3888
server.129=192.168.59.129:2888:3888
server.130=192.168.59.130:2888:3888
格式为:server.A=B:C:D
A:刚刚myid中定义的唯一标识数字
B:服务器的地址
C:服务器Follower与集群中leader服务器交换信息的端口
D:万一集群中leader服务器挂了,需要一个端口来重新选举,选出一个新leader,这个端口就是用来执行选举时服务器相互通信的端口
配置完成后分包发送给其他服务器,使用xsync,然后进入bin目录
Xsync zoo.cfg
随后出现如下:
[root@localhost bin]# xsync /opt/module/zookeeper-3.5.7/conf/zoo.cfg
fname=zoo.cfg
pdir=/opt/module/zookeeper-3.5.7/conf
------------------- hadoop128 --------------
root@hadoop128's password:
sending incremental file list
sent 44 bytes received 12 bytes 22.40 bytes/sec
total size is 1,050 speedup is 18.75
------------------- hadoop129 --------------
root@hadoop129's password:
sending incremental file list
zoo.cfg
sent 445 bytes received 47 bytes 109.33 bytes/sec
total size is 1,050 speedup is 2.13
------------------- hadoop130 --------------
root@hadoop130's password:
sending incremental file list
zoo.cfg
sent 445 bytes received 47 bytes 140.57 bytes/sec
total size is 1,050 speedup is 2.13
[root@localhost bin]#
输入相对应的密码便可以实现分发
配置xsync:
xsync的使用和配置
使用zookeeper常用命令启动zookeeper,分别查看状态可以看到
[root@localhost bin]# ./zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
[root@localhost bin]# ./zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[root@localhost bin]# ./zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower