北京SEO

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页面默认没有采用宽屏模式,如果觉得下面的代码不太美观,可以点击右上角的“<>”切换到宽屏模式,代码如下:

  1. $./awscli.py-h
  2. usage:awscli.py[-h](--create|--clone|--terminate)--regionREGION
  3. [--instance_nameINSTANCE_NAME][--image_idIMAGE_ID]
  4. [--instance_typeINSTANCE_TYPE][--key_nameKEY_NAME]
  5. [--security_group_idsSECURITY_GROUP_IDS]
  6. [--subnet_idSUBNET_ID]
  7. [--src_instance_nameSRC_INSTANCE_NAME]
  8. [--dest_instance_nameDEST_INSTANCE_NAME]
  9. [--private_ip_addressPRIVATE_IP_ADDRESS]
  10. [--instance_idINSTANCE_ID][--volume_sizeVOLUME_SIZE]
  11. [--volume_type{standard,io1,gp2}]
  12. [--volume_zoneVOLUME_ZONE][--volume_iopsVOLUME_IOPS]
  13. [--volume_delete_on_termination]
  14. [--load_balancer_nameLOAD_BALANCER_NAME]
  15. [--quick]
  16. examples:
  17. ./awscli.py--create--regionus-west-1--instance_nameidc1-server2
  18. --image_idami-30f01234--instance_typet1.micro
  19. --key_nameidc1-keypair1--security_group_idssg-eaf01234f
  20. --subnet_idsubnet-6d901234
  21. ./awscli.py--create--regionus-west-1--instance_nameidc1-server3
  22. --image_idami-30f01234--instance_typet1.micro
  23. --key_nameidc1-keypair1--security_group_idssg-eaf01234f
  24. --subnet_idsubnet-6d901234--volume_size10--volume_typegp2
  25. --volume_zoneus-west-1a--volume_delete_on_termination
  26. --load_balancer_nameidc1-elb1--private_ip_address172.16.2.23
  27. ./awscli.py--clone--regionus-west-1--src_instance_nameidc1-server1
  28. --dest_instance_nameidc1-server2
  29. ./awscli.py--clone--regionus-west-1--src_instance_nameidc1-server1
  30. --dest_instance_nameidc1-server3--private_ip_address172.16.2.23
  31. ./awscli.py--terminate--regionus-west-1--instance_nameidc1-server3
  32. ./awscli.py--terminate--regionus-west-1--instance_idi-01234abc
  33. ./awscli.py--terminate--regionus-west-1--instance_idi-01234abc--quick
  34. ...
  35. optionalarguments:
  36. -h,--helpshowthishelpmessageandexit
  37. --createcreateinstance
  38. --clonecloneinstance
  39. --terminateterminateinstance
  40. --regionREGION
  41. --instance_nameINSTANCE_NAME
  42. --image_idIMAGE_ID
  43. --instance_typeINSTANCE_TYPE
  44. --key_nameKEY_NAME
  45. --security_group_idsSECURITY_GROUP_IDS
  46. --subnet_idSUBNET_ID
  47. --src_instance_nameSRC_INSTANCE_NAME
  48. --dest_instance_nameDEST_INSTANCE_NAME
  49. --private_ip_addressPRIVATE_IP_ADDRESS
  50. --instance_idINSTANCE_ID
  51. --volume_sizeVOLUME_SIZE
  52. inGiB
  53. --volume_type{standard,io1,gp2}
  54. --volume_zoneVOLUME_ZONE
  55. --volume_iopsVOLUME_IOPS
  56. --volume_delete_on_termination
  57. deletevolumesontermination
  58. --load_balancer_nameLOAD_BALANCER_NAME
  59. --quicknowaitontermination
  60. $./awscli.py--create--regionus-west-1--instance_nameidc1-server1--image_idami-30f01234
  61. --instance_typet1.micro--key_nameidc1-keypair1--security_group_idssg-eaf01234f
  62. --subnet_idsubnet-6d901234--volume_size10--volume_typegp2--volume_zoneus-west-1a
  63. --volume_delete_on_termination--load_balancer_nameidc1-elb1--private_ip_address172.16.2.21
  64. 1.Launchinginstance:idc1-server1
  65. 2.Creatingtagasinstancename:{"Name":idc1-server1}
  66. Instancestate:pending
  67. Instancestate:running
  68. 3.Creatingsecondaryvolumeforinstance:idc1-server1asgp210G
  69. Volumestatus:available
  70. 4.Attachingvolume:vol-4ba6a54ctoinstance:idc1-server1asdevice:/dev/sdf
  71. 5.Addinginstance:idc1-server1toELB:idc1-elb1
  72. $./awscli.py--clone--regionus-west-1--src_instance_nameidc1-server1--dest_instance_nameidc1-server2
  73. 1.Launchinginstance:idc1-server2
  74. 2.Creatingtagasinstancename:{"Name":idc1-server2}
  75. Instancestate:pending
  76. Instancestate:running
  77. 3.Creatingsecondaryvolumeforinstance:idc1-server2asgp210G
  78. Volumestatus:available
  79. 4.Attachingvolume:vol-5b61635ctoinstance:idc1-server2asdevice:/dev/sdf
  80. 5.Addinginstance:idc1-server2toELB:idc1-elb1
  81. $./awscli.py--terminate--regionus-west-1--instance_nameidc1-server2//phpfensi.com
  82. Terminatinginstance:idc1-server2id:i-86976d62
  83. Instancestate:shutting-down
  84. Instancestate:shutting-down
  85. Instancestate:terminated

广告内容

centos6中AWS自动化运维脚本分享 centos6中AWS自动化运维脚本分享 centos6中AWS自动化运维脚本分享

相关阅读

热门评论

木木老贼 木木老贼

互联网营销达人~

总篇数181

精选文章

RMAN中catalog和nocatalog区别介绍 小技巧:为Linux下的文件分配多个权限 zimbra8.5.1安装第三方签名ssl证书的步骤 解决mysql不能远程连接数据库方法 windows服务器mysql增量备份批处理数据库 mysql中slow query log慢日志查询分析 JavaScript跨域问题总结 Linux下负载均衡软件LVS配置(VS/DR)教程 mysql中权限参数说明 MYSQL(错误1053)无法正常启动

SEO最新算法