From 4378537a38f1791eb7d057ceb091f1df212700ed Mon Sep 17 00:00:00 2001 From: Steve Rao Date: Thu, 12 Jan 2023 16:28:35 +0800 Subject: [PATCH] feature: update 2.2.10-RC1 relevant docs (#3086) feature: update 2.2.10-RC1 relevant docs --- .../src/main/asciidoc-zh/governance.adoc | 53 ++++++++----------- .../src/main/asciidoc-zh/nacos-discovery.adoc | 9 +++- .../asciidoc-zh/spring-cloud-alibaba.adoc | 2 + .../src/main/asciidoc/governance.adoc | 40 +++++++------- .../src/main/asciidoc/nacos-discovery.adoc | 11 ++-- .../main/asciidoc/spring-cloud-alibaba.adoc | 4 +- .../nacos-discovery-example/readme-zh.md | 13 +++-- .../nacos-discovery-example/readme.md | 10 ++-- 8 files changed, 76 insertions(+), 66 deletions(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/governance.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/governance.adoc index 111bc53f7..de31bf475 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/governance.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/governance.adoc @@ -2,15 +2,14 @@ image::pic/governance-module.png[] -Spring Cloud Alibaba Governance模块是Spring Cloud Alibaba推出的微服务治理子模块,提供了多种类型的微服务治理能力,包括标签路由,服务鉴权等。并且对接了多种控制面,比如Istio,OpenSergo,让用户无需改造Spring Cloud应用,也能实时感知到Istio等治理控制面下发的治理规则,并将此规则应用到Spring Cloud应用上,从而完成对Spring Cloud应用的治理。 +Microservices Governance是Spring Cloud Alibaba最新推出的微服务治理能力,提供了多种类型的微服务治理能力,包括标签路由,服务鉴权等。并且对接了多种控制面,比如Istio,OpenSergo,让用户无需改造Spring Cloud应用,也能实时感知到上述治理控制面下发的治理规则,并将此规则应用到Spring Cloud应用上,从而完成对Spring Cloud应用的治理。 -== 如何使用 === 配置转换 image::pic/resource-transform.png[] -Spring Cloud Alibaba Governance的resource-transform模块会将不同控制面下发的配置进行统一的转换,将来自Istio,OpenSergo等控制面下发的配置统一转换为Spring Cloud Alibaba统一抽象出的数据结构以供后续使用 +Microservices Governance的配置转换模块会将不同控制面下发的配置进行统一的转换,目前支持将来自Istio,OpenSergo等控制面下发的配置统一转换为Spring Cloud Alibaba统一抽象出的数据结构以供后续使用 -如果在您的项目中使用Istio来实现配置转换,需要使用group ID 为 `com.alibaba.cloud` 和artifact ID 为 `spring-cloud-starter-xds-adapter` 的starter +如果在项目中使用Istio来实现规则转换,需要使用如下starter依赖: [source,xml,indent=0] ---- @@ -18,6 +17,7 @@ Spring Cloud Alibaba Governance的resource-transform模块会将不同控制面 spring-cloud-starter-xds-adapter ---- +OpenSergo请参考https://github.com/alibaba/spring-cloud-alibaba/tree/2.2.x/spring-cloud-alibaba-examples/governance-example/label-routing-example[Spring Cloud Alibaba Routing Examples] 之后,在application.yml配置文件中配置如下配置 @@ -48,23 +48,13 @@ spring: |是否连接Istio获取鉴权配置| spring.cloud.istio.config.enabled|true| |Istiod的地址| spring.cloud.istio.config.host|127.0.0.1| |Istiod的端口| spring.cloud.istio.config.port|15012|注:连接15010端口无需TLS,连接15012端口需TLS认证 -|SCA去Istio拉取配置的线程池大小| spring.cloud.istio.config.polling-pool-size|10| -|SCA去Istio拉取配置的间隔时间| spring.cloud.istio.config.polling-time|30|单位为秒 +|应用从Istio拉取配置的线程池大小| spring.cloud.istio.config.polling-pool-size|10| +|应用从Istio拉取配置的间隔时间| spring.cloud.istio.config.polling-time|30|单位为秒 |连接Istio 15012端口时使用的JWT token| spring.cloud.istio.config.istiod-token|应用所在pod的 `/var/run/secrets/tokens/istio-token` 文件的内容| |是否打印xDS相关日志| spring.cloud.istio.config.log-xds|true| |=== -=== 运行应用 -需要将应用运行在K8s环境中,并给运行的应用将K8s的一些元信息注入以下环境变量中: - -|=== -|环境变量名|K8s pod metadata name -|POD_NAME|metadata.name -|NAMESPACE_NAME|metadata.namespace -|=== - -=== 运行应用 -需要将应用运行在K8s环境中,并给运行的应用将K8s的一些元信息注入以下环境变量中: +注意,应用运行在K8s环境中,在非默认命名空间下的应用,需要接收Istiod下发的规则,需要将运行的应用K8s的元信息注入以下环境变量中,具体操作方式可参考 https://kubernetes.io/zh-cn/docs/tasks/inject-data-application/environment-variable-expose-pod-information[Kubernetes文档]: |=== |环境变量名|K8s pod metadata name @@ -85,9 +75,9 @@ spring: ==== 使用路由 -在引入配置转换模块后,我们就能获取到相应的治理规则来对Spring Cloud应用赋予相应的治理能力。标签路由模块可以实现对Spring Cloud应用根据请求头,请求参数等标签来路由到不同的服务 +在引入配置转换模块后,就能获取到相应的治理规则来对应用赋予相应的治理能力。标签路由模块可以实现对应用根据请求头,请求参数等标签来路由到不同的服务 -1.如果在您的项目中使用Spring Cloud Alibaba Governance 标签路由,需要使用需要使用group ID 为 `com.alibaba.cloud` 和artifact ID 为 `spring-cloud-starter-alibaba-governance-routing` 的starter +1.如果在项目中使用Spring Cloud Alibaba 标签路由,需要使用添加如下starter [source,xml,indent=0] ---- @@ -96,8 +86,8 @@ spring: ---- -2.配置当没有路由规则时的负载均衡算法(以随机负载均衡算法为例) -如果没有配置,使用ribbon默认的负载均衡算法ZoneAvoidanceRule +2.配置进行路由规则时的负载均衡算法(以随机负载均衡算法为例) +如果未配置,使用Ribbon默认的负载均衡算法ZoneAvoidanceRule ---- spring.cloud.governance.routing.rule=RandomRule ---- @@ -108,18 +98,18 @@ spring.cloud.governance.routing.rule=RandomRule * 请求头 * 请求参数 -我们使用Istio下发对应的 `DestinationRule` 以及 `VirtualService` ,即可配置对应的标签路由规则,具体的配置方法请参考以下文档与示例 +使用Istio下发对应的 `DestinationRule` 以及 `VirtualService` ,即可配置对应的标签路由规则,具体的配置方法请参考以下文档与示例 -* https://istio.io/latest/zh/docs/reference/config/networking/virtual-service/#VirtualService -* https://istio.io/latest/zh/docs/concepts/traffic-management/#destination-rules -* spring-cloud-alibaba-examples/governance-example/label-routing-example/istio-label-routing-consumer-example +* https://istio.io/latest/zh/docs/reference/config/networking/virtual-service/#VirtualService[Istio VirtualService] +* https://istio.io/latest/zh/docs/concepts/traffic-management/#destination-rules[Istio Destination Rule] +* https://github.com/alibaba/spring-cloud-alibaba/tree/2.2.x/spring-cloud-alibaba-examples/governance-example/label-routing-example[Spring Cloud Alibaba Routing Examples] -=== 使用服务鉴权 +=== 服务鉴权 image::pic/auth-process.png[] 在引入配置转换模块后,我们就能获取到相应的治理规则来对Spring Cloud应用赋予相应的治理能力。服务鉴权模块给Spring Cloud应用提供多种鉴权方式,如IP黑白名单,JWT鉴权等 -如果在您的项目中使用Spring Cloud Alibaba Governance 标签路由,需要使用需要使用group ID 为 `com.alibaba.cloud` 和artifact ID 为 `spring-cloud-starter-alibaba-governance-auth` 的starter +如果使用Spring Cloud Alibaba服务鉴权功能,需要使用添加如下依赖: [source,xml,indent=0] ---- @@ -128,9 +118,8 @@ image::pic/auth-process.png[] ---- -我们使用Istio下发对应的 `AuthorizationPolicy` 以及 `RequestAuthentication` ,即可配置对应的鉴权规则,具体的配置方法请参考以下文档与示例 +使用Istio下发对应的 `AuthorizationPolicy` 以及 `RequestAuthentication` ,即可配置对应的鉴权规则,具体的配置方法请参考以下文档与示例 -* https://istio.io/latest/zh/docs/reference/config/security/request_authentication/ -* https://istio.io/latest/zh/docs/reference/config/security/authorization-policy/ -* spring-cloud-alibaba-examples/governance-example/authentication-example/istio-authentication-provider-mvc-example -* spring-cloud-alibaba-examples/governance-example/authentication-example/istio-authentication-provider-webflux-example +* https://istio.io/latest/zh/docs/reference/config/security/request_authentication/[Istio RequestAuthentication] +* https://istio.io/latest/zh/docs/reference/config/security/authorization-policy/[Authorization Policy] +* https://github.com/alibaba/spring-cloud-alibaba/tree/2.2.x/spring-cloud-alibaba-examples/governance-example/authentication-example[Spring Cloud Alibaba Authorization Examples] diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc index 3a562b483..00972aeb4 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc @@ -303,10 +303,15 @@ Endpoint 暴露的 json 中包含了两种属性: === IPv4至IPv6地址迁移方案 +Spring Cloud Alibaba 提供了使用双注册双订阅方式帮助用户实现应用IPv4向IPv6不停机迁移,在使用相关功能之前,需要在服务消费者应用 application.properties 配置客户端负载均衡为 Spring Cloud Alibaba 所提供的 NacosRule 负载均衡算法,配置方式如下,注意需要将[service-name]替换成具体的待消费服务名。 + + [service-name].ribbon.NFLoadBalancerRuleClassName=com.alibaba.cloud.nacos.ribbon.NacosRule + ==== IPv4和IPv6地址双注册 在配置完成NacosRule作为负载均衡策略后,应用启动后会默认将微服务的IPv4地址和IPv6地址注册到注册中心中,其中IPv4地址会存放在Nacos服务列表中的IP字段下,IPv6地址在Nacos的metadata字段中,其对应的Key为IPv6。当服务消费者调用服务提供者时,会根据自身的IP地址栈支持情况,选择合适的IP地址类型发起服务调用。具体规则: -(1)服务消费者本身支持IPv4和IPv6双地址栈或仅支持IPv6地址栈的情况下,服务消费者会使用服务提供的IPv6地址发起服务调用,IPv6地址调用失败如本身还同事支持IPv4地址栈时,暂不支持切换到IPv4再发起重试调用; -(2)服务消费者本身仅支持IPv4单地址栈的情况下,服务消费者会使用服务提供的IPv4地址发起服务调用。 + +1. 服务消费者本身支持IPv4和IPv6双地址栈或仅支持IPv6地址栈的情况下,服务消费者会使用服务提供的IPv6地址发起服务调用,IPv6地址调用失败如本身还同事支持IPv4地址栈时,暂不支持切换到IPv4再发起重试调用; +2. 服务消费者本身仅支持IPv4单地址栈的情况下,服务消费者会使用服务提供的IPv4地址发起服务调用。 ==== 仅注册IPv4 如果您只想使用IPv4地址进行注册,可以在application.properties使用以下配置: diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc index 785d42779..2ff0754f4 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc @@ -33,4 +33,6 @@ include::sidecar.adoc[] include::appactive.adoc[] +include::governance.adoc[] + diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc/governance.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc/governance.adoc index 7a24b41f5..b76ecd4b9 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc/governance.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc/governance.adoc @@ -2,16 +2,15 @@ image::pic/governance-module.png[] -Spring Cloud Alibaba Governance module is a micro-service governance sub-module launched by Spring Cloud Alibaba, which provides various types of micro-service governance capabilities, including label routing, service authentication, etc. Moreover, it supports various control planes, such as Istio and OpenSergo, so that users can get the governance rules in real time without modifying Spring Cloud applications, and apply these rules to Spring Cloud applications to govern the Spring Cloud application. +Microservices Governance module is a micro-service governance sub-module launched by Spring Cloud Alibaba, which provides various types of microservices governance capabilities, including label routing, service authentication, etc. Moreover, it supports various control planes, such as Istio and OpenSergo, so that users can get the governance rules in real time without modifying Spring Cloud applications, and apply these rules to applications to govern the Spring Cloud application. -== How to use === Resource-Transform image::pic/resource-transform.png[] -The resource-transform module of Spring Cloud Alibaba Governance will uniformly transform the configurations published by different control planes, like Istio and OperSergo, into the unified abstract data structure of Spring Cloud Alibaba for subsequent use. +The resource-transform module of Microservices Governance will uniformly transform the configurations published by different control planes, like Istio and OperSergo, into the unified abstract data structure of Spring Cloud Alibaba for subsequent use. -If you use Istio in your project to transform the configuration, you need to use a starter with a group ID of `com.alibaba.cloud` and an artifact ID of `spring-cloud-starter-xds-adapter`. +If you use Istio in your project to transform the configuration, you need to use a following starter: [source,xml,indent=0] ---- @@ -19,6 +18,7 @@ If you use Istio in your project to transform the configuration, you need to use spring-cloud-starter-xds-adapter ---- +If you want to use OpenSergo, you can refer to https://github.com/alibaba/spring-cloud-alibaba/tree/2.2.x/spring-cloud-alibaba-examples/governance-example/label-routing-example[Spring Cloud Alibaba Routing Examples] After that, configure the following configuration in the application.yml: @@ -49,14 +49,13 @@ Here's an explanation of each field: |Whether to connect to Istio to obtain authentication configuration| spring.cloud.istio.config.enabled|true| |Host of Istiod| spring.cloud.istio.config.host|127.0.0.1| |Port of Istiod| spring.cloud.istio.config.port|15012|15010 port does not need TLS,but 15012 does -|Thread pool size for SCA to pull the config| spring.cloud.istio.config.polling-pool-size|10| -|Time interval for SCA to pull the config| spring.cloud.istio.config.polling-time|30|The unit is second -|JWT token for SCA to connect to 15012 port| spring.cloud.istio.config.istiod-token|Content of file `/var/run/secrets/tokens/istio-token` in the pod of application| +|Thread pool size for application to pull the config| spring.cloud.istio.config.polling-pool-size|10| +|Time interval for application to pull the config| spring.cloud.istio.config.polling-time|30|The unit is second +|JWT token for application to connect to 15012 port| spring.cloud.istio.config.istiod-token|Content of file `/var/run/secrets/tokens/istio-token` in the pod of application| |Whether to print logs about xDS| spring.cloud.istio.config.log-xds|true| |=== -### Run the application -You need to run the application in the K8s environment and inject some meta information about K8s into the following environment variables for the running application. +Note that the application runs in the K8s environment, and the application in the non-default namespace needs to receive the rules issued by Istiod, and needs to inject the meta information of the running application Kubernetes into the following environment variables. For the specific operation method, please refer to https://kubernetes.io/zh-cn/docs/tasks/inject-data-application/environment-variable-expose-pod-information[Kubernetes documentation] |=== |Environment variable name|K8s pod metadata name @@ -75,10 +74,10 @@ Load balance Component: Ribbon In the future, more components such as RestTemplate, Spring Cloud LoadBalancer and so on will be supported. -==== use Routing +==== Using With the introduction of the configuration transformation module, we can obtain the governance rules to give the Spring Cloud application some governance capabilities. Label routing module can route the Spring Cloud application according to the request header, request parameters and other tags to route to different services. -If you use Spring Cloud Alibaba Governance Label Routing in your project, You need to use a starter with a group ID of `com.alibaba.cloud` and an artifact ID of `spring-cloud-starter-alibaba-governance-routing`. +If you use Microservices Governance Label Routing in your project, You need to use a following starter: [source,xml,indent=0] ---- @@ -87,7 +86,7 @@ If you use Spring Cloud Alibaba Governance Label Routing in your project, You ne ---- -2.Configure a load balance algorithm when there are no routing rules (RandomRule algorithm as an example) +2.Configure a load balance algorithm when there are routing rules (RandomRule algorithm as an example) If no configuration,use default ribbon load balance algorithm ZoneAvoidanceRule. ---- spring.cloud.governance.routing.rule=RandomRule @@ -101,16 +100,16 @@ With the introduction of Istio Resource Transform module, the label routing modu We use Istio to publish corresponding `DestinationRule` and `VirtualService` to configure corresponding labeled routing rules. For details, see the following documents and examples: -* https://istio.io/latest/zh/docs/reference/config/networking/virtual-service/#VirtualService -* https://istio.io/latest/zh/docs/concepts/traffic-management/#destination-rules -* spring-cloud-alibaba-examples/governance-example/label-routing-example/istio-label-routing-consumer-example +* https://istio.io/latest/zh/docs/reference/config/networking/virtual-service/#VirtualService[Istio VirtualService] +* https://istio.io/latest/zh/docs/concepts/traffic-management/#destination-rules[Istio Destination Rule] +* https://github.com/alibaba/spring-cloud-alibaba/tree/2.2.x/spring-cloud-alibaba-examples/governance-example/label-routing-example[Spring Cloud Alibaba Routing Examples] -=== Use Authentication +=== Authentication image::pic/auth-process.png[] With the introduction of the configuration transformation module, we can obtain the governance rules to give the Spring Cloud application some governance capabilities. The Authentication module provides various authentication modes for Spring Cloud applications, such as IP blacklist and whitelist and JWT authentication. -If you use Istio in your project to transform the configuration, you need to use a starter with a group ID of `com.alibaba.cloud` and an artifact ID of `spring-cloud-starter-alibaba-governance-auth`. +Add following Microservices Authentication starter: [source,xml,indent=0] ---- @@ -122,7 +121,6 @@ If you use Istio in your project to transform the configuration, you need to use We use Istio to publish corresponding `AuthorizationPolicy` and `RequestAuthentication` to configure corresponding Authentication rules. For details, see the following documents and examples -* https://istio.io/latest/zh/docs/reference/config/security/request_authentication/ -* https://istio.io/latest/zh/docs/reference/config/security/authorization-policy/ -* spring-cloud-alibaba-examples/governance-example/authentication-example/istio-authentication-provider-mvc-example -* spring-cloud-alibaba-examples/governance-example/authentication-example/istio-authentication-provider-webflux-example +* https://istio.io/latest/zh/docs/reference/config/security/request_authentication/[Istio RequestAuthentication] +* https://istio.io/latest/zh/docs/reference/config/security/authorization-policy/[Authorization Policy] +* https://github.com/alibaba/spring-cloud-alibaba/tree/2.2.x/spring-cloud-alibaba-examples/governance-example/authentication-example[Spring Cloud Alibaba Authorization Examples] diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc/nacos-discovery.adoc index 29899c830..b330f2fc5 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc/nacos-discovery.adoc @@ -304,12 +304,17 @@ The followings shows how a service instance accesses the Endpoint: [service_name].ribbon.NFLoadBalancerRuleClassName=com.alibaba.cloud.nacos.ribbon.NacosRule ---- -=== IPv4 to IPv6 address migration scheme +=== IPv4 to IPv6 address migration + +Spring Cloud Alibaba provides a dual registration and dual subscription method to help users migrate applications from IPv4 to IPv6 without downtime. Before using related functions, it is necessary to configure client load balancing in the application.properties of the service consumer as the NacosRule provided by Spring Cloud Alibaba The load balancing algorithm is configured as follows. Note that [service-name] needs to be replaced with the specific service name to be consumed. + + [service-name].ribbon.NFLoadBalancerRuleClassName=com.alibaba.cloud.nacos.ribbon.NacosRule ==== Both register IPv4 and IPv6 address After configuring NacosRule as the load balancing policy, the IPv4 address and IPv6 address of the microservice will be registered with the registry by default after the application is started, where the IPv4 address will be stored in the IP field of the Nacos service list, the IPv6 address will be in the metadata field of Nacos, and its corresponding Key will be IPv6. When a service consumer calls a service provider, it selects the appropriate IP address type to initiate a service call based on its IP address stack support. Specific rules: -(1) If the service consumer itself supports IPv4 and IPv6 dual address stacks or only supports IPv6 address stacks, the service consumer will use the IPv6 address provided by the service to initiate a service call, and if the IPv6 address call fails, if it also supports the IPv4 address stack, it is temporarily not supported to switch to IPv4 and then initiate a retry call; -(2) If the service consumer itself only supports IPv4 single-address stack, the service consumer will use the IPv4 address provided by the service to initiate service calls. + +1. If the service consumer itself supports IPv4 and IPv6 dual address stacks or only supports IPv6 address stacks, the service consumer will use the IPv6 address provided by the service to initiate a service call, and if the IPv6 address call fails, if it also supports the IPv4 address stack, it is temporarily not supported to switch to IPv4 and then initiate a retry call; +2. If the service consumer itself only supports IPv4 single-address stack, the service consumer will use the IPv4 address provided by the service to initiate service calls. ==== Only Register IPv4 address If you only want to register IPv4 address.Config in application.properties as follows: diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc/spring-cloud-alibaba.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc/spring-cloud-alibaba.adoc index dae0f28cc..84c7a0a3a 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc/spring-cloud-alibaba.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc/spring-cloud-alibaba.adoc @@ -29,4 +29,6 @@ include::schedulerx.adoc[] include::sms.adoc[] -include::appactive.adoc[] \ No newline at end of file +include::appactive.adoc[] + +include::governance.adoc[] \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md index fe2251cbe..54356bd4c 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md @@ -164,20 +164,25 @@ NacosServerList 实现了 com.netflix.loadbalancer.ServerList 接口, 如果需要有更加自定义的可以使用 @Autowired 注入一个 NacosRegistration 实例,通过其持有的 NamingService 字段内容直接调用 Nacos API。 ## IPv4至IPv6地址迁移方案 +Spring Cloud Alibaba 提供了使用双注册双订阅方式帮助用户实现应用IPv4向IPv6不停机迁移,在使用相关功能之前,需要在服务消费者应用 application.properties 配置客户端负载均衡为 Spring Cloud Alibaba 所提供的 NacosRule 负载均衡算法,配置方式如下,注意需要将[service-name]替换成具体的待消费服务名。 + + [service-name].ribbon.NFLoadBalancerRuleClassName=com.alibaba.cloud.nacos.ribbon.NacosRule + + ### IPv4和IPv6地址双注册 在配置完成NacosRule作为负载均衡策略后,应用启动后会默认将微服务的IPv4地址和IPv6地址注册到注册中心中,其中IPv4地址会存放在Nacos服务列表中的IP字段下,IPv6地址在Nacos的metadata字段中,其对应的Key为IPv6。当服务消费者调用服务提供者时,会根据自身的IP地址栈支持情况,选择合适的IP地址类型发起服务调用。具体规则: -(1)服务消费者本身支持IPv4和IPv6双地址栈或仅支持IPv6地址栈的情况下,服务消费者会使用服务提供的IPv6地址发起服务调用,IPv6地址调用失败如本身还同事支持IPv4地址栈时,暂不支持切换到IPv4再发起重试调用; -(2)服务消费者本身仅支持IPv4单地址栈的情况下,服务消费者会使用服务提供的IPv4地址发起服务调用。 + 1. 服务消费者本身支持IPv4和IPv6双地址栈或仅支持IPv6地址栈的情况下,服务消费者会使用服务提供的IPv6地址发起服务调用,IPv6地址调用失败如本身还同事支持IPv4地址栈时,暂不支持切换到IPv4再发起重试调用; + 2. 服务消费者本身仅支持IPv4单地址栈的情况下,服务消费者会使用服务提供的IPv4地址发起服务调用。 ### 仅注册IPv4 -如果您只想使用IPv4地址进行注册,可以在application.properties使用以下配置: +如果只想使用IPv4地址进行注册,可以在application.properties使用以下配置: ``` spring.cloud.nacos.discovery.ip-type=IPv4 ``` ### 仅注册IPv6 -如果您只想使用IPv6地址,可以在application.properties使用以下配置: +如果只想使用IPv6地址,可以在application.properties使用以下配置: ``` spring.cloud.nacos.discovery.ip-type=IPv6 ``` diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md index 6e1557b33..4539047b3 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md @@ -168,12 +168,16 @@ NacosServerList implements the com.netflix.loadbalancer.ServerList inte If you need to be more customizable, you can use @Autowired to inject a NacosRegistration bean and call the Nacos API directly through the contents of the NamingService field it holds. -## IPv4 to IPv6 address migration scheme +## IPv4 to IPv6 address migration + +Spring Cloud Alibaba provides a dual registration and dual subscription method to help users migrate applications from IPv4 to IPv6 without downtime. Before using related functions, it is necessary to configure client load balancing in the application.properties of the service consumer as the NacosRule provided by Spring Cloud Alibaba The load balancing algorithm is configured as follows. Note that [service-name] needs to be replaced with the specific service name to be consumed. + + [service-name].ribbon.NFLoadBalancerRuleClassName=com.alibaba.cloud.nacos.ribbon.NacosRule ### Both register IPv4 and IPv6 address After configuring NacosRule as the load balancing policy, the IPv4 address and IPv6 address of the microservice will be registered with the registry by default after the application is started, where the IPv4 address will be stored in the IP field of the Nacos service list, the IPv6 address will be in the metadata field of Nacos, and its corresponding Key will be IPv6. When a service consumer calls a service provider, it selects the appropriate IP address type to initiate a service call based on its IP address stack support. Specific rules: -(1) If the service consumer itself supports IPv4 and IPv6 dual address stacks or only supports IPv6 address stacks, the service consumer will use the IPv6 address provided by the service to initiate a service call, and if the IPv6 address call fails, if it also supports the IPv4 address stack, it is temporarily not supported to switch to IPv4 and then initiate a retry call; -(2) If the service consumer itself only supports IPv4 single-address stack, the service consumer will use the IPv4 address provided by the service to initiate service calls. +1. If the service consumer itself supports IPv4 and IPv6 dual address stacks or only supports IPv6 address stacks, the service consumer will use the IPv6 address provided by the service to initiate a service call, and if the IPv6 address call fails, if it also supports the IPv4 address stack, it is temporarily not supported to switch to IPv4 and then initiate a retry call; +2. If the service consumer itself only supports IPv4 single-address stack, the service consumer will use the IPv4 address provided by the service to initiate service calls. ### Only Register IPv4 address If you only want to register IPv4 address.Config in application.properties as follows: