使用外网访问阿里云服务器ZooKeeper
1.阿里云ECS安装ZooKeeper2.阿里云ECS外网不能连接访问ZooKeeper解决3.解决使用外网IP和主机名的映射ZooKeeper启动报错1.阿里云ECS安装ZooKeeper由于参加了阿里云推荐有礼活动,买了一台阿里云云服务器ECS。JDK安装完成后首先安装的是ZooKeeper3.4.10,由于是一台机器,使用的是伪分布式安装,参见ZooKeeper...
1.阿里云ECS安装ZooKeeper
由于参加了阿里云推荐有礼活动,买了一台阿里云云服务器ECS。
JDK安装完成后首先安装的是ZooKeeper3.4.10,由于是一台机器,使用的是伪分布式安装,参见ZooKeeper伪分布式环境搭建及命令行使用
但是ZooKeeper安装配置完成后,启动却报错,报错日志如下,其中*.*.*.*
表示外网IP地址,solang
表示设置的外网IP和主机名的映射
2018-04-09 14:11:56,122 [myid:1] - INFO [solang/*.*.*.*:3887:QuorumCnxManager$Listener@739] - My election bind port: solang/*.*.*.*:3887
2018-04-09 14:11:56,123 [myid:1] - ERROR [solang/*.*.*.*:3887:QuorumCnxManager$Listener@763] - Exception while listening
java.net.BindException: Cannot assign requested address (Bind failed)
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.bind(ServerSocket.java:329)
at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener.run(QuorumCnxManager.java:742)
2018-04-09 14:11:57,123 [myid:1] - INFO [solang/*.*.*.*:3887:QuorumCnxManager$Listener@776] - Leaving listener
2018-04-09 14:11:57,124 [myid:1] - ERROR [solang/*.*.*.*:3887:QuorumCnxManager$Listener@778] - As I'm leaving the listener thread, I won't be able to participate in leader election any longer: solang/*.*.*.*:3887
2018-04-09 14:11:59,140 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@588] - Cannot open channel to 2 at election address solang/*.*.*.*:3888
java.net.SocketTimeoutException: connect timed out
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:562)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:538)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:452)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:433)
at java.lang.Thread.run(Thread.java:748)
将云服务器的/etc/hosts
文件外网IP地址修改为内网IP地址,或者ZooKeeper配置文件的地址修改为localhost,重新启动ZooKeeper,这样ZooKeeper能正常启动。
[solang@solang ~]$ vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.19.83.240 solang
但是外部机器使用ECS外网IP就不能连接操作ZooKeeper了,解决方案见下
2.阿里云ECS外网不能连接访问ZooKeeper解决
1.进入阿里云ECS实例控制台
2.选择更多-安全组配置
3.选择配置规则
4.选择添加安全组规则
5.添加安全组规则
可根据需要选择协议类型及设置对应端口范围,为了省事,我选择协议类型为全部。点击确定
,安全组规则设置完成。
这样Windows或MAC机器就能使用ECS提供的外网IP访问到ZooKeeper了。
3.解决使用外网IP和主机名的映射ZooKeeper启动报错
使用外网IP和主机名映射的配置会报最开始的错误,解决方案如下:
1.ZooKeeper的配置文件zoo.cfg
要加参数quorumListenOnAllIPs=true
2.需要进入ECS控制台配置安全组规则,伪分布式ZooKeeper使用到的端口都需要在规则内
设置完成后启动ZooKeeper,发现启动成功,而且Windows或MAC机器也能使用ECS提供的外网IP访问到ZooKeeper了。
更多推荐
所有评论(0)