lbaas及heat-autoscaling(juno)

实例模板:
https://github.com/openstack/heat-templates/tree/master/hot


key是keypair

lbaas及heat-autoscaling(juno)_第1张图片
其中下述命令中各参数可以用nova net-list nova flavor-list获取:

heat stack-create -f autoscaling.yaml autoscale-ttx -P "database_flavor=m1.tiny;subnet_id=4beaf460-414f-4ae2-a51e-63b047d67e80;external_network_id=338ebf32-6128-4b47-962b-f19409e55261;image=cirros-0.3.3-x86_64;key=ttx-keypair;flavor=m1.tiny;network=4c676ea1-06a6-4235-8326-6c88aaf7fb15"


systemctl restart openstack-heat-api.service openstack-heat-api-cfn.service openstack-heat-engine.service 

heat --debug stack-create   -f autoscaling.yaml  -P "database_flavor=m1.tiny;subnet_id=4beaf460-414f-4ae2-a51e-63b047d67e80;external_network_id=338ebf32-6128-4b47-962b-f19409e55261;image=cirros-0.3.3-x86_64;key=ttx-keypair;flavor=m1.tiny;network=4c676ea1-06a6-4235-8326-6c88aaf7fb15" auto-test-1


tailf /var/log/heat/heat-engine.log
lbaas及heat-autoscaling(juno)_第2张图片
网络报错,最后发现是没有按照LbaaS导致:
http://docs.openstack.org/admin-guide-cloud/content/install_neutron-lbaas-agent.html


 ERROR neutron.agent.linux.utils [req-6533de47-c74c-412c-b98f-8289e6948277 None]
Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ip', 'netns', 'exec', 'qlbaas-8dfb5a4e-ef87-4f14-9a11-d58bd24e4d70', 'haproxy', '-f', '/var/lib/neutron/lbaas/8dfb5a4e-ef87-4f14-9a11-d58bd24e4d70/conf', '-p', '/var/lib/neutron/lbaas/8dfb5a4e-ef87-4f14-9a11-d58bd24e4d70/pid']
Exit code: 99



sudo neutron-rootwrap /etc/neutron/rootwrap.conf ip netns exec qlbaas-8dfb5a4e-ef87-4f14-9a11-d58bd24e4d70 haproxy -f /var/lib/neutron/lbaas/8dfb5a4e-ef87-4f14-9a11-d58bd24e4d70/conf -p /var/lib/neutron/lbaas/8dfb5a4e-ef87-4f14-9a11-d58bd24e4d70/pid
直接输入命令测试:


说明是 neutron-rootwrap没有操作ip该命令权限:

官方wiki:

https://wiki.openstack.org/wiki/Rootwrap

lbaas及heat-autoscaling(juno)_第3张图片

看官方文档,如果发觉e文不好理解的话,最好的方式就是参考现成的写法:

vim /etc/nova/rootwrap.conf
lbaas及heat-autoscaling(juno)_第4张图片


vim /usr/share/nova/rootwrap/compute.filters 

从上图可知,
1、第一列为名称,永远与第三列相同
2、第二列固定为CommandFilter,第四列永远为root
3、似乎ip该项以及加入到nova的nova-rootwrap权限中了

试验nova-rootwrap 对ip命令权限:
lbaas及heat-autoscaling(juno)_第5张图片

下面就直接照抄copy一份即可了:
vim /usr/share/neutron/rootwrap/ip.filters 


lbaas及heat-autoscaling(juno)_第6张图片

ok,权限解决。

继续生成:


直接yum install haproxy -y

lbaas及heat-autoscaling(juno)_第7张图片


lbaas及heat-autoscaling(juno)_第8张图片
lbaas终于搞定。

继续用上述脚本autoscaling:

lbaas及heat-autoscaling(juno)_第9张图片
lbaas及heat-autoscaling(juno)_第10张图片



接下来还是大概分析下autoscaling的heat模块:

