阿里云 Cloud Shell 初体验

今日登陆阿里云,发现 阿里云 推出了 Cloud Shell,本以为是 一个 模拟 终端的一个小工具,体(zhe)验(teng)一番,发现 竟然 是一个 真实的 被限制的 Linux环境,基于 Alpine Linux。好兴奋,有免费的测试机玩了。。。。

阿里云 Cloud Shell 初体验

常用命令都被软关联到了 busybox。测试了下 gcc、apt-get、yum、rpm统统没有,这样就有点鸡肋了,除了自带的工具啥都不能安装。好在默认安装了 Python、SSH、curl等工具,pip因为权限太低不能安装库。

阿里云 Cloud Shell 初体验

看了下 shell 中的核心命令 aliyun,功能还是很强大的,基本所有 业务都可以操作。

shell@Alicloud:~$ aliyun --help

Alibaba Cloud Command Line Interface Version 3.0.6

Usage:

aliyun [--parameter1 value1 --parameter2 value2 ...]

Flags:

--mode use `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair}` to assign authenticate mode

--profile,-p use `--profile ` to select profile

--language use `--language [en|zh]` to assign language

--region use `--region ` to assign region

--access-key-id use `--access-key-id ` to assign AccessKeyId, required in AK/StsToken/RamRoleArn mode

--access-key-secret use `--access-key-secret ` to assign AccessKeySecret

--sts-token use `--sts-token ` to assign StsToken

--ram-role-name use `--ram-role-name ` to assign RamRoleName

--ram-role-arn use `--ram-role-arn

` to assign RamRoleArn

--role-session-name use `--role-session-name ` to assign RoleSessionName

--private-key use `--private-key ` to assign RSA PrivateKey

--key-pair-name use `--key-pair-name ` to assign KeyPairName

--secure use `--secure` to force https

--force use `--force` to skip api and parameters check

--endpoint use `--endpoint ` to assign endpoint

--version use `--version ` to assign product api version

--header use `--header X-foo=bar` to add custom HTTP header, repeatable

--body use `--body $(cat foo.json)` to assign http body in RESTful call

--pager use `--pager` to merge pages for pageable APIs

--output,-o use `--output cols=Field1,Field2 [rows=jmesPath]` to print output as table

--waiter use `--waiter expr= to=` to pull api until result equal to expected value

--dryrun add `--dryrun` to validate and print request without running.

--quiet,-q add `--quiet` to hide normal output

--help print help

Sample:

aliyun ecs DescribeRegions

Products:

aegis Server Guard

agency agency

alidns Alibaba Cloud DNS

arms Application Real-Time Monitoring Service

batchcompute BatchCompute

bssopenapi bss

ccc cloud call center

cdn Alibaba Cloud CDN

cds CodePipeline

chatbot BeeBot

cloudapi API Gateway

cloudauth ID Verification

cloudphoto Cloud Photos

cloudwf CloudAP

cms Cloud Monitor

cr Container Registry

cs Container Service

csb Cloud Service Bus

dds ApsaraDB for MongoDB

dm Direct Mail

domain domain

domain-intl domain

drds Distributed Relational Database Service

eci Elastic Container Instances

ecs Elastic Compute Service

edas Enterprise Distributed Application Service

elasticsearch elasticsearch

emr E-MapReduce

ess Auto Scaling

green Alibaba Content Security Service

hpc Alibaba Cloud HPC

httpdns HttpDNS

iot Alibaba Cloud IoT

itaas Cloud Display

jaq Mobile Security

kms Key Management Service

live ApsaraVideo for Live

mts ApsaraVideo for Media Processing

nas Network Attached Storage

ons Message Queue

ots Table Store

polardb ApsaraDB for POLARDB

push Alibaba Cloud Mobile Push

qualitycheck Smart Conversation Analysis

r-kvstore ApsaraDB for Redis

ram Resource Access Management

rds ApsaraDB for RDS

ros Resource Orchestration Service

sas-api Situation Awareness Service

slb Server Load Balancer

sts Resource Access Management

vod ApsaraVideo for VOD

vpc Virtual Private Cloud

waf Web Application Firewall

Use `aliyun --help` for more information.

