在要开启的三个zookeeper服务器的配置文件都配置完后,我开始运行服务器。
xshell开启三个窗口。运行第一个服务器时时显示如下:
[root@iZ2zef08gmoio8jyeyjvi7Z ~]# cd /usr/local/zookeeper-cluster/
[root@iZ2zef08gmoio8jyeyjvi7Z zookeeper-cluster]# ./zk1/bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-cluster/zk1/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@iZ2zef08gmoio8jyeyjvi7Z zookeeper-cluster]# ./zk1/bin/zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-cluster/zk1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.
一个服务器不足以选举Leader。那开启第二个服务器。
[root@iZ2zef08gmoio8jyeyjvi7Z ~]# cd /usr/local/zookeeper-cluster/
[root@iZ2zef08gmoio8jyeyjvi7Z zookeeper-cluster]# ./zk1/bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-cluster/zk2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@iZ2zef08gmoio8jyeyjvi7Z zookeeper-cluster]# ./zk2/bin/zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-cluster/zk2/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.
结果还是一样的…
Client port found: 2181. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.
开启第三个服务器依然是这样。这让我又去检查了一遍zoo.cfg配置文件。如下:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper-cluster/zk1/data
#zookeeper的日志目录
dataLogDir=/usr/local/zookeeper-cluster/zk1/log
# the port at which the clients will connect
clientPort=2181
# 集群的配置文件
#第几个服务器(1,2,3来自数据目录的一个myid文件,该文件里面保存着当前集群的标识(1,2,3))
# 后面的ip代表将绑定那个ip地址 第一个端口:代表在集群内部,数据复制的接口 第二个端口代表:选举##端口
server.1=172.27.36.23:2888:3888
server.2=172.27.36.23:2889:3889
server.3=172.27.36.23:2887:3887
# the maximum number of client connections.
"./zk1/conf/zoo.cfg" 37L, 1421C
感觉没啥问题。想了半天突然想到是不是ip地址写错了,我写的是公网ip,那换成私网ip。更改完成后再按上面步骤来一遍。结果如下:
终于成功了。Mode:follower。虽然还是不太明白为啥要用私网ip。