autoscaling.yaml
heat_template_version: 2013-05-23 #heat模板版本
description: AutoScaling Wordpress
parameters: #下面为通过命令行输入的参数
  image: #镜像id或者名字
    type: string
    description: Image used for servers
  key: #keypair名字
    type: string
    description: SSH key to connect to the servers
  flavor:# 此处为虚拟机规格,解释说明了,是web服务虚拟机
    type: string
    description: flavor used by the web servers
  database_flavor: #此处为虚拟机规格,解释说明了,是用来安装数据库的后端服务虚拟机
    type: string
    description: flavor used by the db server
  network: #网络
    type: string
    description: Network used by the server
  subnet_id: #子网id
    type: string
    description: subnet on which the load balancer will be located
  database_name: #数据库名
    type: string
    description: Name of the wordpress DB
    default: wordpress
  database_user: #数据库用户
    type: string
    description: Name of the wordpress user
    default: wordpress
  external_network_id: #外网id
    type: string
    description: UUID of a Neutron external network
resources: #资源属性列表
  database_password:
    type: OS::Heat::RandomString
  database_root_password:
    type: OS::Heat::RandomString
  db:
    type: OS::Nova::Server
    properties:
      flavor: {get_param: database_flavor} #获取上述parameters列表中命令行输入的参数值
      image: {get_param: image} #下述同上,获取参数值
      key_name: {get_param: key}
      networks: [{network: {get_param: network} }]
      user_data_format: RAW
      user_data:
        str_replace:
          template: |
            #!/bin/bash -v
            yum -y install mariadb mariadb-server
            systemctl enable mariadb.service
            systemctl start mariadb.service
            mysqladmin -u root password $db_rootpassword
            cat << EOF | mysql -u root --password=$db_rootpassword
            CREATE DATABASE $db_name;
            GRANT ALL PRIVILEGES ON $db_name.* TO "$db_user"@"%"
            IDENTIFIED BY "$db_password";
            FLUSH PRIVILEGES;
            EXIT
            EOF
          params:
            $db_rootpassword: {get_attr: [database_root_password, value]}
            $db_name: {get_param: database_name}
            $db_user: {get_param: database_user}
            $db_password: {get_attr: [database_password, value]}
  asg:
    type: OS::Heat::AutoScalingGroup
    properties:
      min_size: 1
      max_size: 3
      resource:
        type: lb_server.yaml
        properties:
          flavor: {get_param: flavor}
          image: {get_param: image}
          key_name: {get_param: key}
          network: {get_param: network}
          pool_id: {get_resource: pool}
          metadata: {"metering.stack": {get_param: "OS::stack_id"}}
          user_data:
            str_replace:
              template: |
                #!/bin/bash -v
                yum -y install httpd wordpress
                systemctl enable httpd.service
                systemctl start httpd.service
                setsebool -P httpd_can_network_connect_db=1

                sed -i "/Deny from All/d" /etc/httpd/conf.d/wordpress.conf
                sed -i "s/Require local/Require all granted/" /etc/httpd/conf.d/wordpress.conf
                sed -i s/database_name_here/$db_name/ /etc/wordpress/wp-config.php
                sed -i s/username_here/$db_user/ /etc/wordpress/wp-config.php
                sed -i s/password_here/$db_password/ /etc/wordpress/wp-config.php
                sed -i s/localhost/$db_host/ /etc/wordpress/wp-config.php

                systemctl restart httpd.service
              params:
                $db_name: {get_param: database_name}
                $db_user: {get_param: database_user}
                $db_password: {get_attr: [database_password, value]}
                $db_host: {get_attr: [db, first_address]}
  web_server_scaleup_policy:
    type: OS::Heat::ScalingPolicy
    properties:
      adjustment_type: change_in_capacity
      auto_scaling_group_id: {get_resource: asg}
      cooldown: 60
      scaling_adjustment: 1
  web_server_scaledown_policy:
    type: OS::Heat::ScalingPolicy
    properties:
      adjustment_type: change_in_capacity
      auto_scaling_group_id: {get_resource: asg}
      cooldown: 60
      scaling_adjustment: -1
  cpu_alarm_high:
    type: OS::Ceilometer::Alarm
    properties:
      description: Scale-up if the average CPU > 50% for 1 minute
      meter_name: cpu_util
      statistic: avg
      period: 60
      evaluation_periods: 1
      threshold: 50
      alarm_actions:
        - {get_attr: [web_server_scaleup_policy, alarm_url]}
      matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
      comparison_operator: gt
  cpu_alarm_low:
    type: OS::Ceilometer::Alarm
    properties:
      description: Scale-down if the average CPU < 15% for 10 minutes
      meter_name: cpu_util
      statistic: avg
      period: 600
      evaluation_periods: 1
      threshold: 15
      alarm_actions:
        - {get_attr: [web_server_scaledown_policy, alarm_url]}
      matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
      comparison_operator: lt
  monitor:
    type: OS::Neutron::HealthMonitor
    properties:
      type: TCP
      delay: 5
      max_retries: 5
      timeout: 5
  pool:
    type: OS::Neutron::Pool
    properties:
      protocol: HTTP
      monitors: [{get_resource: monitor}]
      subnet_id: {get_param: subnet_id}
      lb_method: ROUND_ROBIN
      vip:
        protocol_port: 80
  lb:
    type: OS::Neutron::LoadBalancer
    properties:
      protocol_port: 80
      pool_id: {get_resource: pool}

  # assign a floating ip address to the load balancer
  # pool.
  lb_floating:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network_id: {get_param: external_network_id}
      port_id: {get_attr: [pool, vip, port_id]}

