有時(shí)候重啟Nacos(大多數(shù)情況下是因?yàn)橹貑⒘藱C(jī)器),再啟動(dòng)微服務(wù)項(xiàng)目的服務(wù)時(shí),后端控制臺(tái)會(huì)出現(xiàn)NacosException: failed to req API異常。
解決辦法:?現(xiàn)有兩種解決可供參考:
一、如果未做過(guò)特殊配置,直接刪除(或重命名)protocol文件夾即可
protocol文件夾在安裝目錄的下列位置:
...\nacos-server-1.4.0\data\
二、如果有特殊配置,修改文件raft_meta、__raft_snapshot_meta中的IP
raft_meta和__raft_snapshot_meta位置如下:
...\nacos-server-1.4.0\data\protocol\raft\naming_persistent_service\meta-data
...\nacos-server-1.4.0\data\protocol\raft\naming_persistent_service\snapshot\snapshot_7(此處可能不是_7,視具體情況而定)
注意:?IP要修改為Nacos所在機(jī)器的當(dāng)前IP。
小編遇到過(guò)的部分異常記錄如下:
2021-02-21 12:24:04.729 INFO 15344 --- [ restartedMain] com.alibaba.nacos.client.naming : [REGISTER-SERVICE] public registering service DEFAULT_GROUP@@hotbuy-orders with instance: {"clusterName":"DEFAULT","enabled":true,"ephemeral":true,"healthy":true,"instanceHeartBeatInterval":5000,"instanceHeartBeatTimeOut":15000,"ip":"192.168.0.104","ipDeleteTimeout":30000,"metadata":{"preserved.register.source":"SPRING_CLOUD"},"port":7000,"weight":1.0}
2021-02-21 12:24:04.754 ERROR 15344 --- [? restartedMain] com.alibaba.nacos.client.naming? ? ? ? ? : request: /nacos/v1/ns/instance failed, servers: [127.0.0.1:8848], code: 503, msg: server is DOWN now, please try again later!
2021-02-21 12:24:04.761 ERROR 15344 --- [? restartedMain] c.a.c.n.registry.NacosServiceRegistry? ? : nacos registry, hotbuy-orders register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='127.0.0.1:8848', endpoint='', namespace='', watchDelay=30000, logName='', service='hotbuy-orders', weight=1.0, clusterName='DEFAULT', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.0.104', networkInterface='', port=7000, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null}},com.alibaba.nacos.api.exception.NacosException: failed to req API:/api//nacos/v1/ns/instance after all servers([127.0.0.1:8848]) tried: server is DOWN now, please try again later!