之前 做过 域名API 相关的开发,拿域名入手,aliyun domain –help 可以看到 域名支持的操作,点击 链接可以进入 域名的API 文档。经过测试,API中的所有操作都可以 支持(很多在 命令帮助中 看不到),比如:QueryDomainList。

阿里云 Cloud Shell 初体验

shell@Alicloud:~$ aliyun domain --help

Alibaba Cloud Command Line Interface Version 3.0.6

Usage:

aliyun Domain --parameter1 value1 --parameter2 value2 ...

Product: Domain (domain)

Version: 2016-05-11

Link: https://help.aliyun.com/api/domain

Available Api List:

CheckDomain

CreateOrder

DeleteContactTemplate

GetWhoisInfo

OSuborderDomain

QueryBatchTaskDetailList

QueryBatchTaskList

QueryContact

QueryContactTemplate

QueryDomainBySaleId

QueryDomainList

QueryFailReasonList

QueryOrder

SaveContactTemplate

SaveContactTemplateCredential

SaveTaskForModifyingDomainDns

SaveTaskForSubmittingDomainNameCredential

SaveTaskForSubmittingDomainNameCredentialByTemplateId

SaveTaskForUpdatingContactByTempateId

SaveTaskForUpdatingContactByTemplateId

WhoisProtection

阿里的域名导出不太好用,用 QueryDomainList 接口,做个 域名导出工具,练练手。根据文档,必须的参数 有 PageNum、PageSize。 执行 aliyun domain QueryDomainList –PageNum 1 –PageSize 10000,就获取到了 每页10000条,第一个 的域名数据。将 输出的 JSON 信息 上传到 服务器处理(比如PHP),生成 csv 下载。

阿里云 Cloud Shell 初体验

经过测试 PageSize 最大值为 1000,我 公司账号里有上万条域名数据,需要分多页下载。考虑到 HTTP 请求的限制,每次只上传 100 个域名信息。经过一下午的摸索,终于 完美的实现了这个小功能。经过优化,已经比较完美了。按照 Linux 下的惯例, 只需要复制一行 命令即可使用。

阿里云 Cloud Shell 初体验

最终生成的文件如下:

阿里云 Cloud Shell 初体验

define('APP_PATH', 'http://www.miaoqiyuan.cn/products/alishell/'); //安装目录

define('APP_URL', APP_PATH . 'domain.php'); //程序路径

define('APP_ACTION', isset($_GET['action']) ? $_GET['action'] : ''); //请求方法

//读取 YunShell 上传的信息

$data = json_decode(file_get_contents("php://input"), true);

if (!empty($data) && isset($data['Data']) && isset($data['Data']['Domain'])) {

switch (APP_ACTION) {

case 'tocsv':

//分页上传域名数据

if (!isset($_GET['key']) && !is_numeric($_GET['key'])) {

die("Key Error!");

}

$tmp_key = $_GET['key'];

$csv_data = '';

foreach ($data['Data']['Domain'] as

$item) {

foreach ($item as $val) {

$csv_data .= $val . "\t";

}

$csv_data .= "\n";

}

$file_name = $tmp_key . '.txt';

file_put_contents($file_name, $csv_data, FILE_APPEND);

echo "Update: " . APP_PATH . "${file_name}";

break;

default:

//根据 总页数 生成 脚本

if (isset($data['TotalPageNum']) && is_numeric($data['TotalPageNum'])) {

$page_all = (int) $data['TotalPageNum'];

echo "\n\necho All:{$page_all}\n";

$tmp_key = date('Ymdhis');

for ($page_id = 1; $page_id <= $page_all; $page_id++) {

echo "\necho Download {$page_id}/${page_all}\n";

echo 'curl "' . APP_URL . '?action=tocsv&key=' . $tmp_key . '" --data "`' . "aliyun domain QueryDomainList --PageNum ${page_id} --PageSize 100" . '`"';

}

}

break;

}

//结尾输出换行,防止影响提示符

die("\n");

} else {

//直接访问,输出调用命令

echo 'curl ' . APP_URL . ' --data "`aliyun domain QueryDomainList --PageNum 1 --PageSize 100`"|bash';

}

?>


分享到:


相關文章: