Nacos(一)部署及使用

单节点部署

下载最新版本的nacos release包,官方给的百度云盘连接:

https://pan.baidu.com/s/1186nmlqPGows9gUZKAx8Zw#list/path=%2F

提取码: rest

下载tar.gz文件

解压:

tar -xvf nacos….

修改配置文件conf/application.properties

1
2
3
4
5
6
7
8
9
10
11
#*************** 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.2.117:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user=root
db.password=pJp&Zzk3213

启动:

cd bin

sh startup.sh -m standalone

由于nacos没有依赖mysql8.0的driver包,所以启动时会报错,连接不上数据库

1
2
3
4
5
6
2020-08-09 13:07:15,048 INFO Root WebApplicationContext: initialization completed in 10238 ms

org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:371)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:523)

解决办法:
在nacos安装目录下新建plugins/mysql文件夹,并放入8.0+版本的mysql-connector-java-8.0.xx.jar,重启nacos即可。
启动时会提示更换了mysql的driver-class类。

最后访问xxx.xxx.xxx.xxx:8848

用户名密码是: nacos nacos