使用Salt-cloud创建openstack虚拟机

一、云计算发展历程

  • 物理机-多服务
  • 虚拟机-EXSI KVM XEN openvz
  • 虚拟化的管理平台
  • 云计算 私有云 公有云 混合云
  • 容器时代 docker ==> Mesos K8S

二、运维自动化的发展历程

  • 标准化:流程和文档
  • 工具化(基于标准化):shell saltstack ansible puppet、
  • web化(基于工具化):弱化流程,更强的管理和日志记录
  • 服务化:对外提供API
  • 智能化:实现自动化扩容
  • 产品化(个人观点):公有云服务,产品服务化,运维产品即服务

三、Saltstack的云管理

3.1学习salt-cloud

saltstack提供了salt-cloud组件,用来管理公有云和私有云aws,Gogrid,openstack,Aliyun,惠普云,LXC

3.2使用salt-cloud创建openstack虚拟机实战

安装saltstack和依赖包

  1. [root@linux-node1 ~]# yum install salt-master salt-minion salt-cloud
  2. [root@linux-node1 ~]# yum install -y python-libcloud

创建配置文件链接openstack,一定注意yum的空格

  1. [root@linux-node1 cloud.providers.d]# cd /etc/salt/cloud.providers.d/ #配置文件路径
  2. [root@linux-node1 cloud.providers.d]# cat openstack.conf
  3. my-openstack-config:
  4. # Set the location of the salt-master
  5. #
  6. minion:
  7. master: 192.168.56.11 #master的地址
  8. # Configure the OpenStack driver
  9. #
  10. identity_url: http://192.168.56.11:5000/v2.0/tokens
  11. compute_name: nova #计算节点
  12. protocol: ipv4
  13. compute_region: RegionOne ##通过nova endpoint-list查看,设置区域
  14. # Configure Openstack authentication credentials
  15. #
  16. user: demo #用户
  17. password: demo #密码
  18. # tenant is the project name
  19. tenant: demo #项目
  20. provider: openstack ##提供者
  21. # skip SSL certificate validation (default false)
  22. insecure: false #不适用ssl

