OpenStack高级控制服务之使用编配服务(Heat)实现自动化部署云主机

一、编配服务的基本概念 

Heat是一个基于模板来编排复合云应用的服务。Heat 目前支持两种格式的模板,一种是基于 JSON 格式的 CFN 模板,另外一种是基于 YAML 格式的 HOT 模板。CFN 模板主要是为了保持对 AWS 的兼容性。HOT 模板是Heat 自有的,资源类型更加丰富,更能体现出 Heat 特点的模板。

Heat 服务包含以下重要的组件

1.Heat-api组件实现OpenStack天然支持的 REST API。该组件通过把 API 请求经由 AMQP 传送给 Heat engine 来处理 API 请求。

2.Heat-api-cfn组件提供兼容 AWS CloudFormation的 API,同时也会把 API 请求通过 AMQP 转发给 heat engine。

3.Heat-engine 组件提供 Heat 最主要的协作功能。

一个典型的 HOT 模板由下列元素构成:

模板版本: 必填字段,指定对应的模板版本,Heat 会根据版本进行检验。

资源列表: 必填,指生成的 Stack 所包含的各种资源。可以定义资源间的依赖关系,比如说生成 Port,然后再用 port 来生成 VM。

参数列表: 选填,指输入参数列表

输出列表: 选填,指生成的 Stack 暴露出来的信息,可以用来给用户使用,也可以用来作为输入提供给其它的 Stack。

 Heat Engine 的作用分为三层:

第一层处理 Heat 层面的请求,就是根据模板和输入参数来创建 Stack,这里的 Stack 是由各种资源组合而成。

第二层解析 Stack 里各种资源的依赖关系,Stack 和嵌套 Stack 的关系。

第三层根据解析出来的关系,依次调用各种服务客户端来创建各种资源。

heat模板 

heat_template_version: 2013-05-23  //版本信息
parameters:  //自定义的变量
ImageID:
type: string
resources:  //描述的资源,如网络、实例
  server1:
type: OS::Nova::Server
outputs:  //返回值
  server1_private_ip:
value: { get_attr: [ server1, first_address ] }

二、编配服务编排

编排:按照一定的目的依次排列。

一个完整的编排包括设置服务器上机器、安装 CPU、内存、硬盘、通电、插入网络接口、安装操作系统、配置操作系统、安装中间件、配置中间件、安装应用程序、配置应用发布程序。对于复杂的需要部署在多台服务器上的应用,需要重复这个过程,而且需要协调各个应用模块的配置,下图显示了一个典型应用需要编排的项目。

 heat编排

        Heat:Heat 在这种情况下应运而生,它采用了业界流行的模板方式进行设计和定义编排。用户只需要打开文本编辑器,编写一段基于 Key-Value 的模板,就能够方便地得到想要的编排。为了方便用户的使用,Heat 提供了大量的模板例子,通常用户只需要选择想要的编排,通过拷贝、粘贴的方式来完成模板的编写。

Heat 的编排方式如下:

首先OpenStack自身提供的基础架构资源,包括计算、网络和存储等资源。通过编排这些资源,用户就可以得到最基本的 VM。此外在编排 VM 的过程中,用户可以编写简单脚本,以便对 VM 做些简单的配置。

然后用户可以通过 Heat 提供的 Software Configuration 和 Software Deployment 等对 VM 进行复杂的配置,比如安装软件和配置软件等。

其次当用户有一些高级的功能需求,比如需要一组能够根据负荷自动伸缩的 VM 组,或者一组负载均衡的 VM时,Heat 提供了AutoScaling和 Load Balance等模板进行支持。

三、编配服务heat的运维基础

使用栈模板test-stack.yml创建一个名为Orchestration的栈

# heat stack-create orchestration -f test-stack1.yml --parameters "ImageID=centos6.5;NetID=sharednet1"

查询栈列表

# heat stack-list

查看栈的详细信息

# heat stack-show orchestration

删除栈

# heat stack-delete orchestration

查看栈资源列表

# heat resource-list orchestration

查看栈资源

# heat resource-show orchestration server1

查看输出列表

# heat output-list orchestration

查看输出值

# heat output-show orchestration server1_private_ip

查看事件列表

# heat event-list orchestration

查看资源事件详细信息

# heat event-show orchestration server1 10c307a5-1732-4f10-8b91-d9b23402661d

任务要求:为了使用编配服务实现自动化部署云主机,需要执行三个步骤:

