【Nacos】Nacos集群模式启动报错&解决方案
nacos
Nacos是由阿里巴巴开源的服务治理中间件,集成了动态服务发现、配置管理和服务元数据管理功能,广泛应用于微服务架构中,简化服务治理过程。
项目地址:https://gitcode.com/gh_mirrors/na/nacos
·
项目场景:
本地Windows10开发环境,下载Nacos作为微服务项目的注册中心和配置中心
下载版本为:nacos-server-2.1.2
问题描述
下载好nacos-server,按照官方文档中的部署手册,修改conf/application.properties文件,增加数据源配置(如下)。
#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://localhost:3306/数据库名?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user=数据库用户名
db.password=数据库密码
启动后报错,报错信息如下:
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at com.alibaba.nacos.Nacos.main(Nacos.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104)
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479)
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160)
... 16 common frames omitted
原因分析:
Nacos支持三种部署模式,其默认设置为集群模式。由于自己粗心,只看了Nacos官网文档中的部署手册,修改了数据源配置,但未添加集群配置,所以导致启动报错。

解决方案:
解决方案有两种:
第一种方案,将启动模式改为单机模式。
修改Nacos启动文件,将配置 set MODE="cluster" 改为 set MODE="standalone" 。
重新启动,可以看到服务以单机模式启动成功。
第二种方案,添加集群配置,依旧使用集群模式启动。
将 cluster.conf.example文件拷贝一份到当前目录,命名为 cluster.conf
修改 cluster.conf配置内容,配置内容如下:
注意:我这里只开启一个服务,所以只配置了一行,通常集群是有多台机器开启服务,在每行按格式添加相应的服务器ip和端口号即可。
重新启动,可以看到服务以集群模式启动成功。
Nacos是由阿里巴巴开源的服务治理中间件,集成了动态服务发现、配置管理和服务元数据管理功能,广泛应用于微服务架构中,简化服务治理过程。
最近提交(Master分支:1 个月前 )
c5aebb02
* Fix naming maintainer sdk auth plugin.
* Fix config maintainer sdk auth plugin.
* Add AI builder to RequestResource.
* Set empty string replace null resource for config module.
* Set empty string replace null resource for naming module.
* Fix NPE for mcp create remote mcp server.
* Support ai mcp request aliyun ram auth. 11 小时前
4b325c58
* Fix config admin api must request admin role problem.
* Fix naming admin api must request admin role problem.
* Fix unit test. 4 天前
更多推荐









所有评论(0)