1. Exception information

Symptom The ZooKeeper cluster fails to be started, and the following error message is displayed:

2021-07-11 20:47:440/010 [myID :2] - INFO [QuorumPeer[myid=2](plain=[0:0:0:0:0:0:0:0]:2181)(secure=disabled):ZooKeeperServer@166] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir /opt/module/apache-zookeeper-3.5.7-bin/zkData/version-2 Snapdir /opt/module/apache-zookeeper-3.5.7-bin/zkData/version-2 2021-07-11 20:47:40,011 [myID :2] -error snapdir /opt/module/apache-zookeeper-3.5.7-bin/zkData/version-2 2021-07-11 20:47:40,011 [myID :2] -error [QuorumPeer[myid=2](plain=[0:0:0:0:0:0:0:0]:2181)(secure=disabled):Leader@260] - Couldn't bind to Java.net.BindException: hadoop10/172.16.24.10:2888 Unable to specify the requested address (Bind failed) at java.net.PlainSocketImpl.socketBind (Native Method) at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387) at java.net.ServerSocket.bind(ServerSocket.java:375) at java.net.ServerSocket.bind(ServerSocket.java:329) at org.apache.zookeeper.server.quorum.Leader.<init>(Leader.java:254) at org.apache.zookeeper.server.quorum.QuorumPeer.makeLeader(QuorumPeer.java:1057) at . Org. Apache. Zookeeper server. Quorum. QuorumPeer. Run (1265) QuorumPeer. Java: the 2021-07-11 20:47:40, 011 [myid: 2] - a WARN [QuorumPeer[myid=2](plain=[0:0:0:0:0:0:0:0]:2181)(secure=disabled):QuorumPeer@1269] - Unexpected exception java.net.BindException: Unable to specify the requested address (Bind failed) at java.net.PlainSocketImpl.socketBind (Native Method) at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387) at java.net.ServerSocket.bind(ServerSocket.java:375) at java.net.ServerSocket.bind(ServerSocket.java:329) at org.apache.zookeeper.server.quorum.Leader.<init>(Leader.java:254) at org.apache.zookeeper.server.quorum.QuorumPeer.makeLeader(QuorumPeer.java:1057) at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:1265)Copy the code

The solution

Configure zoo. CFG as follows

quorumListenOnAllIPs=true

supplement

Pay special attention to the ZooeKeeper configuration

  1. CFG file, must pay attention to server.a. ostName, must correspond to myID, the above problem, later found, is actually caused by configuration, configuration must be clear. Therefore, you do not need to configure quorumListenOnAllIPs=true to solve the problem

It was said on the Internet that it was caused by different time. My system cluster happened to have different time synchronization. However, I did time synchronization later, but it still failed

Configure cluster time synchronization

2. Synchronize the cluster time service

  1. Several commonly used time service commands
  1. NTPD service status: systemctl status NTPD
  2. NTPD Whether to enable the startup upon startup: systemctl is-enabled NTPD
  3. Run the systemctl stop NTPD command to stop the NTPD service
  4. Disable automatic NTPD: systemctl disable NTPD
  5. Enable the NTPD startup command: systemctl enable NTPD
  6. Run the systemctl start NTPD command to start the NTPD service
  1. Roadmap for configuring time synchronization in a cluster

With one service as the time synchronization service, the event timing of other machines synchronizes with the synchronization service machine

3. Specific operations

0. Prerequisites: Ensure that the NTP plug-in has been installed in the system

1. Stop all NTP services and automatic startup in the cluster

systemctl stop ntpd
systemctl disable ntpd
Copy the code

2. Perform the following operations on the time synchronization service

1. Modify the /etc/ntp.conf file

Vim /etc/ntp.conf Modified as follows: 1. Modified 1#Restrict 192.168.1.0 Mask 255.255.255.0 nomodify NotrapSet restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 2. Change 2: (The cluster is on a LAN, Do not use other Internet times) server 0.centos.pool.ntp.org iBurst server 1.centos.pool.ntp.org iBurst server 2.centos.pool.ntp.org iburst Server 3.centos.pool.ntp.org iburst Changed to#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst3. Add 3 (if this node loses its network connection, the local time can still be used as the time server to synchronize time to other nodes in the cluster.) Server 127.127.1.0 fudge 127.127.1.0 stratum 10Copy the code

2. Modify the /etc/sysconfig/ntpd file

Vim /etc/sysconfig/ntpd Add the following information (synchronize hardware time with system time) SYNC_HWCLOCK=yesCopy the code

3. Restart the NTPD service

systemctl start ntpd
Copy the code

4. Enable the NTPD service to start upon startup

systemctl enable ntpd
Copy the code

3. Other machine configurations

Run the scheduled task crontab -e. 2. Enable synchronization every 10 minutes */10 * * * * /usr/sbin/ntpdate hadoop10. 3Copy the code

4. Other issues (My cluster was in a different time zone in addition to time inconsistency. So if you are in a different time zone, you need to change the time zone to be consistent.

  1. Using the command

tzselect

  1. Option 5 Asia
  2. Choose 9 China
  3. Option 1 Beijing