赞
踩
在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产生的异常代码块:
- 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 :
- No DataSource set
- at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
- at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
- at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
- 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:423)
- 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)
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一直连接不上数据库;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。