Skip to content

Commit

Permalink
feat: update nacos version to 2.3.0 in 2023.x (#3583)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuluo-yx authored Jan 16, 2024
1 parent 3a1b270 commit ce28f82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion spring-cloud-alibaba-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<properties>
<revision>2023.0.0.0</revision>
<sentinel.version>1.8.6</sentinel.version>
<nacos.client.version>2.3.0</nacos.client.version>
<seata.version>2.0.0</seata.version>
<nacos.client.version>2.2.3</nacos.client.version>
<spring.context.support.version>1.0.11</spring.context.support.version>
<!-- Apache RocketMQ -->
<rocketmq.version>4.9.4</rocketmq.version>
Expand Down
30 changes: 15 additions & 15 deletions spring-cloud-alibaba-examples/nacos-example/readme-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@

[Nacos](https://github.com/alibaba/Nacos) 是阿里巴巴开源的一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。

## 正确配置并启动 Nacos Server 2.2.x
## 正确配置并启动 Nacos Server 2.3.0

在 Nacos 2.2.x 中,加入了用户鉴权相关的功能,在首次启动 Nacos Server 时,需要正确配置,避免出现启动失败的问题。
在 Nacos 2.3.0 中,加入了用户鉴权相关的功能,在首次启动 Nacos Server 时,需要正确配置,避免出现启动失败的问题。

### 下载 Nacos Server

> 本示例中使用 Nacos Server 版本为 2.2.3
> 本示例中使用 Nacos Server 版本为 2.3.0
Nacos 支持直接下载和源码构建两种方式。**推荐在 Spring Cloud Alibaba 2022.x 中使用 Nacos Server 2.2.3 版本。**
Nacos 支持直接下载和源码构建两种方式。**推荐在 Spring Cloud Alibaba 2023.x 中使用 Nacos Server 2.3.0 版本。**

1. 直接下载:[Nacos Server 下载页](https://github.com/alibaba/nacos/releases)
2. 源码构建:进入 Nacos [Github 项目页面](https://github.com/alibaba/nacos),将代码 git clone 到本地自行编译打包,[参考文档](https://nacos.io/zh-cn/docs/quick-start.html)

### 配置 Nacos Server

打开 `\nacos-server-2.2.3\conf\application.properties` 配置文件,修改以下配置项:
打开 `\nacos-server-2.3.0\conf\application.properties` 配置文件,修改以下配置项:

#### 配置数据源

此处以 MySQL 数据库为例,使用 `nacos-server-2.2.3\conf\mysql-schema.sql` 初始化数据库表文件。同时修改以下配置
此处以 MySQL 数据库为例,使用 `nacos-server-2.3.0\conf\mysql-schema.sql` 初始化数据库表文件。同时修改以下配置

```properties
#*************** Config Module Related Configurations ***************#
Expand All @@ -49,7 +49,7 @@ db.pool.config.minimumIdle=2

#### 开启鉴权

**注意:不开启在 2.2.x 中会出现登陆失败异常!**
**注意:不开启在 2.3.0 中会出现登陆失败异常!**

```properties
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
Expand Down Expand Up @@ -77,7 +77,7 @@ nacos.core.auth.plugin.nacos.token.secret.key=SecretKey0123456789012345678901234

#### Open API 鉴权

在 nacos server 2.2.x 中使用 Open api 接口时需要鉴权:更多细节请参考:[Nacos api 鉴权](https://nacos.io/zh-cn/docs/auth.html)
在 nacos server 2.3.0 中使用 Open api 接口时需要鉴权:更多细节请参考:[Nacos api 鉴权](https://nacos.io/zh-cn/docs/auth.html)

1. 获取 accessToken:使用用户名和密码登陆 nacos server:

Expand Down Expand Up @@ -107,8 +107,6 @@ nacos.core.auth.plugin.nacos.token.secret.key=SecretKey0123456789012345678901234

浏览器输入地址 http://127.0.0.1:8848/nacos**首次登陆需要绑定 nacos 用户,因为新版本增加了鉴权,需要应用注册和配置绑定时配置用户名和密码。**



## Nacos 应用示例

### Spring Cloud Alibaba Nacos Config
Expand Down Expand Up @@ -145,9 +143,9 @@ nacos.core.auth.plugin.nacos.token.secret.key=SecretKey0123456789012345678901234
3. 完成上述两步后,应用会从 Nacos Server 中获取相应的配置,并添加在 Spring Environment 的 PropertySources 中。使用 Nacos 配置中心保存 Nacos 的部分配置时,有以下四种方式:
- BeanAutoRefreshConfigExample: 通过将配置信息配置为bean,支持配置变自动刷新的例子;
- ConfigListenerExample: 监听配置信息的例子;
- DockingInterfaceExample: 对接 Nacos 接口,通过接口完成对配置信息增删改查的例子;
- ValueAnnotationExample: 通过 @Value 注解进行配置信息获取的例子。
- ConfigListenerExample: 监听配置信息的例子;
- DockingInterfaceExample: 对接 Nacos 接口,通过接口完成对配置信息增删改查的例子;
- ValueAnnotationExample: 通过 @Value 注解进行配置信息获取的例子。
#### Nacos Server 中添加配置
Expand Down Expand Up @@ -345,7 +343,9 @@ SecretKey|spring.cloud.nacos.config.secret-key||

#### 查询服务验证

在浏览器输入此地址 `http://127.0.0.1:8848/nacos/v1/ns/catalog/instances?serviceName=service-provider&clusterName=DEFAULT&pageSize=10&pageNo=1&namespaceId=`,并点击跳转,可以看到服务节点已经成功注册到 Nacos Server。
> **注意:需要替换 accessToken!**

在浏览器输入此地址 `http://127.0.0.1:8848/nacos/v1/ns/catalog/instances?accessToken=XXXXXXXXXXXXXXXXXXXXXX&serviceName=service-provider&clusterName=DEFAULT&pageSize=10&pageNo=1&namespaceId=`,并点击跳转,可以看到服务节点已经成功注册到 Nacos Server。

![查询服务](https://cdn.nlark.com/lark/0/2018/png/54319/1536986288092-5cf96af9-9a26-466b-85f6-39ad1d92dfdc.png)

Expand Down Expand Up @@ -572,7 +572,7 @@ Metadata|spring.cloud.nacos.discovery.metadata||使用Map格式配置
}
}
```c
```

#### Spring Cloud Gateway 应用启动

Expand Down
10 changes: 5 additions & 5 deletions spring-cloud-alibaba-examples/nacos-example/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ This project demonstrates how to use Spring Cloud Alibaba Nacos related Starters

[Nacos](https://github.com/alibaba/Nacos) It is Alibaba's open source dynamic service discovery, configuration management and service management platform that is easier to build cloud-native applications.

## Nacos Server 2.2.x is properly configured and started
## Nacos Server 2.3.0 is properly configured and started

In Nacos 2.2.x, functions related to user authentication are added. When starting Nacos Server for the first time, it needs to be configured correctly to avoid the problem of startup failure.
In Nacos 2.3.0, functions related to user authentication are added. When starting Nacos Server for the first time, it needs to be configured correctly to avoid the problem of startup failure.

### Download Nacos Server

Expand Down Expand Up @@ -49,7 +49,7 @@ db.pool.config.minimumIdle=2

#### Turn on authentication

**Note: If it is not enabled, login failure exception will occur in 2.2.x!**
**Note: If it is not enabled, login failure exception will occur in 2.3.0!**

```properties
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
Expand Down Expand Up @@ -77,7 +77,7 @@ nacos.core.auth.plugin.nacos.token.secret.key=SecretKey0123456789012345678901234

#### Open API authentication

Authentication is required when using the Open api interface in nacos server 2.2.x: For more details, please refer to: [Nacos api authentication](https://nacos.io/zh-cn/docs/auth.html)
Authentication is required when using the Open api interface in nacos server 2.3.0: For more details, please refer to: [Nacos api authentication](https://nacos.io/zh-cn/docs/auth.html)

1. Obtain accessToken: Use username and password to log in to the nacos server:

Expand Down Expand Up @@ -339,7 +339,7 @@ Before launching the Nacos Discovery sample for demonstration, take a look at ho

#### Query service validation

Enter this address `http://127.0.0.1:8848/nacos/v1/ns/catalog/instances?serviceName=service-provider&clusterName=DEFAULT&pageSize=10&pageNo=1&namespaceId=` in the browser and click Jump to see that the service node has been successfully registered to the Nacos Server.
Enter this address `http://127.0.0.1:8848/nacos/v1/ns/catalog/instances?accessToken=XXXXXXXXXXXXXXXXXXXXXXXXXXX&serviceName=service-provider&clusterName=DEFAULT&pageSize=10&pageNo=1&namespaceId=` in the browser and click Jump to see that the service node has been successfully registered to the Nacos Server.

![查询服务](https://cdn.nlark.com/lark/0/2018/png/54319/1536986288092-5cf96af9-9a26-466b-85f6-39ad1d92dfdc.png)

Expand Down

0 comments on commit ce28f82

Please sign in to comment.