错误原因:

nacos获取的ip是外网ip:122.123.68.456 ,而cluster.config中配置的是内网ip:192.168.10.53

解决办法,有三种:

1、java启动脚本中增加:-Dnacos.server.ip=192.168.10.53

2、(推荐方式)application.properties增加nacos.inetutils.ip-address=192.168.10.53

3、修改cluster.config中的192.168.10.53为外网地址:122.123.68.456

 

关于nacos ip获取的说明:

1、先看看Jvm属性配置了nacos.server.ip=IP地址没有;如果有就是它;
2、如果1中没有,则看看配置文件application.properties中有没有属性nacos.inetutils.ip-address=IP地址;如果有就是它
3、如果还没有,那判断是否优先使用hostname;preferHostnameOverIp 的判断逻辑是;先判断JVM属性有没有配置nacos.preferHostnameOverIp=true/false;如果false,再去判断配置文件application.properties中有没有属性 nacos.inetutils.prefer-hostname-over-ip=true/false;如果有的话 就优先获取hostname; inetAddress.getHostName();
4、否则的话 就获取所有网卡中第一个非回环地址
selfIp = findFirstNonLoopbackAddress().getHostAddress();

就是不会找到 127.0.0.1这样的回环地址;
具体代码在类 InetUtils中;

selfIp = findFirstNonLoopbackAddress().getHostAddress();

 

附1:nacos集群模式搭建官方文档

 

附2:异常详细信息内容:

2020-05-09 10:50:30,000 ERROR Unexpected error occurred in scheduled task.

java.lang.IllegalStateException: unable to find local peer: 122.123.68.456:8848, all peers: [192.168.10.53:8848, 192.168.10.53:8849, 192.168.10.53:8850]
at com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeerSet.local(RaftPeerSet.java:224)
at com.alibaba.nacos.naming.monitor.PerformanceLoggerThread.collectMetrics(PerformanceLoggerThread.java:100)
at sun.reflect.GeneratedMethodAccessor122.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
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)

posted on 2020-05-09 11:11  张释文  阅读(4417)  评论(0编辑  收藏  举报