美文网首页
阿里云 ECS云助手使用

阿里云 ECS云助手使用

作者: 黑曼巴yk | 来源:发表于2019-09-29 09:27 被阅读0次

简介

云助手是云服务器ECS原生的运维部署服务,支持可视化控制台和API操作。简单的说阿里云云助手可以帮忙我们方便进行运维部署

API编程使用

const client = new Core({
  accessKeyId: 'xxxxxx',
  accessKeySecret: 'xxxxx',
  endpoint: 'https://ecs.aliyuncs.com',
  apiVersion: '2014-05-26',
});
const RegionId = 'cn-hangzhou';

async createCommand(CommandId) {
  const params = {
    "RegionId",
    "Name": "test",
    "Type": "RunShellScript",
    "CommandContent": "echo dankun"
  }
   client.request('CreateCommand', params,  { method: 'POST' });
}

// 执行命令
async invokeCommand(CommandId) {
    const params = {
      CommandId,
      RegionId,
      'InstanceId.1': 'i-bp1ge7stkcnj5044oa83',
      'InstanceId.2': 'i-bp1ge7stkcnj5044oa81',
      'InstanceId.3': 'i-bp1ge7stkcnj5044oa82',
    };
    const result = await client.request('InvokeCommand', params, { method: 'POST' });
    return result.InvokeId;
  }

控制台使用

  1. 控制台页面


    image.png
  2. 定时执行
    定时执行使用cron表达式

但是这里有个坑:cron表达式的时间格式为UTC时间。意思是正常的北京时间减去8小时,才是正常的执行时间。比如:
我们希望凌晨3点形式执行某个任务,比如希望晚上定时备份数据库corn表达式为 0 0 3 * * ?。但是却意外发现变成中午11点执行,导致业务异常。这里特别需要注意下

相关文章

网友评论

      本文标题:阿里云 ECS云助手使用

      本文链接:https://www.haomeiwen.com/subject/vegsyctx.html