当前位置:   article > 正文

数据库连接异常Nacos Server did not start because dumpservice bean construction failure : No DataSource set_nacos server didnot

nacos server didnot

操作环境说明

  • 操作系统:Centos7.x
  • Nacos版本:2.2.X(本章采用的是2.2.3v)
  • Docker社区版:Docker version 24.0.7
  • Mysql数据库:Mysql8

场景操作过程

Linux系统下,使用新版Docker安装Nacos2.2.x,并连接Mysql8产生No DataSource set的异常,总结为三种场景。

1、安装Docker命令

————————Docker-ce社区版本————————
#运行以下命令,下载docker-ce的yum源。
sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#运行以下命令,安装Docker。
sudo yum -y install docker-ce

#执行以下命令,检查Docker是否安装成功。
sudo docker -v

#执行以下命令,启动Docker服务,并设置开机自启动。
sudo systemctl start docker
sudo systemctl enable docker

#执行以下命令,查看Docker是否启动。
sudo systemctl status docker

2、安装Mysql8命令

#创建目录
mkdir -p /home/data/mysql/
#创建配置文件
touch /home/data/mysql/my.cnf

#部署
docker run \
    -p 3306:3306 \
    -e MYSQL_ROOT_PASSWORD=123456 \
    -v /home/data/mysql/conf:/etc/mysql/conf.d \
    -v /home/data/mysql/data:/var/lib/mysql:rw \
    -v /home/data/mysql/my.cnf:/etc/mysql/my.cnf \
    --name test_mysql \
    --restart=always \
    -d mysql:8.0

3、安装Nacos命令

docker run -d \
-e MODE=standalone \
-e JVM_XMS=128m \
-e JVM_XMX=128m \
-e JVM_XMN=128m \
-p 8848:8848 \
-p 9848:9848 \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=127.0.0.1 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=123456 \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e MYSQL_SERVICE_DB_PARAM='characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false' \
--restart=always \
--privileged=true \
-v /home/data/nacos/logs:/home/nacos/logs \
--name test_nacos \
nacos/nacos-server:v2.2.3

在执行以上命令后,使用ssh工具到服务器的home下会看到如下目录结构:

异常问题总结和解决

 Linux下安装Nacos2产生的异常代码块:

  1. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memoryMonitor' defined in URL [jar:file:/home/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-config-2.2.3.jar!/com/alibaba/nacos/config/server/monitor/MemoryMonitor.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'asyncNotifyService': Unsatisfied dependency expressed through field 'dumpService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalDumpService': Invocation of init method failed; nested exception is ErrCode:500, ErrMsg:Nacos Server did not start because dumpservice bean construction failure :
  2. No DataSource set
  3. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
  4. at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)
  5. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372)
  6. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)
  7. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
  8. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
  9. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
  10. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
  11. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
  12. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
  13. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
  14. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
  15. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
  16. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
  17. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745)
  18. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:423)
  19. at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
  20. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
  21. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
  22. at com.alibaba.nacos.Nacos.main(Nacos.java:35)
  23. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  24. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  25. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  26. at java.lang.reflect.Method.invoke(Method.java:498)
  27. at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
  28. at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
  29. at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
  30. at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)

1、Nacos连接Mysql的配置信息错误;检查Nacos脚本的以下参数:

MYSQL_SERVICE_HOST=127.0.0.1 \
MYSQL_SERVICE_PORT=3306 \
MYSQL_SERVICE_USER=root \
MYSQL_SERVICE_PASSWORD=123456 \
MYSQL_SERVICE_DB_NAME=nacos \

必须与安装mysql时,配置的账号密码,端口号等一致。且必须提前创建nacos数据库;

2、Mysql数据库的连接耗时比较久,必须在Nacos配置如下:

MYSQL_SERVICE_DB_PARAM='characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false'

3、在安装Nacos或Mysql时,一般会将重要文件挂载到容器外部,也就是Linux操作系统下,以便保证Docker停止或异常,重要数据得到保留;如下,

No DataSource set 问题,也和这个挂载目录存在关系;在mysq或是Nacos其中一个要重新修改配置信息进行安装的时候,必须把他们对应的挂载文件夹删除,否则会由于缓存之前配置,导致Nacos无法连接上Mysql。

Mysql有数据必须提前备份。

//停止运行中容器

docker stop 容器ID

//移除已停止的容器

docker rm 容器ID

本人就因为目录下配置信息缓存,导致nacos一直连接不上数据库;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/296569
推荐阅读
相关标签
  

闽ICP备14008679号