今天遇到了个奇葩问题,在阿里云服务器上启动了seata并且注册到nacos上面,本地服务却死活访问不了,报错如下:
2022-06-08 16:55:32 [NettyClientSelector_TMROLE_1_1] INFO i.seata.core.rpc.netty.AbstractNettyRemotingClient - ChannelHandlerContext(AbstractNettyRemotingClient$ClientHandler#0, [id: 0x3f7e3ff6]) will closed
2022-06-08 16:55:32 [timeoutChecker_1_1] ERROR io.seata.core.rpc.netty.NettyClientChannelManager - 0304 register RM failed.
io.seata.common.exception.FrameworkException: can not connect to services-server.
at io.seata.core.rpc.netty.NettyClientBootstrap.getNewChannel(NettyClientBootstrap.java:182)
at io.seata.core.rpc.netty.NettyPoolableFactory.makeObject(NettyPoolableFactory.java:58)
at io.seata.core.rpc.netty.NettyPoolableFactory.makeObject(NettyPoolableFactory.java:34)
at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1220)
at io.seata.core.rpc.netty.NettyClientChannelManager.doConnect(NettyClientChannelManager.java:221)
at io.seata.core.rpc.netty.NettyClientChannelManager.acquireChannel(NettyClientChannelManager.java:107)
at io.seata.core.rpc.netty.NettyClientChannelManager.reconnect(NettyClientChannelManager.java:189)
at io.seata.core.rpc.netty.AbstractNettyRemotingClient$1.run(AbstractNettyRemotingClient.java:114)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:308)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:750)
Caused by: io.seata.common.exception.FrameworkException: connect failed, can not connect to services-server.
at io.seata.core.rpc.netty.NettyClientBootstrap.getNewChannel(NettyClientBootstrap.java:177)
... 16 common frames omitted
2022-06-08 16:55:32 [timeoutChecker_1_1] ERROR io.seata.core.rpc.netty.NettyClientChannelManager - 0101 can not connect to xxx.xx.xx.xx:8091 cause:can not register RM,err:can not connect to services-server.
io.seata.common.exception.FrameworkException: can not register RM,err:can not connect to services-server.
到网上找了一大堆,都是千篇一律说配置问题,但仔细检查配置并无差错。其实看到nacos上面seata服务的这个ip,我就觉得不太对劲(因工作原因,马赛克掉了ip地址),并不是阿里云的公网ip。
后来仔细查看了nacos注册ip的资料,才发现问题所在。就是nacos上的seata服务ip是服务器内网ip而非公网ip导致本地服务无法访问的。
在Windows下,启动seata时如果没有指定ip,就会导致服务注册使用内网ip,通过指定ip为公网ip
即可:
seata-server.bat -h 公网ip
参考链接:https://blog.csdn.net/wangw_2007/article/details/113573308