#基于xiandian,首先都需要生效环境变量,获取令牌(source /etc/keystone/admin-openrc.sh)
[root@xiandian ~]# #第一步:获取基础资源信息(如果没有,则需要重新创建),包括认证、镜像、网络、计算、存储等资源,同时还需要设置密钥对和安全组策略
[root@xiandian ~]# #认证服务keystone
[root@xiandian ~]# #需要给cookbook部门的manager启动一台云主机
[root@xiandian ~]# #查看当前的部门信息,即租户列表
[root@xiandian ~]#openstack project list
[root@xiandian ~]# #创建新部门
[root@xiandian ~]#openstack project create cookbook --domain xiandian
[root@xiandian ~]#openstack project list
[root@xiandian ~]#openstack role list
[root@xiandian ~]# #创建新角色
[root@xiandian ~]#openstack role create manager
[root@xiandian ~]#openstack role list
[root@xiandian ~]# #创建新用户cook001
[root@xiandian ~]#openstack user create cook001 --password 000000 --domain xiandian --email cook001@xiandian.com
[root@xiandian ~]#openstack user list
[root@xiandian ~]# #为新用户分配部门,安排角色,就是把三者绑定
[root@xiandian ~]# openstack role add manager --user cook001 --project cookbook
[root@xiandian ~]# #镜像服务glance
[root@xiandian ~]#glance image-list
[root@xiandian ~]# #获取源文件
[root@xiandian ~]#wget ftp://172.16.102.20/cirros-0.3.4-x86_64-disk.img
[root@xiandian ~]# #使用当前源文件创建镜像
[root@xiandian ~]#glance image-create --name cirros50 --disk-format qcow2 --container-format bare --progress<cirros-0.3.4-x86_64-disk.img
[root@xiandian ~]#glance image-list
[root@xiandian ~]#glance image-create --name cirros150 --disk-format vmdk --container-format bare --progress<cirros-0.3.4-x86_64-disk.img
[root@xiandian ~]#glance image-list
[root@xiandian ~]# #设置镜像的最小启动硬盘大小和内存大小
[root@xiandian ~]#glance image-update --min-disk=20 --min-ram=2048 镜像id号
[root@xiandian ~]# #网络服务
[root@xiandian ~]# # 查看当前可用网络
[root@xiandian ~]#neutron net-list
[root@xiandian ~]# #创建子网subnet50
[root@xiandian ~]#neutron subnet-create sharednet1 --name subnet50 --gateway 192.168.50.1 192.168.50.0/24
[root@xiandian ~]#neutron net-list
[root@xiandian ~]#neutron subnet-list
[root@xiandian ~]# #计算服务(确定云主机的主机类型flavor)
[root@xiandian ~]#nova flavor-list
[root@xiandian ~]# #创建自定义主机类型
[root@xiandian ~]#nova flavor-create cook.small 6 4096 60 4 
[root@xiandian ~]#nova flavor-list
[root@xiandian ~]# #生成密钥对keypair
[root@xiandian ~]#nova keypair-list
[root@xiandian ~]#nova keypair-add mykey > mykey
[root@xiandian ~]#nova keypair-list
[root@xiandian ~]# #设置安全组secgroup策略
[root@xiandian ~]#nova secgroup-list
[root@xiandian ~]# #自定义安全组cookbook
[root@xiandian ~]#nova secgroup-create cookbook-rules 'create a secgroup for cookbook'
[root@xiandian ~]# #为安全组添加规则
[root@xiandian ~]#nova secgroup-add-rule cookbook-rules ICMP -1 -1 0.0.0.0/0
[root@xiandian ~]#nova secgroup-add-rule cookbook-rules UDP 83 83 192.168.50.0/24
[root@xiandian ~]#nova secgroup-list-rules cookbook-rules
[root@xiandian ~]# #第二步:编写编配脚本文件test50.yml
[root@xiandian ~]#vi test50.yml    #见图一
[root@xiandian ~]#chmod -X test50.yml
[root@xiandian ~]# #第三步:使用test50.yml这个文件创建栈资源,启动云主机
[root@xiandian ~]#heat stack-create test50-1 -f test50.yml
[root@xiandian ~]# #查看栈列表
[root@xiandian ~]#heat stack-list
[root@xiandian ~]#nova list
[root@xiandian ~]#heat stack-create test50-2 -f test50.yml
[root@xiandian ~]# #编写完整地heat模板文件
[root@xiandian ~]#vi test50-3.yml   #见图二
[root@xiandian ~]#heat stack-create test50-3 -f test50-3.yml --parameterts " Name=myinstance;Image=cirros50"
[root@xiandian ~]#heat stack-list

 图一:

图二:

 不谙世事 步履阑珊 

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值