zookeeper的集群搭建以及遇到的问题总结
1、在/目录下创建zookeeper文件夹mkdir zookeeper2、wgethttps://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz3、tar -zxvfapache-zookeeper-3.6.3-bin.tar.gz4、在/zookeeper目录下创建da
zookeeper集群搭建
1、在/目录下创建zookeeper文件夹
mkdir zookeeper
2、wget https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz
3、tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz
4、在/zookeeper目录下创建dataDir目录,用于存放数据文件,然后在这个文件夹下创建myid文件,写入任意数字
5、进入/zookeeper/apache-zookeeper-3.6.3-bin/conf文件夹,复制zoo_sample.cfg文件,新文件名为zoo.cfg,新增下列行
server.1=192.168.133.129:2888:3888
server.2=192.168.133.128:2888:3888
server.3=192.168.133.131:2888:3888
server.4:192.168.133.134:2181:3181:observer
,其中2888是广播端口,3888是选举端口
对应observer节点的zoo.cfg也要新增一行配置
peerType=observer
6、上述步骤在三台服务器上重复一遍
7、分别进入每台服务器的/zookeeper/apache-zookeeper-3.6.3-bin/bin目录,输入命令
./zkServer.sh start,启动zookeeper
8、使用./zkServer.sh status命令查看状态
9、使用命令打开本地zk客户端:sh zkCli.sh -server 127.0.0.1:2181
使用中遇到的问题
问题1:遇到的问题:按照第八步查看状态,显示zookeeper没有成功启动。
显示结果如截图:
查看/zookeeper/apache-zookeeper-3.6.3.-bin/logs/zookeeper-dachun-server-localhost.localdomain.out 文件显示日志日下:
2021-07-10 18:40:48,273 [myid:2] - WARN [QuorumConnectionThread-[myid=2]-53:QuorumCnxManager@400] - Cannot open channel to 1 at election address /192.168.133.128:3888
java.net.NoRouteToHostException: 没有到主机的路由 (Host unreachable)
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:607)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.initiateConnection(QuorumCnxManager.java:383)
at org.apache.zookeeper.server.quorum.QuorumCnxManager$QuorumConnectionReqThread.run(QuorumCnxManager.java:457)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
2021-07-10 18:41:48,276 [myid:2] - INFO [QuorumPeer[myid=2](plain=[0:0:0:0:0:0:0:0]:2181)(secure=disabled):FastLeaderElection@979] - Notification time out: 60000
2021-07-10 18:41:48,276 [myid:2] - WARN [QuorumConnectionThread-[myid=2]-54:QuorumCnxManager@400] - Cannot open channel to 0 at election address /192.168.133.129:3888
java.net.NoRouteToHostException: 没有到主机的路由 (Host unreachable)
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:607)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.initiateConnection(QuorumCnxManager.java:383)
at org.apache.zookeeper.server.quorum.QuorumCnxManager$QuorumConnectionReqThread.run(QuorumCnxManager.java:457)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
根据日志显示是因为集群间节点无法连接。
解决方法: 关掉所有服务器上的防火墙 systemctl stop firewalld.service
问题2:zookeeper客户端连接不上服务器
运行./zkCli.sh报错,如下:
2021-07-11 23:34:23,241 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1181] - Opening socket connection to server localhost/127.0.0.1:2181.
2021-07-11 23:34:23,241 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1183] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2021-07-11 23:34:23,242 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1013] - Socket connection established, initiating session, client: /127.0.0.1:42654, server: localhost/127.0.0.1:2181
2021-07-11 23:34:23,251 [myid:localhost:2181] - WARN [main-SendThread(localhost:2181):ClientCnxn$SendThread@1300] - Session 0x0 for sever localhost/127.0.0.1:2181, Closing socket connection. Attempting reconnect except it is a SessionExpiredException.
EndOfStreamException: Unable to read additional data from server sessionid 0x0, likely server has closed socket
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:77)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1290)
简而言之,上面的意思就是连不上服务器
解决方法:重启服务器(我也没找到原因,重启网卡,重启zk都没用)
更多推荐
所有评论(0)