安装 Zookeeper 启动报错

本文首发于个人博客: https://joemendezckh.github.io/posts/50e22a29.html

Error contacting service. It is probably not running.

  • 记录在安装启动Zookeeper 3.6.1 时遇到的问题与解决方法

环境信息:

CentOS Linux release 7.8.2003

java version “1.8.0_161”

apache-zookeeper-3.6.1-bin.tar.gz

  • 安装过程

    tar -zxvf /opt/apache-zookeeper-3.6.1-bin.tar.gz -C ./
    mv apache-zookeeper-3.6.1-bin zookeeper-3.6.1
    cd zookeeper-3.6.1
    " 创建 dataDir, 在 zoo.cfg 中修改 dataDir"
    mkdir data
    cd zookeeper-3.6.1/conf
    cp zoo_sample.cfg zoo.cfg
    vim zoo.cfg
    " 修改 dataDir 为上面创建的 data 目录"
    
    • 至此, 安装结束, 进行启动
    [zookeeper-3.6.1]# ./bin/zkServer.sh start
    ZooKeeper JMX enabled by default
    Using config: /usr/local/zookeeper/zookeeper-3.6.1/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    
    • 启动正常, 查看状态
    [zookeeper-3.6.1]# ./bin/zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /usr/local/zookeeper/zookeeper-3.6.1/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost.
    Error contacting service. It is probably not running
    
    • 查看状态错误, 使用 ps 命令和 netstat 命令查看2181端口均没有显示, 说明启动失败

    查阅相关资料后, 解释的原因有下面几种:

    1. 没有创建dataDir目录
    2. 没有关闭防火墙
    3. 2181端口被占用
    4. zoo.cfg文件中主机名出错
    5. myid文件中的整数格式不对,或者与zoo.cfg中的server整数不对应
  • 经过排查上述原因, 均为解决

解决方法

  • 最终发现, 直接查看日志文件即可

    查看位于zookeeper-3.6.1/logs下的.out文件

    [myid:] - ERROR [main:ZooKeeperServerMain@85] - Unable to start AdminServer, exiting abnormally                
    org.apache.zookeeper.server.admin.AdminServer$AdminServerException: Problem starting AdminServer on address 0.0.0.0, port 8080 and comm
    and URL /commands
        at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:176)
        at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:153)
        at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:112)
        at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:67)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:140)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:90)
    Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8080
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:346)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:307)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:231)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.server.Server.doStart(Server.java:385)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:167)
        ... 5 more
    Caused by: java.net.BindException: 地址已在使用
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.Net.bind(Net.java:425)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:342)
        ... 12 more
    Unable to start AdminServer, exiting abnormally
    
    • 显而易见, 是因为8080端口被占用, 解决端口占用后, 即可正常启动
    ZooKeeper JMX enabled by default
    Using config: /usr/local/zookeeper/zookeeper-3.6.1/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost.
    Mode: standalone
    

总结

以后出现问题, 不要忙着百度, 看看日志文件, 就可以解决大部分问题, 如果不行再百度

你可能感兴趣的:(实践,zookeeper,linux)