centos6中AWS自动化运维脚本分享
2019/10/10/17:46:02 阅读:1738 来源:谷歌SEO算法 标签:
挖矿
背景介绍:目前项目中使用了大量的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)--regionREGION
- [--instance_nameINSTANCE_NAME][--image_idIMAGE_ID]
- [--instance_typeINSTANCE_TYPE][--key_nameKEY_NAME]
- [--security_group_idsSECURITY_GROUP_IDS]
- [--subnet_idSUBNET_ID]
- [--src_instance_nameSRC_INSTANCE_NAME]
- [--dest_instance_nameDEST_INSTANCE_NAME]
- [--private_ip_addressPRIVATE_IP_ADDRESS]
- [--instance_idINSTANCE_ID][--volume_sizeVOLUME_SIZE]
- [--volume_type{standard,io1,gp2}]
- [--volume_zoneVOLUME_ZONE][--volume_iopsVOLUME_IOPS]
- [--volume_delete_on_termination]
- [--load_balancer_nameLOAD_BALANCER_NAME]
- [--quick]
- examples:
- ./awscli.py--create--regionus-west-1--instance_nameidc1-server2
- --image_idami-30f01234--instance_typet1.micro
- --key_nameidc1-keypair1--security_group_idssg-eaf01234f
- --subnet_idsubnet-6d901234
- ./awscli.py--create--regionus-west-1--instance_nameidc1-server3
- --image_idami-30f01234--instance_typet1.micro
- --key_nameidc1-keypair1--security_group_idssg-eaf01234f
- --subnet_idsubnet-6d901234--volume_size10--volume_typegp2
- --volume_zoneus-west-1a--volume_delete_on_termination
- --load_balancer_nameidc1-elb1--private_ip_address172.16.2.23
- ./awscli.py--clone--regionus-west-1--src_instance_nameidc1-server1
- --dest_instance_nameidc1-server2
- ./awscli.py--clone--regionus-west-1--src_instance_nameidc1-server1
- --dest_instance_nameidc1-server3--private_ip_address172.16.2.23
- ./awscli.py--terminate--regionus-west-1--instance_nameidc1-server3
- ./awscli.py--terminate--regionus-west-1--instance_idi-01234abc
- ./awscli.py--terminate--regionus-west-1--instance_idi-01234abc--quick
- ...
- optionalarguments:
- -h,--helpshowthishelpmessageandexit
- --createcreateinstance
- --clonecloneinstance
- --terminateterminateinstance
- --regionREGION
- --instance_nameINSTANCE_NAME
- --image_idIMAGE_ID
- --instance_typeINSTANCE_TYPE
- --key_nameKEY_NAME
- --security_group_idsSECURITY_GROUP_IDS
- --subnet_idSUBNET_ID
- --src_instance_nameSRC_INSTANCE_NAME
- --dest_instance_nameDEST_INSTANCE_NAME
- --private_ip_addressPRIVATE_IP_ADDRESS
- --instance_idINSTANCE_ID
- --volume_sizeVOLUME_SIZE
- inGiB
- --volume_type{standard,io1,gp2}
- --volume_zoneVOLUME_ZONE
- --volume_iopsVOLUME_IOPS
- --volume_delete_on_termination
- deletevolumesontermination
- --load_balancer_nameLOAD_BALANCER_NAME
- --quicknowaitontermination
- $./awscli.py--create--regionus-west-1--instance_nameidc1-server1--image_idami-30f01234
- --instance_typet1.micro--key_nameidc1-keypair1--security_group_idssg-eaf01234f
- --subnet_idsubnet-6d901234--volume_size10--volume_typegp2--volume_zoneus-west-1a
- --volume_delete_on_termination--load_balancer_nameidc1-elb1--private_ip_address172.16.2.21
- 1.Launchinginstance:idc1-server1
- 2.Creatingtagasinstancename:{"Name":idc1-server1}
- Instancestate:pending
- Instancestate:running
- 3.Creatingsecondaryvolumeforinstance:idc1-server1asgp210G
- Volumestatus:available
- 4.Attachingvolume:vol-4ba6a54ctoinstance:idc1-server1asdevice:/dev/sdf
- 5.Addinginstance:idc1-server1toELB:idc1-elb1
- $./awscli.py--clone--regionus-west-1--src_instance_nameidc1-server1--dest_instance_nameidc1-server2
- 1.Launchinginstance:idc1-server2
- 2.Creatingtagasinstancename:{"Name":idc1-server2}
- Instancestate:pending
- Instancestate:running
- 3.Creatingsecondaryvolumeforinstance:idc1-server2asgp210G
- Volumestatus:available
- 4.Attachingvolume:vol-5b61635ctoinstance:idc1-server2asdevice:/dev/sdf
- 5.Addinginstance:idc1-server2toELB:idc1-elb1
- $./awscli.py--terminate--regionus-west-1--instance_nameidc1-server2//phpfensi.com
- Terminatinginstance:idc1-server2id:i-86976d62
- Instancestate:shutting-down
- Instancestate:shutting-down
- Instancestate:terminated
热门评论