Aliyun

Aliyun

Aliyun

cred

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from alibabacloud_credentials.client import Client
from alibabacloud_credentials.models import Config

config = Config(
    type='access_key',                    # 凭证类型
    access_key_id='accessKeyId',          # AccessKeyId
    access_key_secret='accessKeySecret',  # AccessKeySecret
)
cred = Client(config)

access_key_id = cred.get_access_key_id()
access_key_secret = cred.get_access_key_secret()
cred_type = cred.get_type()

云盘扩容

 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Date: Fri Jun 10 19:10:39 2022
# Author: liuliancao <liuliancao@gmail.com>

"""Description: used for extend disk by instance names."""

# -*- coding: utf-8 -*-

import sys
import json
from typing import List

from alibabacloud_ecs20140526.client import Client as Ecs20140526Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ecs20140526 import models as ecs_20140526_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class AliyunDiskExtend:
    def __init__(self, access_key_id, access_key_secret):
        self.disk_client = self.create_client(access_key_id=access_key_id, access_key_secret=access_key_secret)

    def create_client(self,
        access_key_id: str,
        access_key_secret: str,
    ) -> Ecs20140526Client:
        """
        使用AK&SK初始化账号Client
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 您的 AccessKey ID,
            access_key_id=access_key_id,
            # 您的 AccessKey Secret,
            access_key_secret=access_key_secret
        )
        # 访问的域名
        config.endpoint = f'ecs-cn-hangzhou.aliyuncs.com'
        return Ecs20140526Client(config)

    def extend(self,
        args: List[str],
    ) -> None:
        resize_disk_request = ecs_20140526_models.ResizeDiskRequest(
            new_size=args['disk_size'],
            type=args['disk_change_type'],
            disk_id=args['disk_id']
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            self.disk_client.resize_disk_with_options(resize_disk_request, runtime)
        except Exception as error:
            # 如有需要,请打印 error
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    with open('./change_list.json') as f:
        change_list_file = json.loads(f.read())
        access_key_id = change_list_file['access_key_id']
        access_key_secret = change_list_file['access_key_secret']
        disk_size = change_list_file['disk_size']
        disk_ids = change_list_file['disk_ids']

    for disk_id in disk_ids:
        print("dealing with disk_id ", disk_id)
        AliyunDiskAPI = AliyunDiskExtend(access_key_id=access_key_id, access_key_secret=access_key_secret)
        args = {'disk_id': disk_id, 'disk_change_type': 'online', 'disk_size': disk_size}
        debug = AliyunDiskAPI.extend(args)
        print("debug info ", debug)

磁盘扩容

https://help.aliyun.com/document_detail/111738.html?spm=5176.2020520101events.top-nav.26.61754df56bgTnT&scm=20140722.S_help%40%40%E6%96%87%E6%A1%A3%40%40111738.S_hot%2Bos0.ID_111738-RL_growpart-LOC_consoleUNDhelp-OR_ser-V_2-P0_2

关机不计费

1
aliyun ecs StopInstances --region cn-hangzhou --RegionId 'cn-hangzhou' --StoppedMode StopCharging --InstanceId.1 1

cloud shell

如果不想写api 可以用cloud shell,也挺好用的 aliyun cloud shell 文档

regions列表

https://next.api.aliyun.com/api/Ecs/2014-05-26/DescribeRegions?tab=DEBUG 可以通过describe regions api获取所有

  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
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{
  "RequestId": "71B20E4F-800D-37C7-A3C0-61D18BFDDC8D",
  "Regions": {
    "Region": [
      {
        "RegionId": "cn-qingdao",
        "RegionEndpoint": "ecs.cn-qingdao.aliyuncs.com",
        "LocalName": "华北1(青岛)"
      },
      {
        "RegionId": "cn-beijing",
        "RegionEndpoint": "ecs.cn-beijing.aliyuncs.com",
        "LocalName": "华北2(北京)"
      },
      {
        "RegionId": "cn-zhangjiakou",
        "RegionEndpoint": "ecs.cn-zhangjiakou.aliyuncs.com",
        "LocalName": "华北3(张家口)"
      },
      {
        "RegionId": "cn-huhehaote",
        "RegionEndpoint": "ecs.cn-huhehaote.aliyuncs.com",
        "LocalName": "华北5(呼和浩特)"
      },
      {
        "RegionId": "cn-wulanchabu",
        "RegionEndpoint": "ecs.cn-wulanchabu.aliyuncs.com",
        "LocalName": "华北6(乌兰察布)"
      },
      {
        "RegionId": "cn-hangzhou",
        "RegionEndpoint": "ecs.aliyuncs.com",
        "LocalName": "华东1(杭州)"
      },
      {
        "RegionId": "cn-shanghai",
        "RegionEndpoint": "ecs.cn-shanghai.aliyuncs.com",
        "LocalName": "华东2(上海)"
      },
      {
        "RegionId": "cn-nanjing",
        "RegionEndpoint": "ecs.cn-nanjing.aliyuncs.com",
        "LocalName": "华东5(南京-本地地域)"
      },
      {
        "RegionId": "cn-shenzhen",
        "RegionEndpoint": "ecs.cn-shenzhen.aliyuncs.com",
        "LocalName": "华南1(深圳)"
      },
      {
        "RegionId": "cn-heyuan",
        "RegionEndpoint": "ecs.cn-heyuan.aliyuncs.com",
        "LocalName": "华南2(河源)"
      },
      {
        "RegionId": "cn-guangzhou",
        "RegionEndpoint": "ecs.cn-guangzhou.aliyuncs.com",
        "LocalName": "华南3(广州)"
      },
      {
        "RegionId": "cn-fuzhou",
        "RegionEndpoint": "ecs.cn-fuzhou.aliyuncs.com",
        "LocalName": "华东6(福州-本地地域)"
      },
      {
        "RegionId": "cn-chengdu",
        "RegionEndpoint": "ecs.cn-chengdu.aliyuncs.com",
        "LocalName": "西南1(成都)"
      },
      {
        "RegionId": "cn-hongkong",
        "RegionEndpoint": "ecs.cn-hongkong.aliyuncs.com",
        "LocalName": "中国香港"
      },
      {
        "RegionId": "ap-northeast-1",
        "RegionEndpoint": "ecs.ap-northeast-1.aliyuncs.com",
        "LocalName": "日本(东京)"
      },
      {
        "RegionId": "ap-northeast-2",
        "RegionEndpoint": "ecs.ap-northeast-2.aliyuncs.com",
        "LocalName": "韩国(首尔)"
      },
      {
        "RegionId": "ap-southeast-1",
        "RegionEndpoint": "ecs.ap-southeast-1.aliyuncs.com",
        "LocalName": "新加坡"
      },
      {
        "RegionId": "ap-southeast-2",
        "RegionEndpoint": "ecs.ap-southeast-2.aliyuncs.com",
        "LocalName": "澳大利亚(悉尼)"
      },
      {
        "RegionId": "ap-southeast-3",
        "RegionEndpoint": "ecs.ap-southeast-3.aliyuncs.com",
        "LocalName": "马来西亚(吉隆坡)"
      },
      {
        "RegionId": "ap-southeast-6",
        "RegionEndpoint": "ecs.ap-southeast-6.aliyuncs.com",
        "LocalName": "菲律宾(马尼拉)"
      },
      {
        "RegionId": "ap-southeast-5",
        "RegionEndpoint": "ecs.ap-southeast-5.aliyuncs.com",
        "LocalName": "印度尼西亚(雅加达)"
      },
      {
        "RegionId": "ap-south-1",
        "RegionEndpoint": "ecs.ap-south-1.aliyuncs.com",
        "LocalName": "印度(孟买)"
      },
      {
        "RegionId": "ap-southeast-7",
        "RegionEndpoint": "ecs.ap-southeast-7.aliyuncs.com",
        "LocalName": "泰国(曼谷)"
      },
      {
        "RegionId": "us-east-1",
        "RegionEndpoint": "ecs.us-east-1.aliyuncs.com",
        "LocalName": "美国(弗吉尼亚)"
      },
      {
        "RegionId": "us-west-1",
        "RegionEndpoint": "ecs.us-west-1.aliyuncs.com",
        "LocalName": "美国(硅谷)"
      },
      {
        "RegionId": "eu-west-1",
        "RegionEndpoint": "ecs.eu-west-1.aliyuncs.com",
        "LocalName": "英国(伦敦)"
      },
      {
        "RegionId": "me-east-1",
        "RegionEndpoint": "ecs.me-east-1.aliyuncs.com",
        "LocalName": "阿联酋(迪拜)"
      },
      {
        "RegionId": "eu-central-1",
        "RegionEndpoint": "ecs.eu-central-1.aliyuncs.com",
        "LocalName": "德国(法兰克福)"
      }
    ]
  }
}

public ip to eip

aliyun ecs ConvertNatPublicIpToEip –region cn-hangzhou –RegionId 'cn-hangzhou' –InstanceId 1

https://next.api.aliyun.com/api/Ecs/2014-05-26/ConvertNatPublicIpToEip?tab=CLI&params=%7B%22RegionId%22%3A%22cn-hangzhou%22%2C%22InstanceId%22%3A%221%22%7D

smc迁移

第一步导入迁移源 https://smcnext.console.aliyun.com/sourceServers/importMigrationSource?sourceServerType=SMT

第二步点击里面的生成激活码

第三步 服务器上面下载

1
2
wget 'https://p2v-tools.oss-cn-hangzhou.aliyuncs.com/smc/go2aliyun_client_linux_x86_64.tar.gz?spm=5176.smc-next_import-source-server.0.0.2fcd18e60cy1T7&file=go2aliyun_client_linux_x86_64.tar.gz'
tar xf go2aliyun_client_linux_x86_64.tar.gz

第四步 配置

1
2
3
4
5
[root@ops-test-jenkins_039 ~]# cat go2aliyun_client2.7.3_linux_x86_64/user_config.json 
{
    "access_token_code": "xxx",
    "access_token_id" : "at-xxx"
}

第五步 运行二进制文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[root@xxx go2aliyun_client2.7.3_linux_x86_64]# ./go2aliyun_client 
[2023-12-26 09:52:44] [Info]  ========= Goto Aliyun Client 2.7.3. =========
[2023-12-26 09:48:47] [Info]  =========   Run In BackGround Daemon Mode   =========
[2023-12-26 09:48:47] [Info]  Goto Aliyun Begin...
[2023-12-26 09:48:47] [Info]  Check Source Server Status...
[2023-12-26 09:48:47] [Info]  Query Source Server...
Please Goto SMC Console To Create New Job, time: 6m31s    \       
[2023-12-26 09:55:48] [Info]  Replication Job [j-bp14ccvl3a2p4hxlksgc] Is TestRunning.
[2023-12-26 09:55:49] [Info]  Do Source Test...
/root/go2aliyun_client2.7.3_linux_x86_64/Check/Test/cpu_usage_exceed.sh: line 7: bc: command not found
[2023-12-26 09:55:49] [Info]  Do Source Test [Source.CPUUsageExceeded] Passed, Status: normal
/root/go2aliyun_client2.7.3_linux_x86_64/Check/Test/memory_usage_exceed.sh: line 10: bc: command not found
...

开启kdump

https://help.aliyun.com/zh/ecs/how-to-enable-the-kdump-service-for-linux-instances?spm=5176.ecscore_server.top-nav.5.1b834df5mlWpAE&scm=20140722.S_help%40%40%E6%96%87%E6%A1%A3%40%40167572.S_BB2%40bl%2BRQW%40ag0%2BBB1%40ag0%2Bhot%2Bos0.ID_167572-RL_kdump-LOC_console~UND~help-OR_ser-V_3-P0_0

云盘扩容失败无法resize2fs initial error at time 1673463435: ext4_reserve_inode_write

云盘报错这种情况如果不是系统盘,一般e2fsck对应的硬件设备就好了。

如果是系统盘,这个时候,需要首先服务器关机,卸载掉这个系统盘,然后挂载 到另一台服务器,执行e2fsck,修复以后再挂载到老的这台机器。然后启动观察 下,

最后再重新resize2fs即可

参考文档