Closed mysunstar closed 3 years ago
单机模式默认使用derby数据库。不需要连接mysql,拔掉网线肯定可以启动啊 集群模式默认连接mysql数据库,连不上数据库不能启动也是预期内
数据库是可以连接的,因为Mysql同一虚拟机的,插上网线就可以访问,拔掉网线就访问不到数据库。Mysql服务是正常的。这个怎么解释呢?
贴一下nacos配置文件,以及你启动的命令
server.servlet.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.75.128:3306/nacos?characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC db.user=root db.password=4F53835FCB15BF84
nacos.naming.empty-service.auto-clean=true nacos.naming.empty-service.clean.initial-delay-ms=50000 nacos.naming.empty-service.clean.period-time-ms=30000
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
server.tomcat.basedir=
nacos.security.ignore.urls=/,/error,//*.css,/*/.js,//*.html,//*.map,/*/.svg,//*.png,/*/.ico,/console-fe/public/,/v1/auth/,/v1/console/health/,/actuator/,/v1/console/server/**
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=false
nacos.core.auth.default.token.expire.seconds=18000
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
nacos.core.auth.caching.enabled=true
nacos.istio.mcp.server.enabled=false
====================
然后通过startup.sh/startup.cmd启动,我在windows和linux都测试过,都是存在这个问题的。
https://github.com/alibaba/nacos/releases/tag/1.3.0 下的包nacos-server-1.3.0.zip
拔掉网线,只能写本地回环地址,你写192.168.75.128肯定是不可以的,都没人分配IP,你怎么连接到这个IP上
你好,是这样的。因为我是在另外一个客户环境发现这个问题的,他关闭了外网,使用的是局域网,导致nacos server连接mysql异常。然后我是通过这样方式重现。 1、 我用windows的电脑用VMware安装了一个linux的虚拟机(IP:192.168.75.128),在虚拟机安装了mysql 2、 开始是windows插上网线的情况,nacos server在linux虚拟机上正常启动 3、 拔掉windows电脑网线,重启nacos server, nacos server连接mysql异常,异常信息如上所述 4、 同样,我在windows的电脑上,运行nacos server,连接虚拟机上的mysql,同样出现一样的异常 5、 然后我做了mysql的连接测试,在windows的电脑和linux的虚拟机上,通过mysql的客户端,连接mysql都是可以正常连接的。
拔掉网线你可以看过下虚拟机的IP是多少,还有你连接mysql的时候,你的ip是怎么写的,数据库连不上已经不是nacos的问题了
你拔掉网线试下能不能用192.168.75.128直接访问mysql?
虚拟机IP也是192.168.75.128没有变化。我用客户端连接数据库用的是192.168.75.128,但是是可以连的哦,但是nacos就是没有连接上。
PS: 1、 经过反复的验证,先用连接网线启动nacos成功了之后,再拔掉网线再启动是可以启动正常nacos的,但是再重启虚拟机之后就不行了 2、 所以这个情况是建立没有使用外网,直接启动nacos,就会报数据库连接失败。 3、拔掉网线试下可以用192.168.75.128直接访问mysql,但是连接的时候是会有点慢。
附: 1、 拔掉之后虚拟机的IP信息: ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.75.128 netmask 255.255.255.0 broadcast 192.168.75.255 inet6 fe80::ea11:8839:5bb7:ff33 prefixlen 64 scopeid 0x20 ether 00:0c:29:a9:83:f6 txqueuelen 1000 (Ethernet) RX packets 1356 bytes 127151 (124.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1248 bytes 196300 (191.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
是不是因为连接超时导致的,你在jdbcurl后面把连接超时时间调大试试看。
@KomachiSion 这个我之前尝试过了,设置了很大的值,还是出现一样的问题的。
您可以试一下写一个简单的jdbc连接程序,驱动版本一致,在nacos连接不上数据库的时候,用jdbc连接程序连一下试试。这有可能是jdbc的问题。
nacos报的错也是jdbc和spring抛出来的。
我感觉我的情况和你的有一点点类似,我的nacos布署在hyper-v的centos下面,可以正常使用,但是用一段时间后,mysql就会链接超时(必现)需要重启nacos后就能正常工作一段时间就又断开,但是我同一台机器下的其它项目也连的这个数据库,是正常的。
@zhouwenqi1982 应该不一样,你那个问题可能和数据库设置有关,他的问题是网络问题,直接nacos连不上数据库。
@mysunstar 有什么进展吗?我理解只要同样环境下,jdbc样例程序能联通,nacos就没有问题。
@KomachiSion 今天测试了下,我们用同个jdbc包的程序是可以连接mysql的,但是nacos不可以连上。
我没有测试过虚拟机,我测试了下无外网的时候 用docker起mysql,本机起nacos,可以启动,估计还是环境设置导致的,可能需要自行排查了 可以试一下用develop分支起一个依赖数据库的单机模式,debug一下看下真正的数据库连接异常是什么。
nacos.log或者start.out日志里应该也有。
Issue Description
Type: bug report or feature request
Describe what happened (or what feature you want)
nacos server 1.30使用内网模式,关闭外网,启动报连接数据库错误
Describe what you expected to happen
nacos server 1.30使用内网模式,关闭外网,启动报连接数据库错误
How to reproduce it (as minimally and precisely as possible)
Tell us your environment
Linux,mysql在同一台虚拟机上
Anything else we need to know?
异常日志:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configOpsController' defined in URL [jar:file:/home/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-config-1.3.0.jar!/com/alibaba/nacos/config/server/controller/ConfigOpsController.class]: Unsatisfied dependency expressed through constructor parameter 1; 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:769) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1308) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1154) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) 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:109) at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:604) Caused by: 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.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:419) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1737) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:273) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1237) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ... 27 common frames omitted Caused by: com.alibaba.nacos.api.exception.NacosException: Nacos Server did not start because dumpservice bean construction failure : No DataSource set at com.alibaba.nacos.config.server.service.dump.DumpService.dumpOperate(DumpService.java:191) at com.alibaba.nacos.config.server.service.dump.ExternalDumpService.init(ExternalDumpService.java:49) 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.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ... 40 common frames omitted Caused by: java.lang.IllegalStateException: No DataSource set at org.springframework.util.Assert.state(Assert.java:73) at org.springframework.jdbc.support.JdbcAccessor.obtainDataSource(JdbcAccessor.java:77) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:371) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:452) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:462) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:473) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:480) at com.alibaba.nacos.config.server.service.repository.ExternalStoragePersistServiceImpl.findConfigMaxId(ExternalStoragePersistServiceImpl.java:702) at com.alibaba.nacos.config.server.service.dump.DumpAllProcessor.process(DumpTask.java:198) at com.alibaba.nacos.config.server.service.dump.DumpService.dumpConfigInfo(DumpService.java:249) at com.alibaba.nacos.config.server.service.dump.DumpService.dumpOperate(DumpService.java:155) ... 48 common frames omitted