Heat入门第一步 「爱情、让人受尽委屈。」 2022-07-13 03:59 234阅读 0赞 Heat 类似于AWS的CloudFormation, 是OpenStack Orchestration进程的一个项目,OpenStack Orchestration旨在创建一个人性化的服务去管理整个云架构,服务和应用的生命周期。heat实现了一种自动化的通过简单定义和配置就能实现的云部署方式。可以在heat模板中定义连串相关任务(例如用某配置开几台虚拟机,然后再去在其中一台中安装一个mysql服务,设定相关数据库属性,然后再配置几台虚拟机安装web服务集群等等),然后交由heat,由heat按照一定的顺序执行heat模板中定义的一连串任务。利用heat还可以连接到neutron来帮助编排负载均衡和其他网络功能。 学习heat主要学习heat的template,heat的template描述了所用的所有组件资源以及组件资源之间的关系。 这些资源包括:servers,floating ips, volumes, security groups, users and others. Heat管理这些组件的生命周期,当你需要对现在的部署做一些修改的时候,你只需要对template做一些修改即可。Heat还可以与其他软件管理工具集成比如Puppet以及chef。 安装Heat 选择一个VM镜像,可以选择 [http://cloud.fedoraproject.org/fedora-20.x86\_64.qcow2F20][http_cloud.fedoraproject.org_fedora-20.x86_64.qcow2F20] ,它包含了heat-cfntools包,当运行./stack.sh的时候Heat将会被加载到screen中前缀是h-. 假如需要使用Ceilometer Alarms功能你需要添加Ceilometer功能。需要做的是在devstack的localrc文件中添加如下: 1. CEILOMETER\_BACKEND=mysql 2. enable\_service ceilometer-acompute ceilometer-acentral ceilometer-collector ceilometer-api 3. enable\_service ceilometer-alarm-notifier ceilometer-alarm-evaluator 4. \#sudo apt-get install gitgit-review ctags 复制代码 首先下载devstack \#git clone [https://github.com/openstack-dev/devstack.git][https_github.com_openstack-dev_devstack.git] 然后准备localrc如下,灵活选择你感兴趣的项目,做减法处理。注意假如你的环境在proxy后面,而proxy又不支持git时,可以将stackrc中的GIT\_BASE=$\{GIT\_BASE:-git://git.openstack.org\}改为GIT\_BASE=$\{GIT\_BASE:- [https://github.com][https_github.com] \} 1. \#The localrc is used to deploy a Neutron+OVS+heat+ceilometer+tempest development env 2. \#OFFLINE True if no need to pull necessary packages again 3. \#OFFLINE=True 4. \#RECLONE True if all need a fresh repo environment 5. \#RECLONE=True 6. ADMIN\_PASSWORD=123 7. MYSQL\_PASSWORD=123 8. RABBIT\_PASSWORD=123 9. SERVICE\_PASSWORD=123 10. SERVICE\_TOKEN=123 11. Q\_PLUGIN=openvswitch 12. disable\_service n-net 13. \#enable necessary network comps 14. ENABLED\_SERVICES+=,neutron,q-svc,q-agt,q-dhcp,q-l3,q-meta 15. \#enable advanced services 16. enable\_service q-vpn q-lbaas q-fwaas 17. \#enable tempest for learning tempest 18. enable\_service tempest 19. \#enable heat 20. enable\_service heat h-api h-api-cfn h-api-cw h-eng 21. \#enable ceilometer for Ceilometer Alarms 22. CEILOMETER\_BACKEND=mysql 23. enable\_service ceilometer-acompute ceilometer-acentral ceilometer-collector ceilometer-anotification 24. enable\_service ceilometer-api 25. enable\_service ceilometer-alarm-notifier ceilometer-alarm-evaluator 26. 27. HOST\_IP=<Host-IP> 28. \#VM images 29. IMAGE\_URLS="http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-i386-uec.tar.gz" 30. \#IMAGE\_URLS+=",http://uec-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img" 31. IMAGE\_URLS+=",http://cloud.fedoraproject.org/fedora-20.x86\_64.qcow2" 32. 33. http\_proxy=<http-proxy> 34. https\_proxy=<https-proxy> 35. no\_proxy=localhost,<Host-IP> 36. 37. \#for IPSec VPNaaS 38. IPSEC\_PACKAGE=openswan 39. 40. \#LOG configure 41. SCREEN\_LOGDIR=/opt/stack/screen-logs 42. SYSLOG=True 43. \#DEST=/opt/stack/project 复制代码 一切准备就绪,最好先update&upgrade一下,然后运行./stack.sh 可以部署openstack环境了。 模板 [https://github.com/openstack/heat-templates][https_github.com_openstack_heat-templates] 提供一些templates参考例子来展示heat的一些核心功能。heat目前支持两种模板: 与CloudFormatior兼容的cnf目录下的模板以及自研的在hot目录下的HOT模板。 HOT模板基于YAML来展示,下面仅研究HOT模板。 写一个HOT hello world 模板 hello template file: 1. heat\_template\_version: 2013-05-23 2. 3. description: Simple template to deploy a single compute instance 4. 5. resources: 6. my\_instance: 7. type: OS::Nova::Server 8. properties: 9. key\_name: heat\_key 10. image: cirros-0.3.0-i386-uec 11. flavor: m1.tiny 复制代码 “heat\_template\_version: 2013-05-23” 是必须制定的,标识当前heat的模板版本。Resources是必须的,其中一个resources内必须至少包含一个resource定义,在该例子中的key\_name, image以及flavor都是hardcoded,该问题可以通过input parameters解决。 查找上面模板相关参数的CLI过程如下: 1. \#admin tenant 2. stack@vm:~/devstack$ . openrc admin admin 3. \#create heat\_key keypair 4. stack@vm:~$ nova keypair-add heat\_key 5. \#get available image name 6. stack@vm:~$ nova image-list 7. \#get instance ttype 8. stack@vm:~$ nova flavor-list 复制代码 部署模板的CLI过程如下: 1. \#create stack hello-stack with helo HOT 2. stack@vm:~/hot-files$ heat stack-create -f ./hello hello-stack 3. \#list stack status 4. stack@vm:~/hot-files$ heat stack-list 5. \#show events status of hello-stack 6. stack@vm:~/hot-files$ heat event-list hello-stack 7. \#show status of hello-stack 8. stack@vm:~/hot-files$ heat stack-show hello-stack 复制代码 去硬编码,使模板更加灵活,需要加入parameters属性,这样调用模板时,可以输入相关参数,hello带input的模板如下: 1. heat\_template\_version: 2013-05-23 2. 3. description: Simple template to deploy a single compute instance 4. 5. parameters: 6. key\_name: 7. type: string 8. label: Key Name 9. description: Name of key-pair to be used for compute instance 10. image\_name: 11. type: string 12. label: Image Name 13. description: Image to be used for compute instance 14. instance\_type: 15. type: string 16. label: Instance Type 17. description: Type of instance (flavor) to be used 18. 19. outputs: 20. instance\_ip: 21. description: the ip addresss of the deployed instance\_type 22. value: \{get\_attr: \[my\_instance, first\_address\]\} 23. 24. resources: 25. my\_instance: 26. type: OS::Nova::Server 27. properties: 28. key\_name: \{ get\_param: key\_name \} 29. image: \{ get\_param: image\_name \} 30. flavor: \{ get\_param: instance\_type \} 复制代码 执行如下: 1. stack@vm:~/hot-files$ heat stack-create -f ./hello\_input -P "key\_name=heat\_key;instance\_type=m1.tiny;image\_name=cirros-0.3.0-i386-uec" stack-vm2 2. 3. stack@vm:~/hot-files$ heat stack-list [http_cloud.fedoraproject.org_fedora-20.x86_64.qcow2F20]: http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2F20 [https_github.com_openstack-dev_devstack.git]: https://github.com/openstack-dev/devstack.git [https_github.com]: https://github.com/ [https_github.com_openstack_heat-templates]: https://github.com/openstack/heat-templates
还没有评论,来说两句吧...