ZooKeeper单机伪集群搭建与启动
下载解压
[xiaobai@xiaobai ~]$ tar -zvxf zookeeper-3.4.9.tar.gz
本机ip地址映射
[xiaobai@xiaobai /]$ su - root
Password:
Last login: Sat Aug 4 18:59:38 EDT 2018 on :0
[root@xiaobai ~]# cd /etc
[root@xiaobai etc]# vim hosts
将本机ip映射为一个主机名,在zoo.cfg中可用这个主机名代替ip来配置:
添加一行:
172.20.10.60 xiaobai-rhel7
保存,退出,切换回普通用户.
详细配置
[xiaobai@xiaobai conf]$ cp zoo_sample.cfg zoo.cfg
[xiaobai@xiaobai conf]$ vim zoo.cfg
配置项值及含义:
tickTime=2000 心跳间隔(ms)
initLimit=10 集群初始化连接间隔最大心跳个数
syncLimit=5 集群Follower与Leader请求与应答间隔最大心跳个数
dataDir=/home/xiaobai/zookeeper-3.4.9/data 集群中该点数据存储目录
dataLogDir=/home/xiaobai/zookeeper-3.4.9/logs 集群中该点日志存储目录
clientPort=2181 客户端访问端口,如是伪集群,每个点该端口都应不同,否则会端口冲突,只能启动一个点,客户端根据多点不同端口进行配置(配置每个点的ip:端口)
集群server配置:
server.1=xiaobai-rhel7:2888:3888
server.2=xiaobai-rhel7:4888:5888
server.3=xiaobai-rhel7:6888:7888
集群中的点至少3个,伪集群要保证端口都不相同,否则端口冲突。与该点ip、端口匹配的的server.xxx...,server.后面的数字与该点配置的myid内容应相同
在每个点配置的data目录中创建名为myid的文件,编辑内容为该点对应的数字
环境变量
用户主目录下执行:
[xiaobai@xiaobai ~]$ vim .bash_profile
配置内容:
#zookeeper env
export ZOOKEEPER_HOME=/home/xiaobai/zookeeper-3.4.9
PATH=$ZOOKEEPER_HOME/bin:$PATH:$HOME/.local/bin:$HOME/bin
export PATH
注意第一行的变量ZOOKEEPER_HOME定义不要写成$ZOOKEEPER_HOME
使配置生效:
[xiaobai@xiaobai ~]$ source .bash_profile
这个配置主要在真正集群环境每个点有意义,方便在任何目录下直接使用ZooKeeper命令。在这里反而引起了误解:在伪集群的每个点应该使用全限定名或./xxx执行ZooKeeper命令(比如后面的启动后查看状态),否则生效的永远是在这里配置了路径的那个点的。这里仅作原理演示。
RHEL7防火墙设置
防火墙需要打开ZooKeeper集群中每个点所使用的端口,这里一共是9个。RHEL7的默认防火墙工具有很大变化。这里仍然使用6及以前的iptables方式,提示及切换效果如下:
[xiaobai@xiaobai ~]$ su - root
Password:
Last login: Sat Aug 4 19:39:17 EDT 2018 on pts/0
[root@xiaobai ~]# chkconfig iptables on
Note: Forwarding request to 'systemctl enable iptables.service'.
ln -s '/usr/lib/systemd/system/iptables.service' '/etc/systemd/system/basic.target.wants/iptables.service'
[root@xiaobai ~]# systemctl enable iptables.service
[root@xiaobai ~]# service iptables start
Redirecting to /bin/systemctl start iptables.service
[root@xiaobai ~]# systemctl start iptables.service
[root@xiaobai ~]# vim /etc/sysconfig/iptables
[root@xiaobai ~]# service iptables restart
Redirecting to /bin/systemctl restart iptables.service
[root@xiaobai ~]# systemctl restart iptables.service
[root@xiaobai ~]# service iptables status
Redirecting to /bin/systemctl status iptables.service
iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled)
Active: active (exited) since Sat 2018-08-04 21:21:57 EDT; 17s ago
Process: 9208 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
Process: 9259 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 9259 (code=exited, status=0/SUCCESS)
Aug 04 21:21:57 xiaobai.rhel7 systemd[1]: Starting IPv4 firewall with iptables...
Aug 04 21:21:57 xiaobai.rhel7 iptables.init[9259]: iptables: Applying firewall rules: [ OK ]
Aug 04 21:21:57 xiaobai.rhel7 systemd[1]: Started IPv4 firewall with iptables.
[root@xiaobai ~]# systemctl status iptables.service
iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled)
Active: active (exited) since Sat 2018-08-04 21:21:57 EDT; 1min 32s ago
Process: 9208 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
Process: 9259 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 9259 (code=exited, status=0/SUCCESS)
Aug 04 21:21:57 xiaobai.rhel7 systemd[1]: Starting IPv4 firewall with iptables...
Aug 04 21:21:57 xiaobai.rhel7 iptables.init[9259]: iptables: Applying firewall rules: [ OK ]
Aug 04 21:21:57 xiaobai.rhel7 systemd[1]: Started IPv4 firewall with iptables.
iptables文件最终配置内容(新增):
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2181 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2182 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2183 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2888 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3888 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4888 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5888 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6888 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7888 -j ACCEPT
集群启动
拷贝一个配置好的点的整个ZooKeeper目录,做出另外两个点。真正集群几个点的配置是完全相同的。这里的伪集群中,server集群配置不需要改动,所有点ip与端口都已配置好。只需修改每个点的clientPort为不同的,防止端口冲突;修改每个点的dataDir与dataLogDir配置,成该点对应的目录。
启动每个点:
使用普通用户,到该点目录使用./xxx而不是默认环境变量配置的方式启动:
[xiaobai@xiaobai bin]$ cd ../../zookeeper-3.4.9/bin
[xiaobai@xiaobai bin]$ ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/xiaobai/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
Java进程查看:
[xiaobai@xiaobai bin]$ ps -ef|grep java
xiaobai 10643 1 1 21:50 pts/0 00:00:00 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/xiaobai/zookeeper-3.4.9_2/bin/../build/classes:/home/xiaobai/zookeeper-3.4.9_2/bin/../build/lib/*.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/slf4j-api-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/netty-3.10.5.Final.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/log4j-1.2.16.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/jline-0.9.94.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../zookeeper-3.4.9.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../src/java/lib/*.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/xiaobai/zookeeper-3.4.9_2/bin/../conf/zoo.cfg
xiaobai 10672 1 1 21:51 pts/0 00:00:00 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/xiaobai/zookeeper-3.4.9/bin/../build/classes:/home/xiaobai/zookeeper-3.4.9/bin/../build/lib/*.jar:/home/xiaobai/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9/bin/../lib/netty-3.10.5.Final.jar:/home/xiaobai/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.jar:/home/xiaobai/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/home/xiaobai/zookeeper-3.4.9/bin/../zookeeper-3.4.9.jar:/home/xiaobai/zookeeper-3.4.9/bin/../src/java/lib/*.jar:/home/xiaobai/zookeeper-3.4.9/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/xiaobai/zookeeper-3.4.9/bin/../conf/zoo.cfg
xiaobai 10715 1 5 21:51 pts/0 00:00:00 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/xiaobai/zookeeper-3.4.9_3/bin/../build/classes:/home/xiaobai/zookeeper-3.4.9_3/bin/../build/lib/*.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/slf4j-api-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/netty-3.10.5.Final.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/log4j-1.2.16.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/jline-0.9.94.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../zookeeper-3.4.9.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../src/java/lib/*.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/xiaobai/zookeeper-3.4.9_3/bin/../conf/zoo.cfg
xiaobai 10755 9691 0 21:51 pts/0 00:00:00 grep --color=auto java
jps查看:
[xiaobai@xiaobai zookeeper-3.4.9_3]$ jps
10715 QuorumPeerMain
10672 QuorumPeerMain
10765 Jps
10643 QuorumPeerMain
其中QuorumPeerMain为每个点的ZooKeeper主进程
状态监控
这里使用ZooKeeper命令。因为前面环境变量配置中配置了其中一个点的路径为ZOOKEEPER_HOME,所以这里就不能直接使用命令,这样永远只看到这个配置的点的。需要到每个点路径下使用./xxx这种相对路径或者全限定名路径:
其中的一个点:
[xiaobai@xiaobai bin]$ pwd
/home/xiaobai/zookeeper-3.4.9/bin
[xiaobai@xiaobai bin]$ cd ../../zookeeper-3.4.9_2/bin
[xiaobai@xiaobai bin]$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/xiaobai/zookeeper-3.4.9_2/bin/../conf/zoo.cfg
Mode: leader
客户端访问(ZkClient客户端,单实例版)
依赖:
<!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.9</version> </dependency> <!-- https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient --> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency>
代码:
package com.xiaobai.zkclient; import java.util.List; import org.I0Itec.zkclient.IZkChildListener; import org.I0Itec.zkclient.IZkDataListener; import org.I0Itec.zkclient.ZkClient; /** * Hello world! * */ public class ZClient { private void client() { ZkClient client = new ZkClient("127.0.0.1:2181", 5000); String path = "/zk-book/cl"; client.createPersistent(path, true); } private void listener() throws InterruptedException { ZkClient client = new ZkClient("127.0.0.1:2181", 5000); String path = "/zk-book11"; client.subscribeChildChanges(path, new IZkChildListener() { public void handleChildChange(String parentPath, List<String> currentChildren) throws Exception { System.out.println(parentPath + "'s children changed,current children:" + currentChildren); } }); //节点是否存在 System.out.println("Node Exists:" + client.exists(path)); //节点不存在也可通知: client.createPersistent(path); Thread.sleep(1000); System.out.println("Node Exists:" + client.exists(path)); //获取子节点 System.out.println(client.getChildren(path)); client.createPersistent(path + "/cl"); Thread.sleep(1000); client.delete(path + "/cl"); Thread.sleep(1000); client.delete(path); Thread.sleep(Integer.MAX_VALUE); } private void read() throws InterruptedException { ZkClient client = new ZkClient("127.0.0.1:2181", 5000); String path = "/zk-book222"; //节点是否存在 System.out.println("Node Exists:" + client.exists(path)); client.createEphemeral(path, "123");//数据为123 System.out.println("Node Exists:" + client.exists(path)); client.subscribeDataChanges(path, new IZkDataListener() { public void handleDataDeleted(String dataPath) throws Exception { System.out.println("Node" + dataPath + " deleted"); } public void handleDataChange(String dataPath, Object data) throws Exception { System.out.println("Node" + dataPath + " changed,new data:" + data); } }); System.out.println(client.readData(path));//获取节点数据 client.writeData(path, "456");//写数据 Thread.sleep(1000); client.delete(path); Thread.sleep(Integer.MAX_VALUE); } public static void main( String[] args ) throws InterruptedException { ZClient cl = new ZClient(); // cl.client(); cl.listener(); // cl.read(); System.out.println( "Hello World!" ); } }
输出:
listener方法:
Node Exists:false
/zk-book11's children changed,current children:[]
Node Exists:true
[]
/zk-book11's children changed,current children:[cl]
/zk-book11's children changed,current children:[]
/zk-book11's children changed,current children:null
read方法:
Node Exists:false
Node Exists:true
123
Node/zk-book222 changed,new data:456
Node/zk-book222 deleted
日志监控
启动日志:(其中一个点bin目录下的zookeeper.out文件)
[xiaobai@xiaobai bin]$ tail -100f zookeeper.out
2018-08-04 21:51:26,856 [myid:] - INFO [main:QuorumPeerConfig@124] - Reading configuration from: /home/xiaobai/zookeeper-3.4.9_3/bin/../conf/zoo.cfg
2018-08-04 21:51:26,879 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:51:26,879 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:51:26,880 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:51:26,880 [myid:] - INFO [main:QuorumPeerConfig@352] - Defaulting to majority quorums
2018-08-04 21:51:26,883 [myid:3] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2018-08-04 21:51:26,883 [myid:3] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2018-08-04 21:51:26,883 [myid:3] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2018-08-04 21:51:26,921 [myid:3] - INFO [main:QuorumPeerMain@127] - Starting quorum peer
2018-08-04 21:51:26,935 [myid:3] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2183
2018-08-04 21:51:26,944 [myid:3] - INFO [main:QuorumPeer@1019] - tickTime set to 2000
2018-08-04 21:51:26,944 [myid:3] - INFO [main:QuorumPeer@1039] - minSessionTimeout set to -1
2018-08-04 21:51:26,944 [myid:3] - INFO [main:QuorumPeer@1050] - maxSessionTimeout set to -1
2018-08-04 21:51:26,944 [myid:3] - INFO [main:QuorumPeer@1065] - initLimit set to 10
2018-08-04 21:51:26,959 [myid:3] - INFO [main:QuorumPeer@533] - currentEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation
2018-08-04 21:51:26,961 [myid:3] - INFO [main:QuorumPeer@548] - acceptedEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation
2018-08-04 21:51:26,972 [myid:3] - INFO [ListenerThread:QuorumCnxManager$Listener@534] - My election bind port: xiaobai-rhel7/172.20.10.60:7888
2018-08-04 21:51:26,978 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:QuorumPeer@774] - LOOKING
2018-08-04 21:51:26,979 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:FastLeaderElection@818] - New election. My id = 3, proposed zxid=0x0
2018-08-04 21:51:27,031 [myid:3] - INFO [WorkerReceiver[myid=3]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 3 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2018-08-04 21:51:27,082 [myid:3] - INFO [WorkerReceiver[myid=3]:FastLeaderElection@600] - Notification: 1 (message format version), 2 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 2 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2018-08-04 21:51:27,082 [myid:3] - INFO [WorkerReceiver[myid=3]:FastLeaderElection@600] - Notification: 1 (message format version), 2 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2018-08-04 21:51:27,082 [myid:3] - INFO [WorkerReceiver[myid=3]:FastLeaderElection@600] - Notification: 1 (message format version), 2 (n.leader), 0x0 (n.zxid), 0x1 (n.round), FOLLOWING (n.state), 1 (n.sid), 0x1 (n.peerEpoch) LOOKING (my state)
2018-08-04 21:51:27,083 [myid:3] - INFO [WorkerReceiver[myid=3]:FastLeaderElection@600] - Notification: 1 (message format version), 2 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LEADING (n.state), 2 (n.sid), 0x1 (n.peerEpoch) LOOKING (my state)
2018-08-04 21:51:27,084 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:QuorumPeer@844] - FOLLOWING
2018-08-04 21:51:27,089 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Learner@86] - TCP NoDelay set to: true
2018-08-04 21:51:27,117 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
2018-08-04 21:51:27,118 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:host.name=<NA>
2018-08-04 21:51:27,118 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:java.version=1.7.0_51
2018-08-04 21:51:27,118 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:java.vendor=Oracle Corporation
2018-08-04 21:51:27,119 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64/jre
2018-08-04 21:51:27,119 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:java.class.path=/home/xiaobai/zookeeper-3.4.9_3/bin/../build/classes:/home/xiaobai/zookeeper-3.4.9_3/bin/../build/lib/*.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/slf4j-api-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/netty-3.10.5.Final.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/log4j-1.2.16.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../lib/jline-0.9.94.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../zookeeper-3.4.9.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../src/java/lib/*.jar:/home/xiaobai/zookeeper-3.4.9_3/bin/../conf:
2018-08-04 21:51:27,119 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-08-04 21:51:27,119 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:java.io.tmpdir=/tmp
2018-08-04 21:51:27,119 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:java.compiler=<NA>
2018-08-04 21:51:27,119 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:os.name=Linux
2018-08-04 21:51:27,119 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:os.arch=amd64
2018-08-04 21:51:27,120 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:os.version=3.10.0-123.el7.x86_64
2018-08-04 21:51:27,120 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:user.name=xiaobai
2018-08-04 21:51:27,120 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:user.home=/home/xiaobai
2018-08-04 21:51:27,120 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Environment@100] - Server environment:user.dir=/home/xiaobai/zookeeper-3.4.9_3/bin
2018-08-04 21:51:27,122 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:ZooKeeperServer@173] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir /home/xiaobai/zookeeper-3.4.9_3/logs/version-2 snapdir /home/xiaobai/zookeeper-3.4.9_3/data/version-2
2018-08-04 21:51:27,123 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Follower@61] - FOLLOWING - LEADER ELECTION TOOK - 144
2018-08-04 21:51:27,125 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:51:27,132 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:Learner@329] - Getting a snapshot from leader
2018-08-04 21:51:27,141 [myid:3] - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2183:FileTxnSnapLog@240] - Snapshotting: 0x100000000 to /home/xiaobai/zookeeper-3.4.9_3/data/version-2/snapshot.100000000
Leader节点启动日志:
[xiaobai@xiaobai bin]$ tail -1000f zookeeper.out
2018-08-04 21:50:54,435 [myid:] - INFO [main:QuorumPeerConfig@124] - Reading configuration from: /home/xiaobai/zookeeper-3.4.9_2/bin/../conf/zoo.cfg
2018-08-04 21:50:54,452 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:54,452 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:54,453 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:54,453 [myid:] - INFO [main:QuorumPeerConfig@352] - Defaulting to majority quorums
2018-08-04 21:50:54,456 [myid:2] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2018-08-04 21:50:54,456 [myid:2] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2018-08-04 21:50:54,456 [myid:2] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2018-08-04 21:50:54,469 [myid:2] - INFO [main:QuorumPeerMain@127] - Starting quorum peer
2018-08-04 21:50:54,493 [myid:2] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2182
2018-08-04 21:50:54,500 [myid:2] - INFO [main:QuorumPeer@1019] - tickTime set to 2000
2018-08-04 21:50:54,500 [myid:2] - INFO [main:QuorumPeer@1039] - minSessionTimeout set to -1
2018-08-04 21:50:54,500 [myid:2] - INFO [main:QuorumPeer@1050] - maxSessionTimeout set to -1
2018-08-04 21:50:54,500 [myid:2] - INFO [main:QuorumPeer@1065] - initLimit set to 10
2018-08-04 21:50:54,520 [myid:2] - INFO [ListenerThread:QuorumCnxManager$Listener@534] - My election bind port: xiaobai-rhel7/172.20.10.60:5888
2018-08-04 21:50:54,530 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer@774] - LOOKING
2018-08-04 21:50:54,533 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:FastLeaderElection@818] - New election. My id = 2, proposed zxid=0x0
2018-08-04 21:50:54,536 [myid:2] - WARN [WorkerSender[myid=2]:QuorumCnxManager@400] - Cannot open channel to 1 at election address xiaobai-rhel7/172.20.10.60:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:354)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:452)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:433)
at java.lang.Thread.run(Thread.java:744)
2018-08-04 21:50:54,537 [myid:2] - INFO [WorkerSender[myid=2]:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:54,538 [myid:2] - WARN [WorkerSender[myid=2]:QuorumCnxManager@400] - Cannot open channel to 3 at election address xiaobai-rhel7/172.20.10.60:7888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:354)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:452)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:433)
at java.lang.Thread.run(Thread.java:744)
2018-08-04 21:50:54,539 [myid:2] - INFO [WorkerSender[myid=2]:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:54,539 [myid:2] - INFO [WorkerReceiver[myid=2]:FastLeaderElection@600] - Notification: 1 (message format version), 2 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 2 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2018-08-04 21:50:54,741 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 1 at election address xiaobai-rhel7/172.20.10.60:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:50:54,742 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:54,742 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 3 at election address xiaobai-rhel7/172.20.10.60:7888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:50:54,743 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:54,743 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:FastLeaderElection@852] - Notification time out: 400
2018-08-04 21:50:55,144 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 1 at election address xiaobai-rhel7/172.20.10.60:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:50:55,144 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:55,145 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 3 at election address xiaobai-rhel7/172.20.10.60:7888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:50:55,145 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:55,145 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:FastLeaderElection@852] - Notification time out: 800
2018-08-04 21:50:55,946 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 1 at election address xiaobai-rhel7/172.20.10.60:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:50:55,956 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:55,956 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 3 at election address xiaobai-rhel7/172.20.10.60:7888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:50:55,957 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:55,957 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:FastLeaderElection@852] - Notification time out: 1600
2018-08-04 21:50:57,558 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 1 at election address xiaobai-rhel7/172.20.10.60:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:50:57,559 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:57,559 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 3 at election address xiaobai-rhel7/172.20.10.60:7888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:50:57,560 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:50:57,560 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:FastLeaderElection@852] - Notification time out: 3200
2018-08-04 21:51:00,761 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 1 at election address xiaobai-rhel7/172.20.10.60:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:51:00,761 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:51:00,762 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 3 at election address xiaobai-rhel7/172.20.10.60:7888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:51:00,762 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:51:00,762 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:FastLeaderElection@852] - Notification time out: 6400
2018-08-04 21:51:07,163 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 1 at election address xiaobai-rhel7/172.20.10.60:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:51:07,163 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:51:07,164 [myid:2] - WARN [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumCnxManager@400] - Cannot open channel to 3 at election address xiaobai-rhel7/172.20.10.60:7888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)
2018-08-04 21:51:07,164 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer$QuorumServer@149] - Resolved hostname: xiaobai-rhel7 to address: xiaobai-rhel7/172.20.10.60
2018-08-04 21:51:07,164 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:FastLeaderElection@852] - Notification time out: 12800
2018-08-04 21:51:08,911 [myid:2] - INFO [xiaobai-rhel7/172.20.10.60:5888:QuorumCnxManager$Listener@541] - Received connection request /172.20.10.60:35955
2018-08-04 21:51:08,921 [myid:2] - INFO [WorkerReceiver[myid=2]:FastLeaderElection@600] - Notification: 1 (message format version), 1 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2018-08-04 21:51:08,934 [myid:2] - INFO [WorkerReceiver[myid=2]:FastLeaderElection@600] - Notification: 1 (message format version), 2 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2018-08-04 21:51:09,138 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:QuorumPeer@856] - LEADING
2018-08-04 21:51:09,142 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Leader@59] - TCP NoDelay set to: true
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:host.name=<NA>
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:java.version=1.7.0_51
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:java.vendor=Oracle Corporation
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64/jre
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:java.class.path=/home/xiaobai/zookeeper-3.4.9_2/bin/../build/classes:/home/xiaobai/zookeeper-3.4.9_2/bin/../build/lib/*.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/slf4j-api-1.6.1.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/netty-3.10.5.Final.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/log4j-1.2.16.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../lib/jline-0.9.94.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../zookeeper-3.4.9.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../src/java/lib/*.jar:/home/xiaobai/zookeeper-3.4.9_2/bin/../conf:
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:java.io.tmpdir=/tmp
2018-08-04 21:51:09,179 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:java.compiler=<NA>
2018-08-04 21:51:09,180 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:os.name=Linux
2018-08-04 21:51:09,180 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:os.arch=amd64
2018-08-04 21:51:09,180 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:os.version=3.10.0-123.el7.x86_64
2018-08-04 21:51:09,180 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:user.name=xiaobai
2018-08-04 21:51:09,180 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:user.home=/home/xiaobai
2018-08-04 21:51:09,180 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Environment@100] - Server environment:user.dir=/home/xiaobai/zookeeper-3.4.9_2/bin
2018-08-04 21:51:09,182 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:ZooKeeperServer@173] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir /home/xiaobai/zookeeper-3.4.9_2/logs/version-2 snapdir /home/xiaobai/zookeeper-3.4.9_2/data/version-2
2018-08-04 21:51:09,183 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Leader@361] - LEADING - LEADER ELECTION TOOK - 14650
2018-08-04 21:51:09,206 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46191:LearnerHandler@329] - Follower sid: 1 : info : org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer@94eefbf
2018-08-04 21:51:09,209 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46191:LearnerHandler@384] - Synchronizing with Follower sid: 1 maxCommittedLog=0x0 minCommittedLog=0x0 peerLastZxid=0x0
2018-08-04 21:51:09,209 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46191:LearnerHandler@393] - leader and follower are in sync, zxid=0x0
2018-08-04 21:51:09,209 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46191:LearnerHandler@458] - Sending DIFF
2018-08-04 21:51:09,237 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46191:LearnerHandler@518] - Received NEWLEADER-ACK message from 1
2018-08-04 21:51:09,238 [myid:2] - INFO [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2182:Leader@952] - Have quorum of supporters, sids: [ 1,2 ]; starting up and setting last processed zxid: 0x100000000
2018-08-04 21:51:27,019 [myid:2] - INFO [xiaobai-rhel7/172.20.10.60:5888:QuorumCnxManager$Listener@541] - Received connection request /172.20.10.60:35961
2018-08-04 21:51:27,083 [myid:2] - INFO [WorkerReceiver[myid=2]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 3 (n.sid), 0x0 (n.peerEpoch) LEADING (my state)
2018-08-04 21:51:27,129 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46194:LearnerHandler@329] - Follower sid: 3 : info : org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer@64b36a83
2018-08-04 21:51:27,130 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46194:LearnerHandler@384] - Synchronizing with Follower sid: 3 maxCommittedLog=0x0 minCommittedLog=0x0 peerLastZxid=0x0
2018-08-04 21:51:27,130 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46194:LearnerHandler@458] - Sending SNAP
2018-08-04 21:51:27,130 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46194:LearnerHandler@482] - Sending snapshot last zxid of peer is 0x0 zxid of leader is 0x100000000sent zxid of db as 0x100000000
2018-08-04 21:51:27,144 [myid:2] - INFO [LearnerHandler-/172.20.10.60:46194:LearnerHandler@518] - Received NEWLEADER-ACK message from 3
2018-08-04 22:00:43,539 [myid:2] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2182:NIOServerCnxnFactory@192] - Accepted socket connection from /127.0.0.1:48578
2018-08-04 22:00:43,543 [myid:2] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2182:NIOServerCnxn@827] - Processing srvr command from /127.0.0.1:48578
2018-08-04 22:00:43,546 [myid:2] - INFO [Thread-3:NIOServerCnxn@1008] - Closed socket connection for client /127.0.0.1:48578 (no session established for client)
注:首次启动一般看不到日志文件,需要restart才能看到!
开机启动
[root@xiaobai-rhel7 ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Aug 19 12:15 /etc/rc.local -> rc.d/rc.local
由此可见/etc/rc.local只是一个到/etc/rc.d/rc.local的一个软连接,那么:
[root@xiaobai-rhel7 ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 536 Aug 31 19:30 /etc/rc.d/rc.local
发现原文件没有可执行权限!所以此前在里面写启动脚本才不会执行!
所以:
[root@xiaobai-rhel7 ~]# chmod +x /etc/rc.d/rc.local
这个文件的注释里其实也有提示:
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
root用户编辑/etc/rc.local文件,添加:
(执行脚本全路径)
/home/xiaobai/zkCluster.sh
/root/soft/redisClusterStart.sh
确保每个脚本都有可执行权限,且在任何用户下都有(拥有者、组、其他人)
也要确保登录用户对脚本中的命令都有执行权限