https://github.com/alibaba/nacos/releases
下载后,解压到任意目录
①、建数据库:nacos的配置一般存放于数据库,所以需要为nacos专门建一个数据库。
②、导入nacos数据:在nacos解压目录/conf文件夹下,存在nacos-mysql.sql文件,下载此文件,在新的nacos数据库中运行此sql文件,新数据库如下:
在解压后目录的conf文件夹下,存在application.properties文件,找到被注释的如下几行数据库配置
取消注释,配置自己的数据库信息。注意,需要将db.user.0以及db.password.0之类的修改为db.user以及db.password,如果未去除多余的0,将报错
[db-load-error]load jdbc.properties error
具体报错如下:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalStoragePersistServiceImpl': Invocation of init method failed; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error]load jdbc.properties error
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:413)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1761)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1196)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:595)
... 146 common frames omitted
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error]load jdbc.properties error
at com.alibaba.nacos.config.server.service.datasource.DynamicDataSource.getDataSource(DynamicDataSource.java:60)
at com.alibaba.nacos.config.server.service.repository.extrnal.ExternalStoragePersistServiceImpl.init(ExternalStoragePersistServiceImpl.java:133)
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)
... 158 common frames omitted
Caused by: java.lang.RuntimeException: [db-load-error]load jdbc.properties error
at com.alibaba.nacos.config.server.service.datasource.ExternalDataSourceServiceImpl.init(ExternalDataSourceServiceImpl.java:109)
at com.alibaba.nacos.config.server.service.datasource.DynamicDataSource.getDataSource(DynamicDataSource.java:55)
... 166 common frames omitted
正确的配置如下:
在nacos解压路径下的/bin目录下,存在startup.sh,进行两个改动
改动一:
我们是单机部署,将cluster改为standalone,如下:
改动二:
在30行左右的位置,做图中改动(ps:此处也可以试试不改,看能不能启动,博主不是太确定这里是否必改,当然,改了肯定没问题)
在startup.sh文件所在目录,执行启动命令:
sh startup.sh
启动需要大概30秒,查看日志,确保启动成功:
在nacos解压目录下的/logs文件夹下,查看start.out日志文件:
成功后的日志:
若失败,会打印错误日志
若启动失败,请先通过jps命令查看是否存在nacos-server.jar进程,及时kill掉,每次执行sh startup.sh都会有一个新的进程。
通过kill -9 xxxx命令杀掉进程:
另外,若出现启动时报错:No DataSource set错误,请检查文中数据库配置截图,一一比较,勿错勿漏
访问:http://主机ip:8848/nacos
记得在主机放行8848端口,任何一个新的软件使用了新的端口,都应该想到提前放行,这是素养。不像我,便宜云服务器,不怕安全问题,直接在阿里云一次性放行几乎所有端口,一劳永逸。
–我是“道祖且长”,一个在互联网"苟且偷生"的Java程序员
“有任何问题,可评论,我看到就会回复”