alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.33k stars 12.85k forks source link

nacos server 1.30使用内网模式,关闭外网,启动报连接数据库错误 #4047

Closed mysunstar closed 3 years ago

mysunstar commented 4 years ago

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)

  1. 单机模式,可以访问外网情况下,正常启动nacos server
  2. 拔掉网线,重启之后,就访问不了数据库,启动异常

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

KomachiSion commented 4 years ago

单机模式默认使用derby数据库。不需要连接mysql,拔掉网线肯定可以启动啊 集群模式默认连接mysql数据库,连不上数据库不能启动也是预期内

mysunstar commented 4 years ago

数据库是可以连接的,因为Mysql同一虚拟机的,插上网线就可以访问,拔掉网线就访问不到数据库。Mysql服务是正常的。这个怎么解释呢?

KomachiSion commented 4 years ago

贴一下nacos配置文件,以及你启动的命令

mysunstar commented 4 years ago

Spring Boot Related Configurations

Default web context path:

server.servlet.contextPath=/nacos

Default web server port:

server.port=8848

Network Related Configurations

If prefer hostname over ip for Nacos server addresses in cluster.conf:

nacos.inetutils.prefer-hostname-over-ip=false

Specify local server's IP:

nacos.inetutils.ip-address=

Config Module Related Configurations

If user MySQL as datasource:

spring.datasource.platform=mysql

Count of DB:

db.num=1

Connect URL of DB:

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

Naming Module Related Configurations

Data dispatch task execution period in milliseconds:

nacos.naming.distro.taskDispatchPeriod=200

Data count of batch sync task:

nacos.naming.distro.batchSyncKeyCount=1000

Retry delay in milliseconds if sync task failed:

nacos.naming.distro.syncRetryDelay=5000

If enable data warmup. If set to false, the server would accept request without local data preparation:

nacos.naming.data.warmup=true

If enable the instance auto expiration, kind like of health check of instance:

nacos.naming.expireInstance=true

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

CMDB Module Related Configurations

The interval to dump external CMDB in seconds:

nacos.cmdb.dumpTaskInterval=3600

The interval of polling data change event in seconds:

nacos.cmdb.eventTaskInterval=10

The interval of loading labels in seconds:

nacos.cmdb.labelTaskInterval=300

If turn on data loading task:

nacos.cmdb.loadDataAtStart=false

Metrics Related Configurations

Metrics for prometheus

management.endpoints.web.exposure.include=*

Metrics for elastic search

management.metrics.export.elastic.enabled=false

management.metrics.export.elastic.host=http://localhost:9200

Metrics for influx

management.metrics.export.influx.enabled=false

management.metrics.export.influx.db=springboot

management.metrics.export.influx.uri=http://localhost:8086

management.metrics.export.influx.auto-create-db=true

management.metrics.export.influx.consistency=one

management.metrics.export.influx.compressed=true

Access Log Related Configurations

If turn on the access log:

server.tomcat.accesslog.enabled=true

The access log pattern:

server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i

The directory of access log:

server.tomcat.basedir=

Access Control Related Configurations

If enable spring security, this option is deprecated in 1.2.0:

spring.security.enabled=false

The ignore urls of auth, is deprecated in 1.2.0:

nacos.security.ignore.urls=/,/error,//*.css,/*/.js,//*.html,//*.map,/*/.svg,//*.png,/*/.ico,/console-fe/public/,/v1/auth/,/v1/console/health/,/actuator/,/v1/console/server/**

The auth system to use, currently only 'nacos' is supported:

nacos.core.auth.system.type=nacos

If turn on auth system:

nacos.core.auth.enabled=false

The token expiration in seconds:

nacos.core.auth.default.token.expire.seconds=18000

The default token:

nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789

Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.

nacos.core.auth.caching.enabled=true

Istio Related Configurations

If turn on the MCP server:

nacos.istio.mcp.server.enabled=false

Add from 1.3.0

Core Related Configurations

set the WorkerID manually