使用salt-cloud查看openstack的镜像

  1. [root@linux-node1 cloud.providers.d]# salt-cloud --list-images openstack
  2. [INFO ] salt-cloud starting
  3. [WARNING ] /usr/lib/python2.7/site-packages/novaclient/v1_1/__init__.py:30: UserWarning: Module novaclient.v1_1 is deprecated (taken as a basis for novaclient.v2). The preferable way to get client class or object you can find in novaclient.client module.
  4. warnings.warn("Module novaclient.v1_1 is deprecated (taken as a basis for "
  5. my-openstack-config:
  6. ----------
  7. openstack:
  8. ----------
  9. chuck:
  10. ----------
  11. driver:
  12. extra:
  13. ----------
  14. created:
  15. 2015-12-25T09:08:11Z
  16. metadata:
  17. ----------
  18. minDisk:
  19. 0
  20. minRam:
  21. 0
  22. progress:
  23. 100
  24. serverId:
  25. None
  26. status:
  27. ACTIVE
  28. updated:
  29. 2015-12-25T09:10:19Z
  30. get_uuid:
  31. id:
  32. 858f547c-5801-4987-9aa4-ecd39fac3a12
  33. name:
  34. chuck
  35. uuid:
  36. 05001c00324dbbc9901d0950543e5f2997c08967
  37. cirros:
  38. ----------
  39. driver:
  40. extra:
  41. ----------
  42. created:
  43. 2015-12-16T18:16:46Z
  44. metadata:
  45. ----------
  46. minDisk:
  47. 0
  48. minRam:
  49. 0
  50. progress:
  51. 100
  52. serverId:
  53. None
  54. status:
  55. ACTIVE
  56. updated:
  57. 2015-12-16T18:16:47Z
  58. get_uuid:
  59. id:
  60. 4b36361f-1946-4026-b0cb-0f7073d48ade
  61. name:
  62. cirros
  63. uuid:
  64. a3de8ee4adc4a4555c430b2eaabf8ef15be7e243

查看所创建虚拟机的类型type

  1. [root@linux-node1 cloud.providers.d]# salt-cloud --list-sizes openstack
  2. [INFO ] salt-cloud starting
  3. [WARNING ] /usr/lib/python2.7/site-packages/novaclient/v1_1/__init__.py:30: UserWarning: Module novaclient.v1_1 is deprecated (taken as a basis for novaclient.v2). The preferable way to get client class or object you can find in novaclient.client module.
  4. warnings.warn("Module novaclient.v1_1 is deprecated (taken as a basis for "
  5. my-openstack-config:
  6. ----------
  7. openstack:
  8. ----------
  9. m1.large:
  10. ----------
  11. bandwidth:
  12. None
  13. disk:
  14. 80
  15. driver:
  16. ephemeral_disk:
  17. 0
  18. extra:
  19. ----------
  20. get_uuid:
  21. id:
  22. 4
  23. name:
  24. m1.large
  25. price:
  26. 0.0
  27. ram:
  28. 8192
  29. swap:
  30. uuid:
  31. b8122b232b105e228f1fd46488a6f731c877063c
  32. vcpus:
  33. 4
  34. m1.medium:
  35. ----------
  36. bandwidth:
  37. None
  38. disk:
  39. 40
  40. driver:
  41. ephemeral_disk:
  42. 0
  43. extra:
  44. ----------
  45. get_uuid:
  46. id:
  47. 3
  48. name:
  49. m1.medium
  50. price:
  51. 0.0
  52. ram:
  53. 4096
  54. swap:
  55. uuid:
  56. 916b53726166c76dc51eeccd7ffc79a337a912bc
  57. vcpus:
  58. 2
  59. m1.small:
  60. ----------
  61. bandwidth:
  62. None
  63. disk:
  64. 20
  65. driver:
  66. ephemeral_disk:
  67. 0
  68. extra:
  69. ----------
  70. get_uuid:
  71. id:
  72. 2
  73. name:
  74. m1.small
  75. price:
  76. 0.0
  77. ram:
  78. 2048
  79. swap:
  80. uuid:
  81. 4fdfc2dbc25fe8e7d640be69eb5e201382996d62
  82. vcpus:
  83. 1
  84. m1.tiny:
  85. ----------
  86. bandwidth:
  87. None
  88. disk:
  89. 1
  90. driver:
  91. ephemeral_disk:
  92. 0
  93. extra:
  94. ----------
  95. get_uuid:
  96. id:
  97. 1
  98. name:
  99. m1.tiny
  100. price:
  101. 0.0
  102. ram:
  103. 512
  104. swap:
  105. uuid:
  106. f5da21ccdbfb518f60bff3a43fe998d14a550e87
  107. vcpus:
  108. 1
  109. m1.xlarge:
  110. ----------
  111. bandwidth:
  112. None
  113. disk:
  114. 160
  115. driver:
  116. ephemeral_disk:
  117. 0
  118. extra:
  119. ----------
  120. get_uuid:
  121. id:
  122. 5
  123. name:
  124. m1.xlarge
  125. price:
  126. 0.0
  127. ram:
  128. 16384
  129. swap:
  130. uuid:
  131. 8f0083f719dbc84a16323b7ad37ef6d0f240dba9
  132. vcpus:
  133. 8

创建一个profile,用来创建虚拟机

  1. [root@linux-node1 cloud.profiles.d]# pwd
  2. /etc/salt/cloud.profiles.d
  3. [root@linux-node1 cloud.profiles.d]# cat web.conf
  4. web-node: #ID声明
  5. provider: my-openstack-config #前面的openstack.conf中定义好的
  6. size: m1.tiny #type大小
  7. image: cirros #镜像名称
  8. ssh_key_file: /root/.ssh/id_rsa #私钥文件地址
  9. ssh_key_name: mykey #key的名称,以前就存在的
  10. ssh_interface: private_ips #浮动ip
  11. networks:
  12. - fixed:
  13. - 7a3c7391-cea7-47eb-a0ef-f7b18010c984 #网络id(可以通过openstack network list查看)
  14. minion: #虚拟机自动生成minion
  15. master: 192.168.56.11 #生成的minion对应的master
  16. grains: #设置一个grains
  17. role: webserver #设置一个grains的role

开始使用salt-cloud创建虚拟机,-p指定profile文件,web-node是声明ID即provider salt-cloud-node1是新创建虚拟机的名称 debulg长格式查看debug

  1. [root@linux-node1 cloud.profiles.d]# salt-cloud -p web-node salt-cloud-node1 -l debug

在dashboard上查看刚才创建的虚拟机

链接到虚拟机中

  1. [root@linux-node1 cloud.profiles.d]# ssh -i ~/.ssh/cirros@192.168.56.113
  2. id_rsa id_rsa.pub known_hosts
  3. [root@linux-node1 cloud.profiles.d]# ssh -i ~/.ssh/id_rsa cirros@192.168.56.113
  4. The authenticity of host '192.168.56.113 (192.168.56.113)' can't be established.
  5. RSA key fingerprint is b1:9e:bc:6e:da:4d:10:9f:8e:d0:ba:e8:f8:91:49:ae.
  6. Are you sure you want to continue connecting (yes/no)? yes
  7. Warning: Permanently added '192.168.56.113' (RSA) to the list of known hosts.
  8. $ ip a
  9. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
  10. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  11. inet 127.0.0.1/8 scope host lo
  12. inet6 ::1/128 scope host
  13. valid_lft forever preferred_lft forever
  14. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
  15. link/ether fa:16:3e:ab:24:a8 brd ff:ff:ff:ff:ff:ff
  16. inet 192.168.56.113/24 brd 192.168.56.255 scope global eth0
  17. inet6 fe80::f816:3eff:feab:24a8/64 scope link
  18. valid_lft forever preferred_lft forever

通过salt-key可以看到新的虚拟机已经加入到master中

到此为止,技术,后续会有基于saltstack创建docker容器的博文,多谢关注!

0
未经许可,不得转载,否则将受到作者追究,博主联系方式见首页右上角

该文章由 发布

这货来去如风,什么鬼都没留下!!!
发表我的评论
取消评论
代码 贴图 加粗 链接 删除线 签到