配置zookeeper异常 Error contacting service. It is probably not running.以及java.net.ConnectException: 拒绝连接

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weiyongle1996/article/details/73733228

网上问题答案有许多种,一一试了一遍:
1. zoo.cfg配置文件中指定目录却没有创建! 创建相应目录即可。

                   //我的目录配置没有问题
2. zoo.cfg中dataDir指定路径为Myid文件的路径。                 
Myid内容与:server.?=localhost:2888:3888 中你所设置?一致!

                    //这里的配置也没有问题
3.使用service iptables stop 关闭防火墙                     

                   //防火墙已经关了
  使用service iptables status确认
4. 1,打开zkServer.sh 找到                         
status)
    STAT=`echo stat | nc localhost $(grep clientPort "$ZOOCFG" | sed -e 's/.*=//') 2> /dev/null| grep Mode`
在nc与localhost之间加上 -q 1 (是数字1而不是字母l)
如果已存在则去掉                                            

                 //zkServer.sh中没有这一行
5.2181端口被占用!                                         
zkServer.sh stop        #先停止zookeep
netstat -an | grep 2181 #查看端口是否占用,如果占用
clientPort = 2888       #随便找个没占用的端口号!

                //2181端口没有被占用

6.还有看到说把/etc/hosts 目录中的127.0.0.1对应哪一行注释掉的,但是试了试也没用。


=====================================分割线======================================================


上面的做法都试过了然而并没有卵用。


又看到了这个命令./zkServer.sh start-foreground,使用这个命令启动zookeeper可以查看错误信息

切换到/bin目录下,运行./zkServer.sh start-foreground这个命令

如果出现的错误信息包括下面的信息那么就是jdk没有安装好,需要配置一下jdk

JMX enabled by defaultUsing config: /root/apps/zookeeper-3.4.5/bin/../conf/zoo.cfg./zkServer.sh:行131: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.75.x86_64/bin/java: 没有那个文件或目录

JMX enabled by defaultUsing config: /root/apps/zookeeper-3.4.5/bin/../conf/zoo.cfg./zkServer.sh: 第 131 行:exec: java: 未找到

后面有jdk的配置步骤。

配置好jdk后重新启动又遇到了下面的错误:

JMX enabled by default
Using config: /root/apps/zookeeper-3.4.5/bin/../conf/zoo.cfg
2017-06-25 21:14:24,940 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading configuration from: /root/apps/zookeeper-3.4.5/bin/../conf/zoo.cfg
2017-06-25 21:14:24,945 [myid:] - INFO  [main:QuorumPeerConfig@334] - Defaulting to majority quorums
2017-06-25 21:14:24,950 [myid:2] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2017-06-25 21:14:24,950 [myid:2] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2017-06-25 21:14:24,951 [myid:2] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2017-06-25 21:14:24,985 [myid:2] - INFO  [main:QuorumPeerMain@127] - Starting quorum peer
2017-06-25 21:14:25,000 [myid:2] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:2181
2017-06-25 21:14:25,002 [myid:2] - ERROR [main:QuorumPeerMain@89] - Unexpected exception, exiting abnormally
java.net.BindException: 地址已在使用
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:444)
        at sun.nio.ch.Net.bind(Net.java:436)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
        at org.apache.zookeeper.server.NIOServerCnxnFactory.configure(NIOServerCnxnFactory.java:95)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:130)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:111)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)

出现这个问题有可能是端口被占用,把之前启动过的zkServer.sh关掉(./zkServer.sh stop)或者换一个端口号试试。

可以用这个命令netstat -lntup 查看所有端口号使用情况

还有这种错误:

java.net.ConnectException: 拒绝连接
        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:354)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:388)
        at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:765)
        at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:716)
2017-06-25 21:34:25,680 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@774] - Notification time out: 12800

(2017.8.10补充)拒绝连接这个问题终于解决了!!!

困扰了好几天的问题,在网上查的各种答案都不正确,最后竟然是在/etc/hosts中添加这一行:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
而我之前将这一行注释掉了,坑爹啊!有木有!

(2017.8.8补充)最近又遇到了这个问题:

java.net.NoRouteToHostException: 没有到主机的路由
        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:354)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:388)
        at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:765)
        at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:716)
2017-08-03 22:32:17,847 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@190] - Have smaller server identifier, so dropping the connection: (3, 1)
2017-08-03 22:32:17,851 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@774] - Notification time out: 1600
2017-08-03 22:32:19,457 [myid:1] - WARN  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@368] - Cannot open channel to 2 at election address mini2/192.168.0.104:3888
java.net.NoRouteToHostException: 没有到主机的路由
        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:354)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:388)
        at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:765)
        at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:716)
这个问题一般是防火墙的问题,起初以为我的防火墙是关了的,使用iptables查看也确实是关了的。

但是注意,centOS7 的默认防火墙不是iptables!不是iptables!不是iptables!

centOS7的防火墙是firewall,所以要关闭的是firewall,不是iptables。

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动
使用这两个命令可以关闭并禁用firewall

这种错误:

