centos6中AWS自动化运维脚本分享
发布:smiling 来源: PHP粉丝网 添加日期:2015-04-23 21:04:42 浏览: 评论:0
背景介绍:目前项目中使用了大量的AWS EC2 Instances作为服务器,在自动化运维方面,我们之前一直使用的是AWS CLI命令行工具,然后在Shell脚本中调用.
最近我想通过脚本实现一个“Clone”的功能,模拟Web Console上的“Launch More Like This”来创建Instance,但在Shell脚本中实现起来感觉不太舒服,于是就直接利用Python的boto库写了一个,在此分享给大家.
具体内容:
脚本地址:https://github.com/mcsrainbow/python-demos/blob/master/demos/awscli.py
相关示例:温馨提示:我的Blog页面默认没有采用宽屏模式,如果觉得下面的代码不太美观,可以点击右上角的“<>”切换到宽屏模式,代码如下:
- $ ./awscli.py -h
- usage: awscli.py [-h] (--create | --clone | --terminate) --region REGION
- [--instance_name INSTANCE_NAME] [--image_id IMAGE_ID]
- [--instance_type INSTANCE_TYPE] [--key_name KEY_NAME]
- [--security_group_ids SECURITY_GROUP_IDS]
- [--subnet_id SUBNET_ID]
- [--src_instance_name SRC_INSTANCE_NAME]
- [--dest_instance_name DEST_INSTANCE_NAME]
- [--private_ip_address PRIVATE_IP_ADDRESS]
- [--instance_id INSTANCE_ID] [--volume_size VOLUME_SIZE]
- [--volume_type {standard,io1,gp2}]
- [--volume_zone VOLUME_ZONE] [--volume_iops VOLUME_IOPS]
- [--volume_delete_on_termination]
- [--load_balancer_name LOAD_BALANCER_NAME]
- [--quick]
- examples:
- ./awscli.py --create --region us-west-1 --instance_name idc1-server2
- --image_id ami-30f01234 --instance_type t1.micro
- --key_name idc1-keypair1 --security_group_ids sg-eaf01234f
- --subnet_id subnet-6d901234
- ./awscli.py --create --region us-west-1 --instance_name idc1-server3
- --image_id ami-30f01234 --instance_type t1.micro
- --key_name idc1-keypair1 --security_group_ids sg-eaf01234f
- --subnet_id subnet-6d901234 --volume_size 10 --volume_type gp2
- --volume_zone us-west-1a --volume_delete_on_termination
- --load_balancer_name idc1-elb1 --private_ip_address 172.16.2.23
- ./awscli.py --clone --region us-west-1 --src_instance_name idc1-server1
- --dest_instance_name idc1-server2
- ./awscli.py --clone --region us-west-1 --src_instance_name idc1-server1
- --dest_instance_name idc1-server3 --private_ip_address 172.16.2.23
- ./awscli.py --terminate --region us-west-1 --instance_name idc1-server3
- ./awscli.py --terminate --region us-west-1 --instance_id i-01234abc
- ./awscli.py --terminate --region us-west-1 --instance_id i-01234abc --quick
- ...
- optional arguments:
- -h, --help show this help message and exit
- --create create instance
- --clone clone instance
- --terminate terminate instance
- --region REGION
- --instance_name INSTANCE_NAME
- --image_id IMAGE_ID
- --instance_type INSTANCE_TYPE
- --key_name KEY_NAME
- --security_group_ids SECURITY_GROUP_IDS
- --subnet_id SUBNET_ID
- --src_instance_name SRC_INSTANCE_NAME
- --dest_instance_name DEST_INSTANCE_NAME
- --private_ip_address PRIVATE_IP_ADDRESS
- --instance_id INSTANCE_ID
- --volume_size VOLUME_SIZE
- in GiB
- --volume_type {standard,io1,gp2}
- --volume_zone VOLUME_ZONE
- --volume_iops VOLUME_IOPS
- --volume_delete_on_termination
- delete volumes on termination
- --load_balancer_name LOAD_BALANCER_NAME
- --quick no wait on termination
- $ ./awscli.py --create --region us-west-1 --instance_name idc1-server1 --image_id ami-30f01234
- --instance_type t1.micro --key_name idc1-keypair1 --security_group_ids sg-eaf01234f
- --subnet_id subnet-6d901234 --volume_size 10 --volume_type gp2 --volume_zone us-west-1a
- --volume_delete_on_termination --load_balancer_name idc1-elb1 --private_ip_address 172.16.2.21
- 1. Launching instance: idc1-server1
- 2. Creating tag as instance name: {"Name": idc1-server1}
- Instance state: pending
- Instance state: running
- 3. Creating secondary volume for instance: idc1-server1 as gp2 10G
- Volume status: available
- 4. Attaching volume: vol-4ba6a54c to instance: idc1-server1 as device: /dev/sdf
- 5. Adding instance: idc1-server1 to ELB: idc1-elb1
- $ ./awscli.py --clone --region us-west-1 --src_instance_name idc1-server1 --dest_instance_name idc1-server2
- 1. Launching instance: idc1-server2
- 2. Creating tag as instance name: {"Name": idc1-server2}
- Instance state: pending
- Instance state: running
- 3. Creating secondary volume for instance: idc1-server2 as gp2 10G
- Volume status: available
- 4. Attaching volume: vol-5b61635c to instance: idc1-server2 as device: /dev/sdf
- 5. Adding instance: idc1-server2 to ELB: idc1-elb1
- $ ./awscli.py --terminate --region us-west-1 --instance_name idc1-server2 //phpfensi.com
- Terminating instance: idc1-server2 id: i-86976d62
- Instance state: shutting-down
- Instance state: shutting-down
- Instance state: terminated
Tags: centos6 AWS自动化
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)