alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.17k stars 12.82k forks source link

mac m2 spring cloud alibaba 集成nacos,在虚拟机docker下,启动项目,出现failed to req API:/api//nacos/v1/ns/instance异常 #10829

Closed 2416941966 closed 1 year ago

2416941966 commented 1 year ago

网上找了很多解决方案,但是都没用,版本也根据官方的重新调整了也还是没有用,有哪位老哥能帮忙看看吗,到底是哪里的问题,非常感谢,昨天开始弄到现在还没解决,还没发现问题在哪里。🙏🙏🙏。

NACOS版本:1.2.1 ;SPRINGBOOT版本:2.2.5.RELEASE; SPRINGCLOUD版本:Hoxton.SR3;SPRINGCLOUDALIBABA版本:2.2.1.RELEASE

这是我的yml文件内容:

server: port: 11000

spring: datasource: username: root password: 1234 url: jdbc:mysql://localhost:3306/gulimall_wms driver-class-name: com.mysql.cj.jdbc.Driver

cloud: nacos: discovery: server-addr: 172.16.179.128:8848 application: name: gulimall-ware

jackson: date-format: yyyy-MM-dd HH:mm:ss

mybatis-plus: mapper-locations: classpath:/mapper/*/.xml global-config: db-config: id-type: auto

logging: level: com.atguigu: debug

这是我的common里边定义的依赖:

com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery

这是我docker启动nacos的命令:

docker run --name nacos -d -p 8848:8848 --privileged=true \ --restart=always \ -e JVM_XMS=512m \ -e JVM_XMX=2048m \ -e MODE=standalone \ -e PREFER_HOST_MODE=hostname \ -v /mydata/nacos/logs/:/home/nacos/logs \ -v /mydata/nacos/conf/:/home/nacos/conf \ --network mynetwork \ centralx/nacos-server:1.2.1@sha256:e8077d371fbf6e4c47ce69990565450e3744725e882993682200cf3861b9d30e

这是我的启动类:

@MapperScan("com.atguigu.gulimall.coupon.dao") @EnableDiscoveryClient @SpringBootApplication public class GulimallCouponApplication {

public static void main(String[] args) {
    SpringApplication.run(GulimallCouponApplication.class, args);
}

}

日志:

nacos日志里是正常运行的,没看见报错

这是nacos首页,可以成功访问的。http://172.16.179.128:8848/nacos/index.html#/configurationManagement?dataId=&group=&appName=&namespace=。, 使用curl http://172.16.179.128:8848/nacos/index.html ,也是成功的,

这是完整日志:

2023-07-20 20:11:47.438 ERROR 1183 --- [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, gulimall-coupon register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='172.16.179.128:8848', endpoint='', namespace='', watchDelay=30000, logName='', service='gulimall-coupon', weight=1.0, clusterName='DEFAULT', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.24.229', 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([172.16.179.128:8848]) tried: at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:496) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:401) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:397) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:212) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:207) ~[nacos-client-1.2.1.jar:na] at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:64) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239) [spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:76) [spring-cloud-starter-alibaba-nacos-discovery-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138) [spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101) [spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88) [spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47) [spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) [spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403) [spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360) [spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:165) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) [spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at com.atguigu.gulimall.coupon.GulimallCouponApplication.main(GulimallCouponApplication.java:61) [classes/:na]

2023-07-20 20:11:48.670 INFO 1183 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2023-07-20 20:11:48.682 ERROR 1183 --- [o-7000-Acceptor] org.apache.tomcat.util.net.Acceptor : Socket accept failed

java.nio.channels.AsynchronousCloseException: null at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:205) ~[na:1.8.0_371] at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:259) ~[na:1.8.0_371] at org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept(NioEndpoint.java:466) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept(NioEndpoint.java:72) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.tomcat.util.net.Acceptor.run(Acceptor.java:95) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at java.lang.Thread.run(Thread.java:750) [na:1.8.0_371]

2023-07-20 20:11:48.724 INFO 1183 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2023-07-20 20:11:48.738 INFO 1183 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'Nacso-Watch-Task-Scheduler' 2023-07-20 20:11:48.743 INFO 1183 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor' 2023-07-20 20:11:48.766 ERROR 1183 --- [ main] o.s.boot.SpringApplication : Application run failed

java.lang.reflect.UndeclaredThrowableException: null at org.springframework.util.ReflectionUtils.rethrowRuntimeException(ReflectionUtils.java:147) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE] at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:73) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:76) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:165) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at com.atguigu.gulimall.coupon.GulimallCouponApplication.main(GulimallCouponApplication.java:61) [classes/:na] Caused by: com.alibaba.nacos.api.exception.NacosException: failed to req API:/api//nacos/v1/ns/instance after all servers([172.16.179.128:8848]) tried: at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:496) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:401) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:397) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:212) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:207) ~[nacos-client-1.2.1.jar:na] at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:64) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.1.RELEASE.jar:2.2.1.RELEASE] ... 20 common frames omitted

Process finished with exit code 1

2416941966 commented 1 year ago

有哪位老哥看见吗?能解个疑惑吗,非常感谢!!!

wilsonwu commented 1 year ago

看您使用的centralx/nacos-server镜像并非官方镜像,不能确定是否镜像本身就有问题,不过官方镜像1.2.1版没有arm版,建议使用新一些的版本。

KomachiSion commented 1 year ago

报错中没有具体的错误原因, 可以看下/$user.home/logs/nacos下的日志文件,看下有没有其他的信息。

KomachiSion commented 1 year ago

No more response from author, and current information is not enough to find problem.