2017-06-26 01:13:35,998 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading configuration from: /root/apps/zookeeper-3.4.5/bin/../conf/zoo.cfg
2017-06-26 01:13:36,021 [myid:] - INFO  [main:QuorumPeerConfig@334] - Defaulting to majority quorums
2017-06-26 01:13:36,029 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2017-06-26 01:13:36,040 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2017-06-26 01:13:36,041 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2017-06-26 01:13:36,080 [myid:1] - INFO  [main:QuorumPeerMain@127] - Starting quorum peer
2017-06-26 01:13:36,111 [myid:1] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:2182
2017-06-26 01:13:36,159 [myid:1] - INFO  [main:QuorumPeer@913] - tickTime set to 2000
2017-06-26 01:13:36,159 [myid:1] - INFO  [main:QuorumPeer@933] - minSessionTimeout set to -1
2017-06-26 01:13:36,160 [myid:1] - INFO  [main:QuorumPeer@944] - maxSessionTimeout set to -1
2017-06-26 01:13:36,161 [myid:1] - INFO  [main:QuorumPeer@959] - initLimit set to 10
2017-06-26 01:13:36,221 [myid:1] - INFO  [main:FileSnap@83] - Reading snapshot /root/zkdata/version-2/snapshot.0
2017-06-26 01:13:36,257 [myid:1] - INFO  [Thread-1:QuorumCnxManager$Listener@486] - My election bind port: 0.0.0.0/0.0.0.0:3888
2017-06-26 01:13:36,283 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2182:QuorumPeer@670] - LOOKING
2017-06-26 01:13:36,287 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2182:FastLeaderElection@740] - New election. My id =  1, proposed zxid=0x0
2017-06-26 01:13:36,300 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@542] - Notification: 1 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x5 (n.peerEPoch), LOOKING (my state)
2017-06-26 01:13:36,301 [myid:1] - INFO  [/192.168.65.134:3888:QuorumCnxManager$Listener@493] - Received connection request /192.168.65.136:55868
2017-06-26 01:13:36,311 [myid:1] - INFO  [WorkerSender[myid=1]:QuorumCnxManager@190] - Have smaller server identifier, so dropping the connection: (2, 1)
2017-06-26 01:13:36,315 [myid:1] - INFO  [/192.168.65.134:3888:QuorumCnxManager$Listener@493] - Received connection request /192.168.65.135:60992
2017-06-26 01:13:36,323 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@542] - Notification: 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 3 (n.sid), 0x5 (n.peerEPoch), LOOKING (my state)
2017-06-26 01:13:36,332 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@542] - Notification: 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x5 (n.peerEPoch), LOOKING (my state)
2017-06-26 01:13:36,350 [myid:1] - INFO  [/192.168.65.134:3888:QuorumCnxManager$Listener@493] - Received connection request /192.168.65.135:60996
2017-06-26 01:13:36,363 [myid:1] - WARN  [SendWorker:2:QuorumCnxManager$SendWorker@679] - Interrupted while waiting for message on queue
java.lang.InterruptedException
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2095)
        at java.util.concurrent.ArrayBlockingQueue.poll(ArrayBlockingQueue.java:389)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.pollSendQueue(QuorumCnxManager.java:831)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.access$500(QuorumCnxManager.java:62)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager$SendWorker.run(QuorumCnxManager.java:667)
要解决上述的错误可以试试改一改zoo.cfg的配置文件,将本机的ip改为0.0.0.0,不要写本机的ip地址,即如下所示

第一个节点

server.1=0.0.0.0:2888:3888
server.2=192.168.65.135:2888:3888
server.3=192.168.65.136:2888:3888
第二个节点:

server.1=192.168.65.134:2888:3888
server.2=0.0.0.0:2888:3888
server.3=192.168.65.136:2888:3888

以此类推,在那个节点内就将那个节点的ip改为0.0.0.0

一般改完应该就可以了,但是我的依然没有好!!!

真的是心累,最后弄了一天,稀里糊涂的重新连接之后竟然神奇的好了,这种问题真是蛋疼。

百度谷歌搜了一圈,几乎所有的解决方案都列出来了,应该没有比我更全的了吧。。。


附上jdk的安装步骤

系统环境:centos7
安装方式:rpm安装
软件:jdk-8u25-linux-x64.rpm
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html

检验系统原版本
[root@zck ~]# java -version
java version "1.7.0_"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

进一步查看JDK信息:
[root@localhost ~]#  rpm -qa | grep java
javapackages-tools-3.4.1-6.el7_0.noarch
tzdata-java-2014i-1.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.71-2.5.3.1.el7_0.x86_64
java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64
python-javapackages-3.4.1-6.el7_0.noarch

卸载OpenJDK,执行以下操作:
[root@localhost ~]# rpm -e --nodeps tzdata-java-2014i-1.el7.noarch
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.71-2.5.3.1.el7_0.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64

安装JDK

上传新的jdk-8u25-linux-x64.rpm软件到/usr/local/执行以下操作:
[root@zck local]# rpm -ivh jdk-8u25-linux-x64.rpm

JDK默认安装在/usr/java中。

验证安装

执行以下操作,查看信息是否正常:
[root@localhost ~]# java
[root@localhost ~]# javac
[root@localhost ~]# java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

配置环境变量

我的机器安装完jdk-7-linux-x64.rpm后不用配置环境变量也可以正常执行javac、java –version操作,因此我没有进行JDK环境变量的配置。但是为了以后的不适之需,这里还是记录一下怎么进行配置,操作如下:
修改系统环境变量文件
vi + /etc/profile

向文件里面追加以下内容:
JAVA_HOME=/usr/java/jdk1.8.0_25
JRE_HOME=/usr/java/jdk1.8.0_25/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH


使修改生效
[root@localhost ~]# source /etc/profile   //使修改立即生效
[root@localhost ~]#        echo $PATH   //查看PATH值

查看系统环境状态
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.8.0_25/bin:/usr/java/jdk1.8.0_25/jre/bin

或运行一下Java,Javac,Java -version查看是否配置成功。

转载请注明:http://blog.csdn.net/weiyongle1996/article/details/73733228


展开阅读全文

没有更多推荐了,返回首页