outputs:
  scale_up_url:
    description: >
      This URL is the webhook to scale up the autoscaling group.  You
      can invoke the scale-up operation by doing an HTTP POST to this
      URL; no body nor extra headers are needed.
    value: {get_attr: [web_server_scaleup_policy, alarm_url]}
  scale_dn_url:
    description: >
      This URL is the webhook to scale down the autoscaling group.
      You can invoke the scale-down operation by doing an HTTP POST to
      this URL; no body nor extra headers are needed.
    value: {get_attr: [web_server_scaledown_policy, alarm_url]}
  pool_ip_address:
    value: {get_attr: [pool, vip, address]}
    description: The IP address of the load balancing pool
  website_url:
    value:
      str_replace:
        template:  http://host/wordpress/
        params:
          host: { get_attr: [lb_floating, floating_ip_address] }
    description: >
      This URL is the "external" URL that can be used to access the
      Wordpress site.
  ceilometer_query:
    value:
      str_replace:
        template: >
          ceilometer statistics -m cpu_util
          -q metadata.user_metadata.stack=stackval -p 600 -a avg
        params:
          stackval: { get_param: "OS::stack_id" }
    description: >
      This is a Ceilometer query for statistics on the cpu_util meter
      Samples about OS::Nova::Server instances in this stack.  The -q
      parameter selects Samples according to the subject's metadata.
      When a VM's metadata includes an item of the form metering.X=Y,
      the corresponding Ceilometer resource has a metadata item of the
      form user_metadata.X=Y and samples about resources so tagged can
      be queried with a Ceilometer query term of the form
      metadata.user_metadata.X=Y.  In this case the nested stacks give
      their VMs metadata that is passed as a nested stack parameter,
      and this stack passes a metadata of the form metering.stack=Y,
      where Y is this stack's ID.



lb_server.yaml
heat_template_version: 2013-05-23
description: A load-balancer server
parameters:
  image:
    type: string
    description: Image used for servers
  key_name:
    type: string
    description: SSH key to connect to the servers
  flavor:
    type: string
    description: flavor used by the servers
  pool_id:
    type: string
    description: Pool to contact
  user_data:
    type: string
    description: Server user_data
  metadata:
    type: json
  network:
    type: string
    description: Network used by the server

resources:
  server:
    type: OS::Nova::Server
    properties:
      flavor: {get_param: flavor}
      image: {get_param: image}
      key_name: {get_param: key_name}
      metadata: {get_param: metadata}
      user_data: {get_param: user_data}
      user_data_format: RAW
      networks: [{network: {get_param: network} }]
  member:
    type: OS::Neutron::PoolMember
    properties:
      pool_id: {get_param: pool_id}
      address: {get_attr: [server, first_address]}
      protocol_port: 80





你可能感兴趣的:(lbaas及heat-autoscaling(juno))