编写zookeeper远程执行脚本过程中出现,zookeeper进程不能正常启动的问题:

进入配置文件conf目录下,查看zookeeper.out文件,内容如下所示:
异常代码:

2019-10-24 04:59:55,814 [myid:3] - ERROR [LearnerHandler-/192.168.10.10:36264:LearnerHandler@631] - Unexpected exception causing shutdown while sock still open
java.io.EOFException
        at java.io.DataInputStream.readInt(DataInputStream.java:392)
        at org.apache.jute.BinaryInputArchive.readInt(BinaryInputArchive.java:63)
        at org.apache.zookeeper.server.quorum.QuorumPacket.deserialize(QuorumPacket.java:83)
        at org.apache.jute.BinaryInputArchive.readRecord(BinaryInputArchive.java:99)
        at org.apache.zookeeper.server.quorum.LearnerHandler.run(LearnerHandler.java:542)
2019-10-24 04:59:55,814 [myid:3] - WARN  [RecvWorker:1:QuorumCnxManager$RecvWorker@810] - Connection broken for id 1, my id = 3, error = 
java.io.EOFException
        at java.io.DataInputStream.readInt(DataInputStream.java:392)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager$RecvWorker.run(QuorumCnxManager.java:795)
2019-10-24 04:59:55,814 [myid:3] - WARN  [LearnerHandler-/192.168.10.10:36264:LearnerHandler@644] - ******* GOODBYE /192.168.10.10:36264 ********
2019-10-24 04:59:55,814 [myid:3] - WARN  [RecvWorker:1:QuorumCnxManager$RecvWorker@813] - Interrupting SendWorker
2019-10-24 04:59:55,816 [myid:3] - WARN  [SendWorker:1:QuorumCnxManager$SendWorker@727] - Interrupted while waiting for message on queue
java.lang.InterruptedException
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2088)
        at java.util.concurrent.ArrayBlockingQueue.poll(ArrayBlockingQueue.java:418)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.pollSendQueue(QuorumCnxManager.java:879)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.access$500(QuorumCnxManager.java:65)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager$SendWorker.run(QuorumCnxManager.java:715)
2019-10-24 04:59:55,816 [myid:3] - WARN  [SendWorker:1:QuorumCnxManager$SendWorker@736] - Send worker leaving thread
2019-10-24 04:59:55,907 [myid:3] - ERROR [LearnerHandler-/192.168.10.20:58166:LearnerHandler@631] - Unexpected exception causing shutdown while sock still open
java.io.EOFException
        at java.io.DataInputStream.readInt(DataInputStream.java:392)
        at org.apache.jute.BinaryInputArchive.readInt(BinaryInputArchive.java:63)
        at org.apache.zookeeper.server.quorum.QuorumPacket.deserialize(QuorumPacket.java:83)
        at org.apache.jute.BinaryInputArchive.readRecord(BinaryInputArchive.java:99)
        at org.apache.zookeeper.server.quorum.LearnerHandler.run(LearnerHandler.java:542)
2019-10-24 04:59:55,907 [myid:3] - WARN  [RecvWorker:2:QuorumCnxManager$RecvWorker@810] - Connection broken for id 2, my id = 3, error = 
java.io.EOFException
        at java.io.DataInputStream.readInt(DataInputStream.java:392)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager$RecvWorker.run(QuorumCnxManager.java:795)
2019-10-24 04:59:55,908 [myid:3] - WARN  [RecvWorker:2:QuorumCnxManager$RecvWorker@813] - Interrupting SendWorker
2019-10-24 04:59:55,908 [myid:3] - WARN  [LearnerHandler-/192.168.10.20:58166:LearnerHandler@644] - ******* GOODBYE /192.168.10.20:58166 ********
2019-10-24 04:59:55,909 [myid:3] - WARN  [SendWorker:2:QuorumCnxManager$SendWorker@727] - Interrupted while waiting for message on queue
java.lang.InterruptedException
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2088)
        at java.util.concurrent.ArrayBlockingQueue.poll(ArrayBlockingQueue.java:418)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.pollSendQueue(QuorumCnxManager.java:879)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.access$500(QuorumCnxManager.java:65)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager$SendWorker.run(QuorumCnxManager.java:715)
2019-10-24 04:59:55,909 [myid:3] - WARN  [SendWorker:2:QuorumCnxManager$SendWorker@736] - Send worker leaving thread

问题:通过分析异常代码可以看出是java异常的问题,没有找到java的路径
解决方案:在配置文件中加入java的路径
打开文件 vi /etc/profile

# java_home
# java
export JAVA_HOME=/home/serverai/bigdata/jdk1.8.0_221
export PATH=:{JAVA_HOME}/bin:$PATH

更新配置source /etc/profile

执行的脚本代码如下:
zookeeper集群启动脚本,zk-all-start.sh

#!/usr/bin/env bash

for host in hadoopmaster hadoopslave01 hadoopslave02
do
# 输出当前服务器的zookeeper启动情况
echo "{$host} start zkServer..."
# 启动zookeeper根据自己安装路径修改
ssh $host "source /etc/profile;/root/bigdata/zookeeper-3.4.9/bin/zkServer.sh start"
done

sleep 2

for host in hadoopmaster hadoopslave01 hadoopslave02
do
echo "{$host} zkServer status..."
# 显示状态
ssh $host "source /etc/profile;/root/bigdata/zookeeper-3.4.9/bin/zkServer.sh status"
done

zookeeper集群停止脚本,zk-all-stop.sh

#!/usr/bin/env bash

for host in hadoopmaster hadoopslave01 hadoopslave02
do
# 输出当前服务器的zookeeper启动情况
echo "{$host} start zkServer..."
# 启动zookeeper根据自己安装路径修改
ssh $host "source /etc/profile;/root/bigdata/zookeeper-3.4.9/bin/zkServer.sh stop"
done

sleep 2

for host in hadoopmaster hadoopslave01 hadoopslave02
do
echo "{$host} zkServer status..."
# 显示状态
ssh $host "source /etc/profile;/root/bigdata/zookeeper-3.4.9/bin/zkServer.sh status"
done
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