nacos集群模式部署 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]


錯誤原因:

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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM