作者:张华  发表于:2015-12-19
版权声明:能够随意转载。转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明

(http://blog.csdn.net/quqi99 )

Heat依据配置文件模板(HOT, heat orchestration template)实例化一组符合要求的虚机。也能够在其上相应用软件进行配置与编排。对支持对一个组件部署后的负载均衡进行编排。
Heat 服务包括以下重要的组件:

  • Heat-api组件实现OpenStack天然支持的REST API。该组件通过把API请求经由AMQP传送给Heat engine来处理API请求。
  • Heat-api-cfn组件提供兼容AWS CloudFormation的API。同一时候也会把API请求通过AMQP转发给heat engine。

  • Heat-engine组件提供Heat最基本的协作功能。

Setting up test environment

# bzr branch lp:~openstack-charm-testers/+junk/ipv6

bzr branch lp: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

或者使用devstack部署。localrc文件例如以下:

#OFFLINE=True
DEST=/home/demo
IPSEC_PACKAGE=strongswan
sudo route del -net 10.0.1.0/24 gw 192.168.101.3
sudo apt-get install openvswitch-switch qemu-kvm libvirt-bin
sudo ovs-vsctl -- --may-exist add-br br-phy
sleep 5
sudo ip addr add 172.16.1.1/24 dev br-phy
#sudo ovs-vsctl -- --may-exist add-port br-phy eth0 -- set interface eth0 type=internal
ENABLED_SERVICES=rabbit,mysql,key,g-api,g-reg
ENABLED_SERVICES+=,n-api,n-crt,n-obj,n-cpu,n-cond,n-sch
#ENABLED_SERVICES+=,cinder,c-api,c-vol,c-sch
ENABLED_SERVICES+=,q-svc,q-agt,q-dhcp,q-l3,q-meta,neutron,q-lbaas,q-fwaas,q-vpn

Q_ML2_TENANT_NETWORK_TYPE=flat,vlan,gre,vxlan
OVS_BRIDGE_MAPPINGS=physnet1:br-phy #ENABLED_SERVICES+=,horizon
#ENABLED_SERVICES+=,s-proxy,s-object,s-container,s-account
VOLUME_BACKING_FILE_SIZE=500M
SWIFT_HASH=66a3d6b56c1f479c8b4e70ab5c2000f5
SWIFT_REPLICAS=1
SWIFT_DATA_DIR=/home/demo/data/swift HOST_IP=172.16.1.1
SERVICE_HOST=172.16.1.1
MYSQL_HOST=172.16.1.1
RABBIT_HOST=172.16.1.1
GLANCE_HOSTPORT=172.16.1.1:9292
Q_HOST=172.16.1.1 FIXED_RANGE=10.0.1.0/24
FLOATING_RANGE=192.168.101.0/24
Q_FLOATING_ALLOCATION_POOL=start=192.168.101.3,end=192.168.101.100
PUBLIC_NETWORK_GATEWAY=192.168.101.1
NETWORK_GATEWAY=10.0.1.1
PUBLIC_BRIDGE=br-ex
# sudo ovs-vsctl add-port br-ex eth1
OVS_PHYSICAL_BRIDGE=br-phy DATABASE_USER=root
DATABASE_PASSWORD=password
ADMIN_PASSWORD=password
SERVICE_PASSWORD=password
RABBIT_PASSWORD=password
SERVICE_TOKEN=ADMIN
LOGFILE=/home/demo/logs/stack.log
ENABLE_DEBUG_LOG_LEVEL=False
SYSLOG=False
SCREEN_LOGDIR=/home/demo/logs
LOG_COLOR=False
Q_USE_DEBUG_COMMAND=False
APACHE_ENABLED_SERVICES+=keystone
KEYSTONE_TOKEN_FORMAT=UUID
USE_SSL=False
disable_service tls-proxy ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng
CIRROS_VERSION=0.3.4

使用Heat进行部署

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文件。大概是须要完毕以下的工作

  1. 创建一个私有网络
  2. 创建一个路由器
  3. 连接好外部网络和内部网络
  4. 创建两个虚拟机,绑定floating ip

Heat眼下支持两种格式的模板。一种是基于JSON格式的CFN模板;第二种是基于YAML格式的HOT模板。CFN模板主要是为了保持对AWS的兼容性。HOT模板是Heat自有的。资源类型更加丰富。更能体现出Heat特点的模板。一个典型的 HOT 模板由下列元素构成:

  • 模板版本号:必填字段,指定所相应的模板版本号,Heat 会依据版本号进行检验。

  • 參数列表:选填,指输入參数列表。
  • 资源列表:必填,指生成的 Stack 所包括的各种资源。能够定义资源间的依赖关系,比方说生成Port。然后再用port来生成VM。
  • 输出列表:选填,指生成的 Stack 暴露出来的信息,能够用来给用户使用。也能够用来作为输入提供给其他的 Stack。

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 提供了多种资源类型来支持对于软件配置和部署的编排,例如以下所列:

  • OS::Heat::CloudConfig: VM引导程序启动时的配置。由 OS::Nova::Server 引用
  • OS::Heat::SoftwareConfig:描写叙述软件配置
  • OS::Heat::SoftwareDeployment:运行软件部署
  • OS::Heat::SoftwareDeploymentGroup:对一组 VM 运行软件部署
  • OS::Heat::SoftwareComponent:针对软件的不同生命周期部分。相应描写叙述软件配置
  • OS::Heat::StructuredConfig:和 OS::Heat::SoftwareConfig 相似。可是用 Map 来表述配置
  • OS::Heat::StructuredDeployment:运行 OS::Heat::StructuredConfig 相应的配置
  • OS::Heat::StructuredDeploymentsGroup:对一组 VM 运行 OS::Heat::StructuredConfig 相应的配置

Heat 对负载均衡的编排

负载均衡也是一个非常高级应用,它也是由一组不同的资源类型来实现的。资源类型包括:

  • OS::Neutron::Pool:定义资源池,一般能够由 VM 组成
  • OS::Neutron::PoolMember:定义资源池的成员
  • OS::Neutron::HealthMonitor:定义健康监视器,依据自定的协议,比方 TCP 来监控资源的状态,并提供给 OS::Neutron::Pool 来调整请求分发
  • OS::Neutron::LoadBalancer:关联资源池以定义整个负载均衡。

Heat对资源自己主动伸缩的编排
基础架构的自己主动伸缩是一个非常高级的功能。Heat 提供自己主动伸缩组 OS::Heat::AutoScalingGroup 和伸缩策略 OS::Heat::ScalingPolicy。结合基于 Ceilometer 的 OS::Ceilometer::Alarm 实现了能够依据各种条件,比方负载,进行资源自己主动伸缩的功能。

怎样使用Cirros作为样例镜像

Since cirros images don't currently support multi-part mime user-data, it's necessary to inject the hook script to the image and upload the modified image to glance:

https://github.com/openstack/heat-templates/tree/master/hot/software-config/example-templates/cirros-example
wget http://download.cirros-cloud.net/0.3.2/cirros-0.3.2-x86_64-disk.img
virt-copy-in -a cirros-0.3.2-x86_64-disk.img init.d/heat-deploy-hook /etc/init.d
virt-copy-in -a cirros-0.3.2-x86_64-disk.img rc3.d/S99-heat-deploy-hook /etc/rc3.d
glance image-create --name cirros-0.3.2-sc --disk-format=qcow2 --container-format=bare < cirros-0.3.2-x86_64-disk.img
heat stack-create sc1 -f cirros-hello-world.yaml -P "image=cirros-0.3.2-sc"

或者用cirros 0.3.3:

glance image-create --name "Cirros 0.3.3" --disk-format qcow2 --container-format bare --is-public True --copy http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img
nova flavor-create m1.nano 42 64 0 1

或者在devstack中直接指定cirros的版本号

CIRROS_VERSION=0.3.4

參考

How to test Heat (by quqi99)的更多相关文章

  1. What's VPC (by quqi99)

    作者:张华  发表于:2014-12-09版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) VPC ...

  2. openstack-kilo--issue(九) heat stacks topology中图形无法正常显示

    ======声明======= 欢迎转载:转载请注明出处 http://www.cnblogs.com/horizonli/p/6186581.html ==========环境=========== ...

  3. 网格测地线算法(Geodesics in Heat)附源码

    测地线又称为大地线,可以定义为空间曲面上两点的局部最短路径.测地线具有广泛的应用,例如在工业上测地线最短的性质就意味着最优最省,在航海和航空中,轮船和飞机的运行路线就是测地线.[Crane et al ...

  4. openStack Use Orchestration module(heat) create and manage cloud resources

  5. BZOJ 3408: [Usaco2009 Oct]Heat Wave 热浪( 最短路 )

    普通的最短路...dijkstra水过.. ------------------------------------------------------------------------------ ...

  6. 比較Swift与HDFS话Ceph本质(by quqi99)

    作者:张华  发表于:2014-06-21版权声明:能够随意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 (http://blog.csdn.net/quqi99 ) 作者将又 ...

  7. 3408: [Usaco2009 Oct]Heat Wave 热浪

    3408: [Usaco2009 Oct]Heat Wave 热浪 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 55[Subm ...

  8. [USACO09OCT]热浪Heat Wave

    未经同意,不得转载. The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make ...

  9. [最短路]P1339 [USACO09OCT]热浪Heat Wave

    题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for g ...

随机推荐

  1. js 监听ios手机键盘弹起和收起的事件

    document.body.addEventListener('focusin', () => { //软键盘弹起事件 console.log("键盘弹起") }) docu ...

  2. vue v-if的使用

    代码部分 <el-row> <el-col :span="20"> <template v-for="(node,i) of hierarc ...

  3. git远程仓库变更

    查看自己的远程仓库 git remote -v 远程仓库变更 git remote remove origin //移出现有的远程仓库的地址 git remote add origin http:// ...

  4. [agc015c]nuske vs phantom thnook

    题意: 有一个n*m的网格图,每个格子是蓝色或白色.四相邻的两个格子连一条边,保证蓝格子构成一个森林. 有q组询问,每次询问给出一个矩形,问矩形内蓝格子组成的联通块个数. $1\leq n,m\leq ...

  5. 用TamperMonkey去掉cdsn中的广告

    最近CSDN需要登录后才能查看更多内容,有点影响心情 解决方案 添加一段书签 javascript:(function(){document.getElementById('article_conte ...

  6. [CTSC2016]单调上升路径

    题目:UOJ#201. 题目大意:给定n个点(n是偶数)的完全图,现在要你给每条边确定一个权值(互不相等),使得最长的单调上升路径最短.现在要你输出边的权值. 一条路径被称为单调上升的,如果沿着它走时 ...

  7. C实现JAVA类似ArrayList的静态链接库

    文件结构: ArrayList.h:头文件 ArrayList.c:实现头文件中的功能 ArrayListTest.c:测试 ArrayList.h 头文件的基本框架: #ifndef _ARRAYL ...

  8. Object-C学习比较费劲的3点原因

    作为一名有8年编程经验的资历不浅的程序员,学习Object-C和iOS,感觉效率有点低,至少和学习Android比起来,慢的不是一点点. 主要有以下3个原因: 1.Object-C,和C系列的语言(C ...

  9. CI框架源代码阅读笔记2 一切的入口 index.php

    上一节(CI框架源代码阅读笔记1 - 环境准备.基本术语和框架流程)中,我们提到了CI框架的基本流程.这里再次贴出流程图.以备參考: 作为CI框架的入口文件.源代码阅读,自然由此開始. 在源代码阅读的 ...

  10. Experience Design for Sexable Forum

    Mars March 16, 2015