(http://blog.csdn.net/quqi99 )
Heat根据配置文件模板(HOT, heat orchestration template)实例化一组符合要求的虚机。也能够在其上对应用软件进行配置与编排。对支持对一个组件部署后的负载均衡进行编排。
Heat 服务包含以下重要的组件:
# bzr branch lp:~openstack-charmers/+junk/openstack-charm-testing
juju destroy-environment --force zhhuabj
juju switch zhhuabj && juju bootstrap
juju-deployer -c ./next.yaml -d trusty-kilo
juju add-unit neutron-gateway
#juju set neutron-api overlay-network-type=vxlan
#juju set neutron-api l2-population=false enable-l3ha=true
./configure #edit script to use vxlan
source ./novarc
neutron net-list && neutron router-list
nova boot --image trusty --nic net-id=98e10e32-13eb-48ee-b265-4ae0e449b6e5 --flavor 2 i1
nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
nova floating-ip-create
nova floating-ip-associate i1 10.5.150.1
heat_template_version: 2013-05-23
description: HOT template for two interconnected VMs with floating ips.
parameters:
image_id:
type: string
description: Image Name
secgroup_id:
type: string
description : Id of the security groupe
public_net:
type: string
description: public network id
resources:
private_net:
type: OS::Neutron::Net
properties:
name: private-net
private_subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: private_net }
cidr: 172.16.2.0/24
gateway_ip: 172.16.2.1
router1:
type: OS::Neutron::Router
properties:
external_gateway_info:
network: { get_param: public_net }
router1_interface:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: router1 }
subnet_id: { get_resource: private_subnet }
server1_port:
type: OS::Neutron::Port
properties:
network_id: { get_resource: private_net }
security_groups: [ get_param: secgroup_id ]
fixed_ips:
- subnet_id: { get_resource: private_subnet }
server1_floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net }
port_id: { get_resource: server1_port }
server1:
type: OS::Nova::Server
properties:
name: Server1
image: { get_param: image_id }
flavor: m1.tiny
networks:
- port: { get_resource: server1_port }
server2_port:
type: OS::Neutron::Port
properties:
network_id: { get_resource: private_net }
security_groups: [ get_param: secgroup_id ]
fixed_ips:
- subnet_id: { get_resource: private_subnet }
server2_floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net }
port_id: { get_resource: server2_port }
server2:
type: OS::Nova::Server
properties:
name: Server2
image: { get_param: image_id }
flavor: m1.tiny
networks:
- port: { get_resource: server2_port }
outputs:
server1_private_ip:
description: Private IP address of server1
value: { get_attr: [ server1, first_address ] }
server1_public_ip:
description: Floating IP address of server1
value: { get_attr: [ server1_floating_ip, floating_ip_address ] }
server2_private_ip:
description: Private IP address of server2
value: { get_attr: [ server2, first_address ] }
server2_public_ip:
description: Floating IP address of server2
value: { get_attr: [ server2_floating_ip, floating_ip_address ] }
这个ymal文件,大概是需要完成下面的工作
Heat目前支持两种格式的模板,一种是基于JSON格式的CFN模板;另外一种是基于YAML格式的HOT模板。CFN模板主要是为了保持对AWS的兼容性。HOT模板是Heat自有的,资源类型更加丰富,更能体现出Heat特点的模板。一个典型的 HOT 模板由下列元素构成:
NET_ID=$(nova net-list | awk '/ ext_net / { print $2 }')
SEC_ID=$(nova secgroup-list | awk '/ default / { print $2 }')
heat stack-create -f first-stack.yml -P image_id=cirros -P public_net=$NET_ID -P secgroup_id=$SEC_ID First_Stack
ubuntu@zhhuabj-bastion:~/openstack-charm-testing$ heat stack-list
+--------------------------------------+-------------+-----------------+----------------------+
| id | stack_name | stack_status | creation_time |
+--------------------------------------+-------------+-----------------+----------------------+
| b36bdf67-bd59-401d-ab3b-f7437aa06c30 | First_Stack | CREATE_COMPLETE | 2015-12-19T10:18:49Z |
+--------------------------------------+-------------+-----------------+----------------------+
ubuntu@zhhuabj-bastion:~/openstack-charm-testing$ nova list
+--------------------------------------+---------+--------+------------+-------------+------------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+---------+--------+------------+-------------+------------------------------------+
| 901d5365-01b6-4254-a65f-5177d804d074 | Server1 | ACTIVE | - | Running | private-net=172.16.2.3, 10.5.150.4 |
| f1441f2d-4fb2-4560-b0ff-85d0cde4bc45 | Server2 | ACTIVE | - | Running | private-net=172.16.2.4, 10.5.150.3 |
ubuntu@juju-zhhuabj-machine-7:~$ ps -ef|grep heat
root 3656 1 0 Dec08 ? 00:05:40 /var/lib/juju/tools/unit-heat-0/jujud unit --data-dir /var/lib/juju --unit-name heat/0 --debug
heat 20395 1 0 Dec08 ? 00:00:10 /usr/bin/python /usr/bin/heat-api --config-file=/etc/heat/heat.conf --log-file=/var/log/heat/heat-api.log
heat 20414 1 0 Dec08 ? 00:00:10 /usr/bin/python /usr/bin/heat-api-cfn --config-file=/etc/heat/heat.conf --log-file=/var/log/heat/heat-api-cfn.log
heat 20437 1 0 Dec08 ? 00:19:54 /usr/bin/python /usr/bin/heat-engine --config-file=/etc/heat/heat.conf --log-file=/var/log/heat/heat-engine.log
Heat 提供了多种资源类型来支持对于软件配置和部署的编排,如下所列:
负载均衡也是一个很高级应用,它也是由一组不同的资源类型来实现的。资源类型包括:
Heat对资源自动伸缩的编排
基础架构的自动伸缩是一个很高级的功能。Heat 提供自动伸缩组 OS::Heat::AutoScalingGroup 和伸缩策略 OS::Heat::ScalingPolicy,结合基于 Ceilometer 的 OS::Ceilometer::Alarm 实现了可以根据各种条件,比如负载,进行资源自动伸缩的功能。
http://docs.openstack.org/developer/heat/template_guide/index.html
http://www.ibm.com/developerworks/cn/cloud/library/1511_zoupx_openstackheat/index.htm