Zookeeper启动失败排错

China☆狼群 提交于 2019-12-05 05:43:22

1、执行zkServer.sh start 后报错:

root@zServer-2-8:/opt/zookeeper-3.4.13/bin# sh zkServer.sh start
JMX enabled by default
bin/zkServer.sh: 95: /opt/zookeeper-3.4.13/bin/zkEnv.sh: Syntax error: "(" unexpected (expecting "fi")

原因:Ubuntu的bash问题,默认是dash,可以通过ls -l /bin/sh查看

解决:更换dash为bash,命令ln -sf bash /bin/sh

2、执行zkServer.sh start 后显示,但Zookeeper未启动成功:

JMX enabled by default
Using config:/home/hadoop/app/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

3、jps后发现没有QuorumPeerMain进程

4、查看zookeeper.out文件(默认在zookeeper的bin目录下),内容如下:

2018-12-08 02:59:24,056 [myid:] - INFO  [main:QuorumPeerConfig@136] - Reading configuration from: /opt/zookeeper-3.4.13/bin/../conf/zoo.cfg
2018-12-08 02:59:24,250 [myid:] - WARN  [main:QuorumPeer$QuorumServer@190] - Failed to resolve address: hqhServer
java.net.UnknownHostException: hqhServer
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:923)
	at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1302)
	at java.net.InetAddress.getAllByName0(InetAddress.java:1253)
	at java.net.InetAddress.getAllByName(InetAddress.java:1184)
	at java.net.InetAddress.getAllByName(InetAddress.java:1120)
	at java.net.InetAddress.getByName(InetAddress.java:1070)
	at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.recreateSocketAddresses(QuorumPeer.java:180)
	at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.<init>(QuorumPeer.java:152)
	at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:240)
	at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:152)
	at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:104)
	at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:81)
2018-12-08 02:59:24,252 [myid:] - INFO  [main:QuorumPeer$QuorumServer@184] - Resolved hostname: ubuntu to address: ubuntu/127.0.1.1
2018-12-08 02:59:24,264 [myid:] - INFO  [main:QuorumPeer$QuorumServer@184] - Resolved hostname: huangqh-PC to address: huangqh-PC/11.1.2.1
2018-12-08 02:59:24,264 [myid:] - ERROR [main:QuorumPeerMain@88] - Invalid config, exiting abnormally
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /opt/zookeeper-3.4.13/bin/../conf/zoo.cfg
	at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:156)
	at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:104)
	at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:81)
Caused by: java.lang.IllegalArgumentException: minSessionTimeout must not be larger than maxSessionTimeout
	at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:329)
	at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:152)
	... 2 more
Invalid config, exiting abnormally

5、根据.out的信息找不到主机hqhServer,然后检查/etc/hostname和/etc/hosts是否有主机名hqhServer, 在大多数Linux操作系统中,都是以/etc/hosts中的配置查找主机名的,以下是两文件内容,发现/etc/hosts中没有hqhServer,如下:

在这里插入图片描述
原因:当时修改主机名只改了/etc/hostname,忘记改/etc/hosts了。
解决:把/etc/hosts中的ubuntu改为hqhServer,然后保存,然后在报错系统的/etc/hosts中加入对方的主机名和IP。

6、在.zookeeper.out文件中继续有以下错误

2018-12-08 05:49:44,885 [myid:1] - WARN  [WorkerSender[myid=1]:QuorumCnxManager@584] - Cannot open channel to 2 at election address zServer-2-10/11.1.2.10:3888
java.net.ConnectException: Connection refused (Connection refused)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:558)
	at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:534)
	at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:454)
	at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:435)
	at java.lang.Thread.run(Thread.java:748)

原因:需要配置免密登录或开了防火墙
解决:如果配了免密登录还不行就检查一防火墙。
查看防火墙方法:service iptables status
关闭防火墙方法:sudo service iptables stop
关闭自启动方法:sudo chkconfig iptables off

免密配置:

# 一直回车即可生成公钥和私钥
ssh-keygen -t rsa
# 生成了公钥和私钥
cd /root/.ssh/
# 将公钥追加到授权文件中
cat id_rsa.pub >> authorized_keys
# 可以查看到里面追加的公钥
more authorized_keys

# 在zServer-2-8上将zServer-2-8的公钥复制到zServer-2-10
ssh-copy-id -i zServer-2-10或scp /root/.ssh/authorized_keys zServer-2-10:/root/.ssh/

# 在zServer-2-10上将zServer-2-10的公钥复制到zServer-2-8
ssh-copy-id -i zServer-2-10或scp /root/.ssh/authorized_keys zServer-2-8:/root/.ssh/

# 验证
ssh zServer-2-8
ssh zServer-2-10
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!