更新时间:2025-09-10 GMT+08:00

指定节点缩容

功能介绍

当集群具备充足资源处理当前负载、业务处于流量低谷期或数据量减少时,可通过缩容指定节点节省资源。

接口约束

  • 缩容过程会涉及数据迁移,单个节点的数据迁移的超时阈值为48小时,超时将导致缩容失败。当集群数据量大时,建议手动调整数据迁移速率,避免在业务高峰期操作。

  • 包周期类型的集群不支持通过api进行指定节点缩容操作。

  • 在缩容前,建议备份所有关键数据,以免造成数据丢失。

  • 只有Elasticsearch和OpenSearch集群支持。

  • 缩容过程会涉及数据迁移,单个节点的数据迁移的超时阈值为48小时,超时将导致缩容失败。当集群数据量大时,建议手动调整数据迁移速率,避免在业务高峰期操作。

  • 无Master节点的集群:当数据节点数和冷数据节点数之和大于或等于3时(即“ 数据节点数 + 冷数据节点数 ≥ 3”)才支持缩容。单次缩容的数据节点数和冷数据节点数之和要小于缩容前数据节点数和冷数据节点数之和的一半,即“ 单次缩容的(数据节点数 + 冷数据节点数)< 缩容前的(数据节点数 + 冷数据节点数)÷ 2”。缩容后的数据节点数和冷数据节点数之和要大于索引副本数的最大值,即“ 缩容后的(数据节点数 + 冷数据节点数)> 索引副本数的最大值”。

  • 有Master节点的集群:当数据节点数大于或等于2时(即“ 数据节点数 ≥ 2”)才支持缩容。单次缩容的Master节点数要小于缩容前的Master节点数的一半,即“ 单次缩容的Master节点数 < 缩容前的Master节点数 ÷ 2”。

  • 缩容后,磁盘使用率必须小于80%。

  • 缩容后,每个AZ至少保留1个同类型节点,在跨AZ集群中,各AZ之间,同类型节点的数量差不得超过1。

调用方法

请参见如何调用API

URI

POST /v1.0/{project_id}/clusters/{cluster_id}/node/offline

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释

项目ID。获取方法请参见获取项目ID和名称

约束限制

不涉及

取值范围

账户的项目ID。

默认取值

不涉及

cluster_id

String

参数解释

指定缩容的集群ID。获取方法请参见获取集群ID

约束限制

不涉及

取值范围

集群ID。

默认取值

不涉及

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

migrate_data

String

参数解释

节点是否迁移数据。

取值范围

  • true:迁移数据。数据迁移过程中,系统会把待下线节点中的所有数据分片移动到剩余节点,待数据迁移完成后再进行节点下线操作。

  • false:不迁移数据。当待下线节点上的数据在剩余节点存在副本时,可跳过数据迁移,缩短集群变更时间,减少数据迁移带来的负载压力。

默认取值

true

shrink_nodes

Array of strings

参数解释

待缩容的节点ID。

约束限制

不涉及

取值范围

通过查询集群详情获取instances中的ID属性。

默认取值

不涉及

agency_name

String

参数解释

委托名称,删除节点会释放网卡,需要VPC的操作权限。选择IAM委托,授权当前账号访问和使用VPC的权限。

约束限制

委托需要有VPC的操作权限:"vpc:subnets:get","vpc:ports:*"。

对接了IAM新平面时该参数必填,对接IAM旧平面时该参数可选。

取值范围

不涉及

默认取值

不涉及

响应参数

状态码:200

请求已成功。

请求示例

通过指定节点方式缩容集群。

POST https://{Endpoint}/v1.0/{project_id}/clusters/4f3deec3-efa8-4598-bf91-560aad1377a3/node/offline

{
  "shrink_nodes" : [ "2077bdf3-b90d-412e-b460-635b9b159c11" ],
  "migrate_data" : "true"
}

响应示例

SDK代码示例

SDK代码示例如下。

Java

通过指定节点方式缩容集群。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.css.v1.region.CssRegion;
import com.huaweicloud.sdk.css.v1.*;
import com.huaweicloud.sdk.css.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateShrinkNodesSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        CssClient client = CssClient.newBuilder()
                .withCredential(auth)
                .withRegion(CssRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateShrinkNodesRequest request = new UpdateShrinkNodesRequest();
        request.withClusterId("{cluster_id}");
        ShrinkNodesReq body = new ShrinkNodesReq();
        List<String> listbodyShrinkNodes = new ArrayList<>();
        listbodyShrinkNodes.add("2077bdf3-b90d-412e-b460-635b9b159c11");
        body.withShrinkNodes(listbodyShrinkNodes);
        body.withMigrateData("true");
        request.withBody(body);
        try {
            UpdateShrinkNodesResponse response = client.updateShrinkNodes(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Python

通过指定节点方式缩容集群。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcss.v1.region.css_region import CssRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcss.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = CssClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CssRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateShrinkNodesRequest()
        request.cluster_id = "{cluster_id}"
        listShrinkNodesbody = [
            "2077bdf3-b90d-412e-b460-635b9b159c11"
        ]
        request.body = ShrinkNodesReq(
            shrink_nodes=listShrinkNodesbody,
            migrate_data="true"
        )
        response = client.update_shrink_nodes(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

通过指定节点方式缩容集群。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    css "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := css.NewCssClient(
        css.CssClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateShrinkNodesRequest{}
	request.ClusterId = "{cluster_id}"
	var listShrinkNodesbody = []string{
        "2077bdf3-b90d-412e-b460-635b9b159c11",
    }
	migrateDataShrinkNodesReq:= "true"
	request.Body = &model.ShrinkNodesReq{
		ShrinkNodes: listShrinkNodesbody,
		MigrateData: &migrateDataShrinkNodesReq,
	}
	response, err := client.UpdateShrinkNodes(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求已成功。

400

非法请求。

建议直接修改该请求,不要重试该请求。

409

服务器在完成请求时发生冲突。

返回该状态码,表明客户端尝试创建的资源已经存在,或者由于冲突请求的更新操作不能被完成。

412

未满足前提条件,服务器未满足请求者在请求中设置的其中一个前提条件。

错误码

请参见错误码