nacos.core.snowflake.worker-id=

Member-MetaData

nacos.core.member.meta.site=

nacos.core.member.meta.adweight=

nacos.core.member.meta.weight=

MemberLookup

Addressing pattern category, If set, the priority is highest

nacos.core.member.lookup.type=[file,address-server,discovery]

Set the cluster list with a configuration file or command-line argument

nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809

for DiscoveryMemberLookup

If you want to use cluster node self-discovery, turn this parameter on

nacos.member.discovery=false

for AddressServerMemberLookup

Maximum number of retries to query the address server upon initialization

nacos.core.address-server.retry=5

JRaft Related Configurations

Sets the Raft cluster election timeout, default value is 5 second

nacos.core.protocol.raft.data.election_timeout_ms=5000

Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute

nacos.core.protocol.raft.data.snapshot_interval_secs=30

Requested retries, default value is 1

nacos.core.protocol.raft.data.request_failoverRetries=1

raft internal worker threads

nacos.core.protocol.raft.data.core_thread_num=8

Number of threads required for raft business request processing

nacos.core.protocol.raft.data.cli_service_thread_num=4

raft linear read strategy, defaults to index

nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe

rpc request timeout, default 5 seconds

nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000

mysunstar commented 4 years ago

====================

mysunstar commented 4 years ago

然后通过startup.sh/startup.cmd启动,我在windows和linux都测试过,都是存在这个问题的。

mysunstar commented 4 years ago

https://github.com/alibaba/nacos/releases/tag/1.3.0 下的包nacos-server-1.3.0.zip

chuntaojun commented 4 years ago

拔掉网线,只能写本地回环地址,你写192.168.75.128肯定是不可以的,都没人分配IP,你怎么连接到这个IP上

mysunstar commented 4 years ago

你好,是这样的。因为我是在另外一个客户环境发现这个问题的,他关闭了外网,使用的是局域网,导致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都是可以正常连接的。

chuntaojun commented 4 years ago

拔掉网线你可以看过下虚拟机的IP是多少,还有你连接mysql的时候,你的ip是怎么写的,数据库连不上已经不是nacos的问题了

KomachiSion commented 4 years ago

你拔掉网线试下能不能用192.168.75.128直接访问mysql?

mysunstar commented 4 years ago

虚拟机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

KomachiSion commented 4 years ago

是不是因为连接超时导致的,你在jdbcurl后面把连接超时时间调大试试看。

mysunstar commented 4 years ago

@KomachiSion 这个我之前尝试过了,设置了很大的值,还是出现一样的问题的。

KomachiSion commented 4 years ago

您可以试一下写一个简单的jdbc连接程序,驱动版本一致,在nacos连接不上数据库的时候,用jdbc连接程序连一下试试。这有可能是jdbc的问题。

nacos报的错也是jdbc和spring抛出来的。

zhouwenqi1982 commented 4 years ago

我感觉我的情况和你的有一点点类似,我的nacos布署在hyper-v的centos下面,可以正常使用,但是用一段时间后,mysql就会链接超时(必现)需要重启nacos后就能正常工作一段时间就又断开,但是我同一台机器下的其它项目也连的这个数据库,是正常的。

KomachiSion commented 4 years ago

@zhouwenqi1982 应该不一样,你那个问题可能和数据库设置有关,他的问题是网络问题,直接nacos连不上数据库。

@mysunstar 有什么进展吗?我理解只要同样环境下,jdbc样例程序能联通,nacos就没有问题。

mysunstar commented 4 years ago

@KomachiSion 今天测试了下,我们用同个jdbc包的程序是可以连接mysql的,但是nacos不可以连上。

KomachiSion commented 4 years ago

我没有测试过虚拟机,我测试了下无外网的时候 用docker起mysql,本机起nacos,可以启动,估计还是环境设置导致的,可能需要自行排查了 可以试一下用develop分支起一个依赖数据库的单机模式,debug一下看下真正的数据库连接异常是什么。

nacos.log或者start.out日志里应该也有。