在Openstack Liberty版本里实现Auto Scale
来源:互联网 发布:java自行车 编辑:程序博客网 时间:2024/05/30 04:23
Openstack里的Auto Scale是由Heat和Ceilometer模块一起配合完成的。Ceilometer负责收集处理性能数据,一旦达到Heat模版里定义的阀值,就发告警信息给heat-engine,由heat-engine调动Heat模版里定义的其它的OpenStack资源实现auto scale,总体示意图如下:
下面介绍一下实现的步骤:
1. 安装配置好一个标准的OpenStack试验环境,具体配置参考社区文档。在配置auto scale之前要先检查确定nova, neutron, heat, ceilometer模块都正常工作。nova和neutron的检查通过启动一个虚机就可以实现,heat的检查可以通过运行一个简单的生成虚机的stack来实现,ceilometer的检查要确保在虚机创建后,命令“ceilometer meter-list”可以输出计量项。
2. 检查通过后,准备一个最简单的环境模版,名字叫cirros.yaml,内容如下。其作用就是启动一个虚机,并且分配一个私网IP给它。这个模版可以直接通过heat来运行。
heat_template_version: 2014-10-16description: A base Cirros 0.3.4 serverresources: server: type: OS::Nova::Server properties: flavor: m1.micro image: cirros-0.3.4 key_name: my_key networks: - port: { get_resource: port } port: type: OS::Neutron::Port properties: network: private
2. 对之前生成的环境模版进行注册,注册后的文件名叫environment.yaml,内容如下:
resource_registry: "OS::Nova::Server::Cirros": "file:///openstack/master/kvm-controller/heat-template/cirros.yaml"
3. 创建一个heat stack模版,命名为example.yaml,内容如下。主要目的是生成两个ceilometer alarm,一个监控cpu_util是否大于50%,另一个监控cpu_util是否小于10%。如果大于50%,就创建一个新的Cirros资源(这里就是一个虚机),如果小于10%,就终结一个Cirros资源。
heat_template_version: 2014-10-16description: Example auto scale group, policy and alarmresources: scaleup_group: type: OS::Heat::AutoScalingGroup properties: cooldown: 30 desired_capacity: 1 max_size: 3 min_size: 1 resource: type: OS::Nova::Server::Cirros scaleup_policy: type: OS::Heat::ScalingPolicy properties: adjustment_type: change_in_capacity auto_scaling_group_id: { get_resource: scaleup_group } cooldown: 30 scaling_adjustment: 1 scaledown_policy: type: OS::Heat::ScalingPolicy properties: adjustment_type: change_in_capacity auto_scaling_group_id: { get_resource: scaleup_group } cooldown: 30 scaling_adjustment: -1 cpu_alarm_high: type: OS::Ceilometer::Alarm properties: meter_name: cpu_util statistic: avg period: 30 evaluation_periods: 1 threshold: 50 alarm_actions: - {get_attr: [scaleup_policy, alarm_url]} comparison_operator: gt cpu_alarm_low: type: OS::Ceilometer::Alarm properties: meter_name: cpu_util statistic: avg period: 30 evaluation_periods: 1 threshold: 10 alarm_actions: - {get_attr: [scaledown_policy, alarm_url]} comparison_operator: lt
4. 为了快速验证,建议修改ceilometer对cpu的polling时间,从缺省的600秒改为30秒。编辑/etc/ceilometer/pipeline.yaml,修改为如下内容:
- name: cpu_source interval: 30 meters: - "cpu" sinks: - cpu_sink - cpu_delta_sink
5. 重启所有的OpenStack服务,以让对ceilometer的修改生效:
# openstack-service restart
6. 之后就可以尝试通过heat创建stack了。但是这时候创建一般都会报错,因为这个版本存在一些bug,并且一些配置文件内容需要修改。具体请参考后面的内容:
# heat stack-create auto-scale -f example.yaml -e environment.yaml
7. 因为存在bug,需要修改部分代码。编辑/usr/lib/python2.7/site-packages/heat/engine/clients/os/ceilometer.py内容,修改如下:
def _create(self): con = self.context endpoint_type = self._get_client_option('ceilometer', 'endpoint_type') endpoint = self.url_for(service_type=self.METERING, endpoint_type=endpoint_type) args = { 'auth_url': con.auth_url, 'service_type': self.METERING, 'project_name': con.tenant, ==> 修改为'project_id': con.tenant_id, 'token': lambda: self.auth_token, 'endpoint_type': endpoint_type, 'os_endpoint': endpoint, 'cacert': self._get_client_option('ceilometer', 'ca_file'), 'cert_file': self._get_client_option('ceilometer', 'cert_file'), 'key_file': self._get_client_option('ceilometer', 'key_file'), 'insecure': self._get_client_option('ceilometer', 'insecure') }注意,如果不修改的话,会在/var/log/heat/heat-engine.log里报错“BadRequest: Expecting to find domain in project - the server could not comply with the request since it is either malformed or otherwise incorrect”
8. 编辑/etc/heat/heat.conf文件,修改如下内容:
[ec2authtoken]<span style="color:#FF0000;">#auth_uri = http://controller:5000</span>
==> 注释掉标红的一行,否则heat-engine不会收到来自ceilometer notifer的alarm信息。
[trustee]http://controller:5000auth_url = http://controller:35357auth_plugin = passwordproject_domain_id = defaultuser_domain_id = default<span style="color:#FF0000;">#project_name = service</span>username = heatpassword = Welcome1
==> 注释掉标红的一行,否则heat-engine会报错"AuthorizationFailure: Authentication cannot be scoped to multiple targets. Pick one of: project, domain, trust or unscoped" 。这是因为heat默认使用keystone trusts认证(由deferred_auth_method = trusts定义),这种情况下使用trust_id,而不是project_name。trust_id和project_name是互斥的,也就是说在keystone认证的时候只能二者取其一,可以从/usr/lib/python2.7/site-packages/keystoneclient/auth/identity/v3/base.py代码看到如下定义:
mutual_exclusion = [bool(self.domain_id or self.domain_name),
bool(self.project_id or self.project_name),
bool(self.trust_id),
bool(self.unscoped)]
9. 然后就又回到步骤6,可以尝试创建stack了,创建之前需要重启heat让之前的配置修改生效。
# openstack-service restart heat# heat stack-create auto-scale -f example.yaml -e environment.yaml
检查stack是否创建成功,如下。同时可以看到一个虚机已经被创建出来,因为之前stack模版里定义的初始虚机数量为1。
# heat stack-list
10. Heat stack被创建成功后,会有两个ceilometer alarm被创建出来,并且对虚机的cpu_util进行监控,如下。一旦达到预设条件,就会通过ceilometer notifier向heat engine发送告警信息。state值为ok表示没有达到预设条件。
# ceilometer alarm-list
11. 登陆该虚机,在root用户下执行如下命令升高CPU使用率。如果升高不够,可以多执行几遍该命令:
# dd if=/dev/zero of=/dev/null &
ceilometer alarm监控发现满足预设条件后,state值就会变为alarm,并向heat-engine发出告警,如下:
同时在/var/log/ceilometer/alarm-notifier.log里可以看到如下告警信息:
2015-12-19 19:28:19.380 1231 INFO ceilometer.alarm.notifier.rest [req-1d154751-2cd7-457d-8134-81f027c5308e - - - - -] Notifyingalarm auto-scale-cpu_alarm_high-afcfufyrodcu d38ddcc7-648d-4825-870b-8ead836018e3 with severity low from alarm to alarm with action SplitResult(scheme=u'http', netloc=u'controller:8000', path=u'/v1/signal/arn%3Aopenstack%3Aheat%3A%3A2ceea994018041b09f2c247e9e2e8981%3Astacks%2Fauto-scale%2F7670529e-4f38-4d3a-ab3b-dcdb85aecef1%2Fresources%2Fscaleup_policy', query=u'Timestamp=2015-12-19T10%3A02%3A38Z&SignatureMethod=HmacSHA256&AWSAccessKeyId=7875be3699d7487cbe0ae3f5a109dddc&SignatureVersion=2&Signature=HhXf2JwXUzll4c%2BL%2BbeeJHqa74DP5LWfBXTVNF%2Ba1%2F4%3D', fragment='') because Remaining as alarm due to 1 samples outside threshold, most recent: 110.633529734. request-id: req-877f2872-2a40-4dc1-9667-9a05a412ddde
12. heat-engine收到告警后,就会根据auto scale policy扩展资源,完成auto scaling。一个新的虚机资源就会被创建出来:
# nova list
13. 如果虚机的CPU使用率降下来,触发了cpu_low的alarm,其中一个虚机就会被删除掉。
- 在Openstack Liberty版本里实现Auto Scale
- OpenStack Liberty版本network troubleshooting
- OpenStack Liberty版本里如何配置基于haproxy的负载均衡服务(LBaaS)
- OpenStack Liberty(第12个版本)
- 自动安装分布式liberty版本openstack
- openstack nova 创建虚拟机流程 liberty版本
- openstack nova schduler服务分析 liberty版本
- 自动安装分布式liberty版本openstack
- OpenStack Liberty 版本功能有哪些新突破
- 20分钟自动安装liberty版本openstack开发云环境
- 手动安装liberty版本openstack环境(allinone)---环境准备
- [译] OpenStack Liberty 版本中的53个新变化
- 手动安装liberty版本openstack环境(allinone)---安装keystone
- 手动安装liberty版本openstack环境(allinone)---安装glance
- 手动安装liberty版本openstack环境(allinone)---安装nova
- 手动安装liberty版本openstack环境(allinone)---安装cinder
- 手动安装liberty版本openstack环境(allinone)---安装neutron
- 手动安装liberty版本openstack环境(allinone)---安装dashboard
- eclipse打jar包步骤
- MongoDB使用小结:一些不常见的经验分享
- 2硬件连接借口
- Apple的示例SpeakHere不能运行解决
- ubuntu 15.10 安装Wine1.7 解决依赖
- 在Openstack Liberty版本里实现Auto Scale
- 关于递归调用
- [Java学习] Java文件处理类
- 实战c++中的vector系列--C++11对vector成员函数的扩展(cbegin()、cend()、crbegin()、crend()、emplace()、data())
- Unity - 序列化 ScriptableObject、SerializedProperty 编辑器运用进阶
- 麦兜个人博客开通啦!!!
- Base64编码及其运用
- Android-Bluetooth Low Energy
- [Java代码] java使用itext按页码拆分pdf文件