• 【Nacos】Nacos集群模式启动报错&解决方案


    项目场景:

    本地Windows10开发环境,下载Nacos作为微服务项目的注册中心和配置中心

    下载版本为:nacos-server-2.1.2


    问题描述

    下载好nacos-server,按照官方文档中的部署手册,修改conf/application.properties文件,增加数据源配置(如下)。

    1. #*************** Config Module Related Configurations ***************#
    2. ### If use MySQL as datasource:
    3. spring.datasource.platform=mysql
    4. ### Count of DB:
    5. db.num=1
    6. ### Connect URL of DB:
    7. db.url.0=jdbc:mysql://localhost:3306/数据库名?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
    8. db.user=数据库用户名
    9. db.password=数据库密码

    启动后报错,报错信息如下:

    1. org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    2. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163)
    3. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
    4. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    5. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745)
    6. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420)
    7. at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    8. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
    9. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
    10. at com.alibaba.nacos.Nacos.main(Nacos.java:35)
    11. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    12. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    13. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    14. at java.lang.reflect.Method.invoke(Method.java:498)
    15. at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    16. at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
    17. at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    18. at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
    19. Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    20. at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142)
    21. at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104)
    22. at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479)
    23. at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211)
    24. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182)
    25. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160)
    26. ... 16 common frames omitted

    原因分析:

    Nacos支持三种部署模式,其默认设置为集群模式。由于自己粗心,只看了Nacos官网文档中的部署手册,修改了数据源配置,但未添加集群配置,所以导致启动报错。


     解决方案:

    解决方案有两种:

    第一种方案,将启动模式改为单机模式。

    修改Nacos启动文件,将配置 set MODE="cluster" 改为 set MODE="standalone"

     重新启动,可以看到服务以单机模式启动成功。

    第二种方案,添加集群配置,依旧使用集群模式启动。

    将 cluster.conf.example文件拷贝一份到当前目录,命名为 cluster.conf

     修改 cluster.conf配置内容,配置内容如下:

     注意:我这里只开启一个服务,所以只配置了一行,通常集群是有多台机器开启服务,在每行按格式添加相应的服务器ip和端口号即可。

    重新启动,可以看到服务以集群模式启动成功。

  • 相关阅读:
    springboot+nodejs+vue工程师售后服务评价管理系统
    论文解读(GMI)《Graph Representation Learning via Graphical Mutual Information Maximization》
    ArcGIS:如何利用站点数据(例如臭氧)进行克里金插值得到连续臭氧表面?
    【Linux】感性认识冯诺依曼体系结构和操作系统
    学会这个小技巧,让你的Jenkins更好用
    蓝桥杯嵌入式Debug
    报错:wget命令出现Unable to establish SSL connection.
    js-读书笔记-函数式编程-applicative函数-join的实现
    ElasticSearch之类型映射_mapping
    web网页设计期末课程大作业 HTML+CSS+JavaScript重庆火锅(代码质量好)
  • 原文地址:https://blog.csdn.net/Simple_Bo/article/details/127514938