Openstack Heat 实验
- Get link
- X
- Other Apps
什么是热量?
Heat 是一项使用 AWS CloudFormation 模板格式编排多个复合云应用程序的服务,它是 Openstack 对 CloudFormation 和 CloudWatch 的实现。
Heat将OpenStack的其他核心组件集成到一个文件模板系统中。这些模板允许创建大多数OpenStack资源类型,Heat cover的主要功能:
- vAPP堆栈创建/更新/删除(暂停/恢复将在哈瓦那添加)
- 高可用性
- 自动缩放
- 手动放大/缩小(哈瓦那境内)
如何安装Heat并随时可以使用?
1.安装
->Heat已包含在RDO存储库中,安装可以由Yum完成:
yum install openstack-heat-api openstack-heat-api-cfn openstack-heat-api-cloudwatch \
openstack-heat-cli openstack-heat-common openstack-heat-engine \
python-heatclient python-heatclient-doc heat-cfntools heat-jeos
->注释出以下行,因为我们使用 RabbitMQ 而不是 QPID 作为消息队列。对于 heat-api-cfn.conf、heat-api-cloudwatch.conf、heat-api.conf、heat-engine.conf under /etc/heat,请执行此操作。
#rpc_backend=heat.openstack.common.rpc.impl_qpid
->配置下 /etc/heat 的部分[filter:authtoken]
heat-api-cfn-paste.ini
heat-api-cloudwatch-paste.ini
heat-api-paste.ini
[filter:authtoken]
paste.filter_factory = heat.common.auth_token:filter_factory
service_protocol = http
service_host = api-vip
service_port = 5000
auth_host = api-vip
auth_port = 35357
auth_protocol = http
auth_uri = http://api-vip:35357/v2.0
admin_tenant_name = service
admin_user = heat
admin_password = password
->配置下 /etc/heat 的部分[filter:ec2authtoken]
heat-api-cfn-paste.ini
heat-api-cloudwatch-paste.ini
[filter:ec2authtoken]
paste.filterfactory = heat.api.aws.ec2token:EC2Tokenfilterfactory
authuri = http://api-vip:5000/v2.0
keystoneec2uri = http://api-vip:5000/v2.0/ec2tokens
->更新 /etc/heat/heat-engine.conf 如下所示:
heatmetadataserverurl = http://10.68.125.11:8000
heatwaitconditionserverurl = http://10.68.125.11:8000/v1/waitcondition
heatwatchserverurl = http://10.68.125.11:8003
sqlconnection = mysql://heat:heat@db-vip/heat
元数据、监视条件和watch_server的 IP 应该是正在运行的热服务的主机 IP,并且应该可以从 VM 实例访问。
->设置热数据库:
heat-db-setup rpm -y -r <root password of mysql>
->设置热的基石条目:
heat-keystone-setup
->开始热服务:
service openstack-heat-api start
service openstack-heat-api-cfn start
service openstack-heat-api-cloudwatch start
service openstack-heat-engine start
2.准备JEOS(刚好够操作系统)
JEOS映像是预装了云初始化和热cfn工具的基本操作系统映像,它们是Heat和VM交换信息以及执行后期和常规工作的关键。
Fedora 17 和 18 的预建 JEOS 可以从以下位置下载:http://fedorapeople.org/groups/heat/prebuilt-jeos-images/
要在RHEL上制作我们自己的JEOS,请按照以下步骤操作:
一个。假设我们已经在 Glance 中注册了一个 RHEL 6.3 映像,请从中启动 VM 实例。
(二)登录到 VM,安装 cloud-init 和 heat-cfn-tools
yum -y update
export http_proxy= #This is needed if lab has no direct internet access
curl -O http://ftp.ps.pl/pub/Linux/fedora-epel/6/i386/epel-release-6-7.noarch.rpm
rpm -Uvh epel-release-6-7.noarch.rpm
yum -y install perl python python-setuptools cloud-init python-pip
pip-python install argparse ‘boto==2.5.2’ heat-cfntools
cfn-create-aws-symlinks –source /usr/bin
rm -rf /etc/udev/rules.d/70-persistent-net.rules
c. 从 Horizon GUI 或 CLI 中,为此 VM 创建快照,将其命名为“rhel63-x86_64-cfntools”。此快照实际上成为有效的 JEOS 映像。
使用案例
1.部署一个具有关联浮动IP的WordPress博客服务器。
此模板部署具有关联浮动IP的单个VM实例,然后安装mysql-server,httpd和wordpress包,初始数据库,相互集成,最后启动wordpress Web服务。
->Download the template file
wget https://github.com/abckey/heat-templates/raw/master/WordPress_Single_Instance_With_EIP.template
->Source a tenant credential
source /root/nceprc
->Create a key-pair
nova keypair-add ncepkey > ncepkey.pem
chmod 400 ncepkey.pem
->Deploy this template by heat
heat stack-create wordpress -f WordPress_Single_Instance_With_EIP.template \
-P “InstanceType=m1.medium;DBUsername=wordpress;DBPassword=worldpress;KeyName=ncepkey;LinuxDistribution=RHEL-6.3”
Parameters followed after “-P” are needed for instance type selection, DB access setup, key-pair selection and image selection.
->Check stack creation process
Once the stack-create is issued, we should see the stack in “CREATE_IN_PROGRESS” status from output of “heat list”
Once creation is complete, we can see the status will change to “CREATE_COMPLETE”.
[root@controller-1 heat(keystone_ncep)]# heat list
+————————————–+————–+—————–+———————-+
| ID | Name | Status | Created |
+————————————–+————–+—————–+———————-+
| a6740599-2c98-41b8-a55e-490f28f6f6f8 | wordpress | CREATE_COMPLETE | 2013-08-05T06:57:40Z |
+————————————–+————–+—————–+———————-+
We can also see detailed resource status in the stack by:
[root@controller-1 heat(keystone_ncep)]# heat resource-list wordpress
+————————+————————–+—————–+———————-+
| Name | Type | Status | Updated |
+————————+————————–+—————–+———————-+
| IPAddress | AWS::EC2::EIP | CREATECOMPLETE | 2013-08-05T06:57:40Z |
| WebServerSecurityGroup | AWS::EC2::SecurityGroup | CREATECOMPLETE | 2013-08-05T06:57:41Z |
| IPAssoc | AWS::EC2::EIPAssociation | CREATECOMPLETE | 2013-08-05T06:57:52Z |
| WebServer | AWS::EC2::Instance | CREATECOMPLETE | 2013-08-05T06:57:52Z |
+————————+————————–+—————–+———————-+
Also heat stack-show wordpress can be used to show detailed information of the stack
->Try to access the wordpress web UI
From nova list, we could see a VM named is created with internal IP and floating IP:wordpress.WebServer
[root@controller-1 heat(keystone_ncep)]# nova list
+————————————–+——————————————–+——–+————————————-+
| ID | Name | Status | Networks |
+————————————–+——————————————–+——–+————————————-+|
| 02da7185-a0a6-44cf-8076-875754163dac | wordpress.WebServer | ACTIVE | ncep-net=10.20.20.17, 10.68.124.102 |
+————————————–+——————————————–+——–+————————————-+
Try to access the wordpress website by its floating IP
http://10.68.124.102/wordpress
You should see the login page in the browser!!!
2.Deploy wordpress blog server with 2 VM instances(front-end + back-end topology)
This template deploy a 2 VM wordpress solution, one VM running web server, 2nd VM running Mysql DB.
->Download the template:
wget https://github.com/abckey/heat-templates/raw/master/WordPress_2_Instances.template
->Deploy the template by heat
heat stack-create wp-2-vm -f WordPress_2_Instances.template -P \n
“InstanceType=m1.medium;DBUsername=wordpress;DBPassword=worldpress;KeyName=ncepkey;LinuxDistribution=RHEL-6.3”
->From heat resource-list wp-2-vm, we can see 2 VM instances are created, also a floating IP and association with Webserver is there
[root@controller-1 heat(keystonencep)]# heat resource-list wp-2-vm
+—————-+————————–+—————–+———————-+
| Name | Type | Status | Updated |
+—————-+————————–+—————–+———————-+
| DatabaseServer | AWS::EC2::Instance | CREATECOMPLETE | 2013-08-05T07:14:04Z |
| IPAddress | AWS::EC2::EIP | CREATECOMPLETE | 2013-08-05T07:14:13Z |
| WebServer | AWS::EC2::Instance | CREATECOMPLETE | 2013-08-05T07:14:13Z |
| IPAssoc | AWS::EC2::EIPAssociation | CREATE_COMPLETE | 2013-08-05T07:14:14Z |
+—————-+————————–+—————–+———————-+
->Try wordpress website with floating IP of WebServer VM instance
[root@controller-1 heat(keystone_ncep)]# nova list
+————————————–+——————————————–+——–+————————————-+
| ID | Name | Status | Networks |
+————————————–+——————————————–+——–+————————————-+
| 4879bb03-bc20-4c33-91e2-d4a7e197d2e5 | wp-2-vm.DatabaseServer | ACTIVE | ncep-net=10.20.20.18 |
| 8e1dc2c7-bc34-4e5d-b833-b64dc8a12c9b | wp-2-vm.WebServer | ACTIVE | ncep-net=10.20.20.19, 10.68.124.103 |
+————————————–+——————————————–+——–+————————————-+
http://10.68.124.103/wordpress
3.Deploy a wordpress blog server with EBS volume as mysql DB storage
This template deploy a VM instance with httpd, wordpress and mysql-server installed, a EBS volume is attached to instance as Mysql DB storage point.
->Download the template
wget https://github.com/abckey/heat-templates/raw/master/WordPress_Single_Instance_With_EBS_EIP.template
heat stack-create wp-ebs -f WordPress_Single_Instance_With_EBS_EIP.template -P “VolumeSize=5;InstanceType=m1.medium;DBUsername=wordpress;DBPassword=worldpress;KeyName=ncepkey;LinuxDistribution=RHEL-6.3”
[root@controller-1 heat(keystone_ncep)]# heat resource-list wp-ebs
+————————-+—————————-+—————–+———————-+
| Name | Type | Status | Updated |
+————————-+—————————-+—————–+———————-+
| DataVolume | AWS::EC2::Volume | CREATE_COMPLETE | 2013-08-05T07:35:48Z |
| WikiServerSecurityGroup | AWS::EC2::SecurityGroup | CREATE_COMPLETE | 2013-08-05T07:35:48Z |
| IPAddress | AWS::EC2::EIP | CREATE_COMPLETE | 2013-08-05T07:35:59Z |
| WikiServer | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T07:35:59Z |
| IPAssoc | AWS::EC2::EIPAssociation | CREATE_COMPLETE | 2013-08-05T07:36:00Z |
| MountPoint | AWS::EC2::VolumeAttachment | CREATE_COMPLETE | 2013-08-05T07:36:02Z |
+————————-+—————————-+—————–+———————-+
[root@controller-1 heat(keystone_ncep)]# cinder list
+————————————–+——–+————————-+——+————-+———-+————————————–+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+————————————–+——–+————————-+——+————-+———-+————————————–+
| 16c9c84f-9bf3-43c7-853d-453ec161b170 | in-use | wp-ebs.DataVolume | 5 | None | false | 0738154d-8d58-4a84-a5fc-71774228105d |
+————————————–+——–+————————-+——+————-+———-+————————————–+
Inside vm, we can check mounts:
[root@wp-ebs ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 5.0G 1.6G 3.1G 34% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/vdb1 938M 39M 853M 5% /var/lib/mysql
4.部署启用了HA保护的wordpress博客服务器
wget https://github.com/abckey/heat-templates/raw/master/WordPress_Single_Instance_With_HA.template
要使用 HA,需要等待条件资源,这需要创建一个 ec2sign 的 url,为此,它会在 keystone 中创建一个受限用户。
keystone user-role-add –user <ncep user id> –role <admin role id> –tenant-id <ncep tenant id>
heat stack-create wp-ha -f WordPress_Single_Instance_With_HA.template -P “HupPollInterval=1;InstanceType=m1.medium;DBUsername=wordpress;DBPassword=worldpress;KeyName=ncepkey;LinuxDistribution=RHEL-6.3”
[root@controller-1 heat(keystone_ncep)]# heat resource-list wp-ha
+—————+——————————————+—————–+———————-+
| Name | Type | Status | Updated |
+—————+——————————————+—————–+———————-+
| CfnUser | AWS::IAM::User | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WaitHandle | AWS::CloudFormation::WaitConditionHandle | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WebServerKeys | AWS::IAM::AccessKey | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WaitCondition | AWS::CloudFormation::WaitCondition | IN_PROGRESS | 2013-08-05T07:53:41Z |
| WikiDatabase | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T07:53:41Z |
+—————+——————————————+—————–+———————-+
这里实际上是在等待VM实例正确启动和配置,然后转到下一步WaitCondition
create_complete后的整个资源列表:
[root@controller-1 heat(keystone_ncep)]# heat resource-list wp-ha
+————————+——————————————+—————–+———————-+
| Name | Type | Status | Updated |
+————————+——————————————+—————–+———————-+
| CfnUser | AWS::IAM::User | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WebServerKeys | AWS::IAM::AccessKey | CREATE_COMPLETE | 2013-08-05T07:53:30Z |
| WaitHandle | AWS::CloudFormation::WaitConditionHandle | CREATE_COMPLETE | 2013-08-05T07:54:41Z |
| WikiDatabase | AWS::EC2::Instance | CREATE_COMPLETE | 2013-08-05T07:54:41Z |
| HttpFailureAlarm | AWS::CloudWatch::Alarm | CREATE_COMPLETE | 2013-08-05T07:54:47Z |
| WaitCondition | AWS::CloudFormation::WaitCondition | CREATE_COMPLETE | 2013-08-05T07:54:47Z |
| WebServerRestartPolicy | OS::Heat::HARestarter | CREATE_COMPLETE | 2013-08-05T07:54:47Z |
+————————+——————————————+—————–+———————-+
资源负责服务 HA。OS::Heat::HARestart
->尝试通过浮动IP访问wordpress网站
登录页面应该会显示出来。
->通过停止 httpd 服务来试用 HA
在 VM 中,执行服务 httpd 停止。
检查cfn-hup.log
[root@wp-ha ~]# tail -f /var/log/cfn-hup.log
DEBUG [2013-08-05 16:28:02,552] Running command: /sbin/service httpd status
DEBUG [2013-08-05 16:28:02,609] Return code of 3 after executing: ‘[‘su’, ‘root’, ‘-c’, u’/sbin/service httpd status’]’
WARNING [2013-08-05 16:28:02,610] Restarting service httpd
DEBUG [2013-08-05 16:28:02,610] Running command: /sbin/service httpd start
DEBUG [2013-08-05 16:28:02,732] Running command: /etc/cfn/notify-on-httpd-restarted
DEBUG [2013-08-05 16:28:03,634] Running command: /sbin/service mysqld status
DEBUG [2013-08-05 16:28:03,714] Running command: /sbin/service crond status
我们可以看到,一旦 cfn-hup 发现 httpd 服务有问题,它就试图启动 httpd 服务。
->再次检查wordpress Web访问,它应该再次工作。
- Get link
- X
- Other Apps
Comments
Post a Comment