目录 弹性伸缩 使用Heat Heat模板 创建 手动创建 创建负载均衡Policy 创建集群成员的Profile 创建集群 挂载Policy 创建Receiver 查看 查看集群状态 查看负载均衡的状态 查看Listener的状态 负载均衡资源池的状态 查看负载均衡的成员的状态 查看集群节点的状态 查看集群的操作记录 查看集群的Receiver 验证 集群收缩 集群扩张
弹性伸缩 使用Heat Heat是OpenStack中负责资源编排的组件,旨在自动化和管理OpenStack环境中的基础设施和应用程序部署。Heat的主要功能是实现基础设施即代码(IaC)和自动化编排,它允许用户定义和描述整个云环境的基础设施需求,然后通过模板来部署和管理这些资源。 实际部署实践通常需要使集群负载平衡并自动扩展。Senlin更希望用户基于业务数据而不是基础设施指标触发扩展操作。当现有集群不足以承担吞吐量或工作负载时,集群将被扩展;当吞吐量或工作负载较低时,集群将被扩展。
Heat模板 下面为连接到创建的负载均衡集群定义了一个安全组。
1 2 3 4 5 6 7 8 9 10 11 security_group: type: OS::Neutron::SecurityGroup properties: rules: - protocol: icmp - protocol: tcp port_range_min: 22 port_range_max: 22 - protocol: tcp port_range_min: 80 port_range_max: 80
下面定义了用于创建目标集群的配置文件。
1 2 3 4 5 6 7 8 9 10 11 12 profile: type: OS::Senlin::Profile properties: type: os.nova.server-1.0 properties: flavor: {get_param: flavor } image: {get_param: image } key_name: {get_param: key_name } networks: - network: {get_param: network } security_groups: - {get_resource: security_group }
下面定义创建一个至少有两个节点的Senlin集群。
1 2 3 4 5 6 cluster: type: OS::Senlin::Cluster properties: desired_capacity: 2 min_size: 2 profile: {get_resource: profile }
下面的两个资源定义了附加到创建的集群的两个策略scale_in_policy和scale_out_policy。其中,event用于定义策略工作的目标操作。当adjustment的类型设置为CHANGE_IN_CAPACITY时,集群将在scale_out时增加节点数,或在scale_in时减少节点数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 scale_in_policy: type: OS::Senlin::Policy properties: type: senlin.policy.scaling-1.0 bindings: - cluster: {get_resource: cluster } properties: event: CLUSTER_SCALE_IN adjustment: type: CHANGE_IN_CAPACITY number: 1 scale_out_policy: type: OS::Senlin::Policy properties: type: senlin.policy.scaling-1.0 bindings: - cluster: {get_resource: cluster } properties: event: CLUSTER_SCALE_OUT adjustment: type: CHANGE_IN_CAPACITY number: 1
下面的资源定义了要附加到目标集群的负载均衡策略lb_policy。一旦将策略附加到集群,Senlin将通过调用neutron LBaas V2 API来自动创建负载平衡器、池和health_monitor以实现负载平衡。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 lb_policy: type: OS::Senlin::Policy properties: type: senlin.policy.loadbalance-1.0 bindings: - cluster: {get_resource: cluster } properties: pool: protocol: HTTP protocol_port: 80 subnet: {get_param: pool_subnet } lb_method: ROUND_ROBIN vip: subnet: {get_param: vip_subnet } protocol: HTTP protocol_port: 80 health_monitor: type: HTTP delay: 10 timeout: 5 max_retries: 4
下面定义了两个当某个警报或事件发生时要触发的接收器,用于执行集群节点的伸缩。
1 2 3 4 5 6 7 8 9 10 11 12 13 receiver_scale_out: type: OS::Senlin::Receiver properties: cluster: {get_resource: cluster } action: CLUSTER_SCALE_OUT type: webhook receiver_scale_in: type: OS::Senlin::Receiver properties: cluster: {get_resource: cluster } action: CLUSTER_SCALE_IN type: webhook
下面定义了在要缩减群集时选择要删除的候选节点的策略。
1 2 3 4 5 6 7 8 9 10 11 deletion_policy: type: OS::Senlin::Policy properties: type: senlin.policy.deletion-1.0 bindings: - cluster: {get_resource: cluster } properties: criteria: YOUNGEST_FIRST destroy_after_deletion: True grace_period: 20 reduce_desired_capacity: False
下面的两个资源分别定义了触发上述两个接收器的alarm。使用LoadBalancer的上传字节的平均速率作为触发缩放操作的指标。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 scale_in_alarm: type: OS::Ceilometer::Alarm properties: description: trigger when bandwidth overflow meter_name: network.services.lb.incoming.bytes.rate statistic: avg period: 180 evaluation_periods: 1 threshold: 12000 repeat_actions: True alarm_actions: - {get_attr: [receiver_scale_in , channel , alarm_url ]} comparison_operator: le query: metadata.user_metadata.cluster_id: {get_resource: cluster } scale_out_alarm: type: OS::Ceilometer::Alarm properties: description: trigger when bandwidth insufficient meter_name: network.services.lb.incoming.bytes.rate statistic: avg period: 60 evaluation_periods: 1 threshold: 28000 repeat_actions: True alarm_actions: - {get_attr: [receiver_scale_out , channel , alarm_url ]} comparison_operator: ge query: metadata.user_metadata.cluster_id: {get_resource: cluster }
创建 部署前,请确保OpenStack环境中开启neutron lbaas、ceilometer/aodh。 使用Heat命令创建上面的资源。
1 openstack stack create test -t ./ex_aslb.yaml
手动创建 创建负载均衡Policy 先创建负载均衡的policy。编辑一个用于创建负载均衡policy的yaml文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 type: senlin.policy.loadbalance version: 1.1 description: A policy for load-balancing the nodes in a cluster. properties: pool: protocol: HTTP protocol_port: 9527 subnet: c6294e23-1028-412a-b837-ae6bf54e641e lb_method: ROUND_ROBIN session_persistence: type: NONE cookie_name: whatever vip: subnet: d7886821-fc22-4531-bad4-c5a3abe7d382 connection_limit: 500 protocol: HTTP protocol_port: 9527 health_monitor: type: HTTP delay: 10000 timeout: 5000 max_retries: 4 http_method: 'GET' url_path: '/' expected_codes: '200, 202' lb_status_timeout: 300
利用yaml文件创建负载均衡的policy。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 openstack cluster policy create --spec-file ./lb_policy.yml lb_policy +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | created_at | 2023-09-21T07:03:15.000000 | | data | {} | | domain_id | None | | id | 8ab1e7b4-9ba0-4419-86dc-f220f023cfae | | location | Munch({'cloud' : '' , 'region_name' : 'RegionOne' , 'zone' : None, 'project' : Munch({'id' : '9ded7ac44c184871a6e4ea7f07bf3e6e' , 'name' : 'admin' , 'domain_id' : None, 'domain_name' : 'Default' })}) | | name | lb_policy | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | spec | { | | | "description" : "A policy for load-balancing the nodes in a cluster." , | | | "properties" : { | | | "health_monitor" : { | | | "delay" : 10000, | | | "expected_codes" : "200, 202" , | | | "http_method" : "GET" , | | | "max_retries" : 4, | | | "timeout" : 5000, | | | "type" : "HTTP" , | | | "url_path" : "/" | | | }, | | | "lb_status_timeout" : 300, | | | "pool" : { | | | "lb_method" : "ROUND_ROBIN" , | | | "protocol" : "HTTP" , | | | "protocol_port" : 9527, | | | "session_persistence" : { | | | "cookie_name" : "whatever" , | | | "type" : "NONE" | | | }, | | | "subnet" : "c6294e23-1028-412a-b837-ae6bf54e641e" | | | }, | | | "vip" : { | | | "connection_limit" : 500, | | | "protocol" : "HTTP" , | | | "protocol_port" : 9527, | | | "subnet" : "d7886821-fc22-4531-bad4-c5a3abe7d382" | | | } | | | }, | | | "type" : "senlin.policy.loadbalance" , | | | "version" : 1.1 | | | } | | type | senlin.policy.loadbalance-1.1 | | updated_at | None | | user_id | 08a18c9cb7cc474d8369b370b8fcbb34 | +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
创建集群成员的Profile 一个简单的profile如下所示。
1 2 3 4 5 6 7 8 type: os.nova.server version: 1.0 properties: name: web-server flavor: 30b0e9c8-7705-4b0d-b492-219df8980588 image: 16e19711 -03cf-4861-8853-de799086090c networks: - network: e258c6a1-ed25-4a91-8fb4-184b0e793be5
创建profile。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 openstack cluster profile create --spec-file ./nova_profile.yml web_server_profile +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | created_at | 2023-09-21T07:17:32Z | | domain_id | None | | id | 6399ab6d-904e-436e-89e3-1a2c04ae7335 | | location | Munch({'cloud' : '' , 'region_name' : 'RegionOne' , 'zone' : None, 'project' : Munch({'id' : '9ded7ac44c184871a6e4ea7f07bf3e6e' , 'name' : 'admin' , 'domain_id' : None, 'domain_name' : 'Default' })}) | | metadata | {} | | name | web_server_profile | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | spec | +------------+---------------------------------------------------------+ | | | | property | value | | | | +------------+---------------------------------------------------------+ | | | | properties | { | | | | | | "flavor" : "30b0e9c8-7705-4b0d-b492-219df8980588" , | | | | | | "image" : "16e19711-03cf-4861-8853-de799086090c" , | | | | | | "name" : "web-server" , | | | | | | "networks" : [ | | | | | | { | | | | | | "network" : "e258c6a1-ed25-4a91-8fb4-184b0e793be5" | | | | | | } | | | | | | ] | | | | | | } | | | | | type | os.nova.server | | | | | version | 1.0 | | | | +------------+---------------------------------------------------------+ | | type | os.nova.server-1.0 | | updated_at | None | | user_id | 08a18c9cb7cc474d8369b370b8fcbb34 | +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
创建集群 利用上面的profile,创建一个大小为2的集群。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 openstack cluster create --max-size 2 --desired-capacity 2 --profile web_server_profile my_cluster +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | config | {} | | created_at | None | | data | {} | | dependents | {} | | desired_capacity | 2 | | domain_id | None | | id | 22514765-c3e2-4872-9a03-c928ffc17107 | | init_at | 2023-09-21T07:22:14Z | | location | Munch({'cloud' : '' , 'region_name' : 'RegionOne' , 'zone' : None, 'project' : Munch({'id' : '9ded7ac44c184871a6e4ea7f07bf3e6e' , 'name' : 'admin' , 'domain_id' : None, 'domain_name' : 'Default' })}) | | max_size | 2 | | metadata | {} | | min_size | 0 | | name | my_cluster | | node_ids | | | profile_id | 6399ab6d-904e-436e-89e3-1a2c04ae7335 | | profile_name | web_server_profile | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | status | INIT | | status_reason | Initializing | | timeout | 3600 | | updated_at | None | | user_id | 08a18c9cb7cc474d8369b370b8fcbb34 | +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
挂载Policy 等待集群创建成功,将负载均衡的策略挂载到新建的集群上。
1 2 openstack cluster policy attach --policy lb_policy my_cluster Request accepted by action: 58efd113-febf-42bb-8de5-8f638c1ae2bf
创建Receiver 创建两个receiver,用于触发集群的伸缩。
1 2 openstack cluster receiver create --cluster my_cluster --action CLUSTER_SCALE_IN --type webhook scale_in_receiver openstack cluster receiver create --cluster my_cluster --action CLUSTER_SCALE_OUT --type webhook scale_out_receiver
创建用于集群收缩的receiver。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 openstack cluster receiver create --cluster my_cluster --action CLUSTER_SCALE_IN --type webhook scale_in_receiver +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | action | CLUSTER_SCALE_IN | | actor | { | | | "trust_id" : "0d4b7eb454844e58bcc8dad3ca6a37b2" | | | } | | channel | { | | | "alarm_url" : "http://172.16.10.10:8778/v1/webhooks/19f36f5a-fe73-4b95-870d-6abe3368ba34/trigger?V=2" | | | } | | cluster_id | 22514765-c3e2-4872-9a03-c928ffc17107 | | created_at | 2023-09-21T08:30:49Z | | domain_id | None | | id | 19f36f5a-fe73-4b95-870d-6abe3368ba34 | | location | Munch({'cloud' : '' , 'region_name' : 'RegionOne' , 'zone' : None, 'project' : Munch({'id' : '9ded7ac44c184871a6e4ea7f07bf3e6e' , 'name' : 'admin' , 'domain_id' : None, 'domain_name' : 'Default' })}) | | name | scale_in_receiver | | params | {} | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | type | webhook | | updated_at | None | | user_id | 08a18c9cb7cc474d8369b370b8fcbb34 | +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
创建用于集群扩张的receiver。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 openstack cluster receiver create --cluster my_cluster --action CLUSTER_SCALE_OUT --type webhook scale_out_receiver +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | action | CLUSTER_SCALE_OUT | | actor | { | | | "trust_id" : "0d4b7eb454844e58bcc8dad3ca6a37b2" | | | } | | channel | { | | | "alarm_url" : "http://172.16.10.10:8778/v1/webhooks/59f632d6-4aad-4e79-817c-93947a318db2/trigger?V=2" | | | } | | cluster_id | 22514765-c3e2-4872-9a03-c928ffc17107 | | created_at | 2023-09-21T08:31:22Z | | domain_id | None | | id | 59f632d6-4aad-4e79-817c-93947a318db2 | | location | Munch({'cloud' : '' , 'region_name' : 'RegionOne' , 'zone' : None, 'project' : Munch({'id' : '9ded7ac44c184871a6e4ea7f07bf3e6e' , 'name' : 'admin' , 'domain_id' : None, 'domain_name' : 'Default' })}) | | name | scale_out_receiver | | params | {} | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | type | webhook | | updated_at | None | | user_id | 08a18c9cb7cc474d8369b370b8fcbb34 | +------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
查看 查看集群状态 等待负载均衡创建完毕。使用命令查看集群状态。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 openstack cluster show my_cluster +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | config | {} | | created_at | 2023-09-21T07:22:34Z | | data | {'loadbalancers' : {'8ab1e7b4-9ba0-4419-86dc-f220f023cfae' : {'vip_address' : '10.10.15.21' }}} | | dependents | {} | | desired_capacity | 2 | | domain_id | None | | id | 22514765-c3e2-4872-9a03-c928ffc17107 | | init_at | 2023-09-21T07:22:14Z | | location | Munch({'cloud' : '' , 'region_name' : 'RegionOne' , 'zone' : None, 'project' : Munch({'id' : '9ded7ac44c184871a6e4ea7f07bf3e6e' , 'name' : 'admin' , 'domain_id' : None, 'domain_name' : 'Default' })}) | | max_size | 2 | | metadata | {} | | min_size | 0 | | name | my_cluster | | node_ids | 60015441-92a7-492c-86b1-e08da8e164e6 | | | f19c798d-2eac-4b63-9a6d-cbf1adbd7aa2 | | profile_id | 6399ab6d-904e-436e-89e3-1a2c04ae7335 | | profile_name | web_server_profile | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | status | ACTIVE | | status_reason | CLUSTER_CREATE: number of active nodes is equal or above desired_capacity (2). | | timeout | 3600 | | updated_at | 2023-09-21T07:33:14Z | | user_id | 08a18c9cb7cc474d8369b370b8fcbb34 | +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
可以看到集群挂载了一个负载均衡器,vip是10.10.15.21。
8ab1e7b4-9ba0-4419-86dc-f220f023cfae是lb_policy的ID并不是负载均衡器的ID
查看负载均衡的状态 然后使用命令查看负载均衡的状态。
1 2 3 4 5 6 openstack loadbalancer list +--------------------------------------+----------------------+----------------------------------+-------------+---------------------+------------------+----------+ | id | name | project_id | vip_address | provisioning_status | operating_status | provider | +--------------------------------------+----------------------+----------------------------------+-------------+---------------------+------------------+----------+ | 7c9408c4-e876-4832-8c18-49a8ef7c3035 | senlin-lb-my_cluster | 9ded7ac44c184871a6e4ea7f07bf3e6e | 10.10.15.21 | ACTIVE | ONLINE | amphora | +--------------------------------------+----------------------+----------------------------------+-------------+---------------------+------------------+----------+
查看senlin-lb-my_cluster的状态。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 openstack loadbalancer show senlin-lb-my_cluster +---------------------+--------------------------------------+ | Field | Value | +---------------------+--------------------------------------+ | admin_state_up | True | | availability_zone | None | | created_at | 2023-09-21T07:25:40 | | description | | | flavor_id | None | | id | 7c9408c4-e876-4832-8c18-49a8ef7c3035 | | listeners | 9fe70cce-b5cf-49aa-b89a-5278bb7d10f5 | | name | senlin-lb-my_cluster | | operating_status | ONLINE | | pools | c832ed78-539a-4e4a-a2e8-ae8fcf3f383c | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | provider | amphora | | provisioning_status | ACTIVE | | updated_at | 2023-09-21T07:33:10 | | vip_address | 10.10.15.21 | | vip_network_id | aa471001-1ac1-4820-9532-65c28794d2bd | | vip_port_id | 3c7ac89a-74f2-498c-979d-03efe2170db4 | | vip_qos_policy_id | None | | vip_subnet_id | d7886821-fc22-4531-bad4-c5a3abe7d382 | | tags | | | additional_vips | [] | +---------------------+--------------------------------------+
查看Listener的状态 查看listener的状态,值得注意的是protocol和protocol_port两个字段。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 openstack loadbalancer listener show 9fe70cce-b5cf-49aa-b89a-5278bb7d10f5 +-----------------------------+--------------------------------------+ | Field | Value | +-----------------------------+--------------------------------------+ | admin_state_up | True | | connection_limit | 500 | | created_at | 2023-09-21T07:30:34 | | default_pool_id | c832ed78-539a-4e4a-a2e8-ae8fcf3f383c | | default_tls_container_ref | None | | description | | | id | 9fe70cce-b5cf-49aa-b89a-5278bb7d10f5 | | insert_headers | None | | l7policies | | | loadbalancers | 7c9408c4-e876-4832-8c18-49a8ef7c3035 | | name | senlin-listener-my_cluster | | operating_status | ONLINE | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | protocol | HTTP | | protocol_port | 9527 | | provisioning_status | ACTIVE | | sni_container_refs | [] | | timeout_client_data | 50000 | | timeout_member_connect | 5000 | | timeout_member_data | 50000 | | timeout_tcp_inspect | 0 | | updated_at | 2023-09-21T07:33:10 | | client_ca_tls_container_ref | None | | client_authentication | NONE | | client_crl_container_ref | None | | allowed_cidrs | None | | tls_ciphers | None | | tls_versions | None | | alpn_protocols | None | | tags | | | hsts_max_age | | | hsts_include_subdomains | | | hsts_preload | | +-----------------------------+--------------------------------------+
负载均衡资源池的状态 查看负载均衡资源池的状态,主要是lb_algorithm和members字段。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 openstack loadbalancer pool show c832ed78-539a-4e4a-a2e8-ae8fcf3f383c +----------------------+--------------------------------------+ | Field | Value | +----------------------+--------------------------------------+ | admin_state_up | True | | created_at | 2023-09-21T07:31:25 | | description | | | healthmonitor_id | 40bc5e4b-114b-44ae-8c8f-b14e20e6e1b9 | | id | c832ed78-539a-4e4a-a2e8-ae8fcf3f383c | | lb_algorithm | ROUND_ROBIN | | listeners | 9fe70cce-b5cf-49aa-b89a-5278bb7d10f5 | | loadbalancers | 7c9408c4-e876-4832-8c18-49a8ef7c3035 | | members | 4ce9b82d-6aca-4cb8-bd67-2339f60f9644 | | | 7b6382e0-4d4a-459f-919a-e87c6d1e77de | | name | senlin-pool-my_cluster | | operating_status | ONLINE | | project_id | 9ded7ac44c184871a6e4ea7f07bf3e6e | | protocol | HTTP | | provisioning_status | ACTIVE | | session_persistence | None | | updated_at | 2023-09-21T07:33:10 | | tls_container_ref | None | | ca_tls_container_ref | None | | crl_container_ref | None | | tls_enabled | False | | tls_ciphers | None | | tls_versions | None | | tags | | | alpn_protocols | None | +----------------------+--------------------------------------+
查看负载均衡的成员的状态 查看负载均衡的成员,可以看到两个成员的状态都是ACTIVE。
1 2 3 4 5 6 7 openstack loadbalancer member list senlin-pool-my_cluster +--------------------------------------+------------+----------------------------------+---------------------+---------------+---------------+------------------+--------+ | id | name | project_id | provisioning_status | address | protocol_port | operating_status | weight | +--------------------------------------+------------+----------------------------------+---------------------+---------------+---------------+------------------+--------+ | 4ce9b82d-6aca-4cb8-bd67-2339f60f9644 | web-server | 9ded7ac44c184871a6e4ea7f07bf3e6e | ACTIVE | 192.168.1.172 | 9527 | ONLINE | 1 | | 7b6382e0-4d4a-459f-919a-e87c6d1e77de | web-server | 9ded7ac44c184871a6e4ea7f07bf3e6e | ACTIVE | 192.168.1.182 | 9527 | ONLINE | 1 | +--------------------------------------+------------+----------------------------------+---------------------+---------------+---------------+------------------+--------+
查看集群节点的状态 查看一下集群节点的状态。
1 2 3 4 5 6 7 openstack cluster members list my_cluster --full-id +--------------------------------------+---------------+-------+--------+--------------------------------------+----------------------+ | id | name | index | status | physical_id | created_at | +--------------------------------------+---------------+-------+--------+--------------------------------------+----------------------+ | 60015441-92a7-492c-86b1-e08da8e164e6 | node-IrIFBpDE | 1 | ACTIVE | bae65730-77e9-4ffd-b50c-e5908f77961e | 2023-09-21T07:22:31Z | | f19c798d-2eac-4b63-9a6d-cbf1adbd7aa2 | node-BoVRlikF | 2 | ACTIVE | 7eac42bd-f1bd-49a4-a48e-0720f6818156 | 2023-09-21T07:22:29Z | +--------------------------------------+---------------+-------+--------+--------------------------------------+----------------------+
查看集群的操作记录 查看集群的操作记录。
1 2 3 4 5 6 7 8 9 openstack cluster action list --filters cluster_id=22514765-c3e2-4872-9a03-c928ffc17107 --full-id +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+ | id | name | action | status | target_id | depends_on | depended_by | created_at | cluster_id | +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+ | d84f39ac-6139-4a7d-a019-0a42411c0a25 | cluster_create_22514765 | CLUSTER_CREATE | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T07:22:15Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 1ae0fe0c-61ff-4d10-809b-aca7cbda3866 | node_create_60015441 | NODE_CREATE | SUCCEEDED | 60015441-92a7-492c-86b1-e08da8e164e6 | | | 2023-09-21T07:22:16Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 4500e8a6-0377-4945-8af8-8d555227d577 | node_create_f19c798d | NODE_CREATE | SUCCEEDED | f19c798d-2eac-4b63-9a6d-cbf1adbd7aa2 | | | 2023-09-21T07:22:16Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 58efd113-febf-42bb-8de5-8f638c1ae2bf | attach_policy_22514765 | CLUSTER_ATTACH_POLICY | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T07:25:37Z | 22514765-c3e2-4872-9a03-c928ffc17107 | +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+
查看集群的Receiver 查看集群的receiver。
1 2 3 4 5 6 7 openstack cluster receiver list --filters cluster_id=22514765-c3e2-4872-9a03-c928ffc17107 --full-id +--------------------------------------+--------------------+---------+--------------------------------------+-------------------+----------------------+ | id | name | type | cluster_id | action | created_at | +--------------------------------------+--------------------+---------+--------------------------------------+-------------------+----------------------+ | 19f36f5a-fe73-4b95-870d-6abe3368ba34 | scale_in_receiver | webhook | 22514765-c3e2-4872-9a03-c928ffc17107 | CLUSTER_SCALE_IN | 2023-09-21T08:30:49Z | | 59f632d6-4aad-4e79-817c-93947a318db2 | scale_out_receiver | webhook | 22514765-c3e2-4872-9a03-c928ffc17107 | CLUSTER_SCALE_OUT | 2023-09-21T08:31:22Z | +--------------------------------------+--------------------+---------+--------------------------------------+-------------------+----------------------+
验证 这时,我们得到了一个带有负载均衡器的集群,同时这个负载均衡器的vip是10.10.15.21,端口是9527,集群的每个成员所起的服务的端口也是9527。用命令测试访问。
1 2 curl 10.10.15.21:9527 Hello world!
可以看到访问成功啦。
集群收缩 使用receiver手动触发集群的收缩。
1 2 curl -X POST http://172.16.10.10:8778/v1/webhooks/19f36f5a-fe73-4b95-870d-6abe3368ba34/trigger?V=2 {"action" : "69049c43-2a37-4228-94c9-5c21f1320e7f" }
查看集群的操作记录,发现节点删除的操作执行成功了。
1 2 3 4 5 6 7 8 9 10 11 openstack cluster action list --filters cluster_id=22514765-c3e2-4872-9a03-c928ffc17107 --full-id +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+ | id | name | action | status | target_id | depends_on | depended_by | created_at | cluster_id | +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+ | d84f39ac-6139-4a7d-a019-0a42411c0a25 | cluster_create_22514765 | CLUSTER_CREATE | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T07:22:15Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 1ae0fe0c-61ff-4d10-809b-aca7cbda3866 | node_create_60015441 | NODE_CREATE | SUCCEEDED | 60015441-92a7-492c-86b1-e08da8e164e6 | | | 2023-09-21T07:22:16Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 4500e8a6-0377-4945-8af8-8d555227d577 | node_create_f19c798d | NODE_CREATE | SUCCEEDED | f19c798d-2eac-4b63-9a6d-cbf1adbd7aa2 | | | 2023-09-21T07:22:16Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 58efd113-febf-42bb-8de5-8f638c1ae2bf | attach_policy_22514765 | CLUSTER_ATTACH_POLICY | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T07:25:37Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 69049c43-2a37-4228-94c9-5c21f1320e7f | webhook_19f36f5a | CLUSTER_SCALE_IN | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T08:48:30Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 96b89886-829b-42e6-a9ad-e477fe4ea2dc | node_delete_60015441 | NODE_DELETE | SUCCEEDED | 60015441-92a7-492c-86b1-e08da8e164e6 | | | 2023-09-21T08:48:52Z | 22514765-c3e2-4872-9a03-c928ffc17107 | +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+
查看集群的节点成员,只剩余一个。
1 2 3 4 5 6 openstack cluster members list my_cluster +----------+---------------+-------+--------+-------------+----------------------+ | id | name | index | status | physical_id | created_at | +----------+---------------+-------+--------+-------------+----------------------+ | f19c798d | node-BoVRlikF | 2 | ACTIVE | 7eac42bd | 2023-09-21T07:22:29Z | +----------+---------------+-------+--------+-------------+----------------------+
集群扩张 调用集群扩张的receiver。
1 2 curl -X POST http://172.16.10.10:8778/v1/webhooks/59f632d6-4aad-4e79-817c-93947a318db2/trigger?V=2 {"action" : "8e17a80e-4093-4165-bb13-5eddb8ede7fd" }
查看集群的操作记录。
1 2 3 4 5 6 7 8 9 10 11 12 13 openstack cluster action list --filters cluster_id=22514765-c3e2-4872-9a03-c928ffc17107 --full-id +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+ | id | name | action | status | target_id | depends_on | depended_by | created_at | cluster_id | +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+ | d84f39ac-6139-4a7d-a019-0a42411c0a25 | cluster_create_22514765 | CLUSTER_CREATE | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T07:22:15Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 1ae0fe0c-61ff-4d10-809b-aca7cbda3866 | node_create_60015441 | NODE_CREATE | SUCCEEDED | 60015441-92a7-492c-86b1-e08da8e164e6 | | | 2023-09-21T07:22:16Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 4500e8a6-0377-4945-8af8-8d555227d577 | node_create_f19c798d | NODE_CREATE | SUCCEEDED | f19c798d-2eac-4b63-9a6d-cbf1adbd7aa2 | | | 2023-09-21T07:22:16Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 58efd113-febf-42bb-8de5-8f638c1ae2bf | attach_policy_22514765 | CLUSTER_ATTACH_POLICY | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T07:25:37Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 69049c43-2a37-4228-94c9-5c21f1320e7f | webhook_19f36f5a | CLUSTER_SCALE_IN | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T08:48:30Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 96b89886-829b-42e6-a9ad-e477fe4ea2dc | node_delete_60015441 | NODE_DELETE | SUCCEEDED | 60015441-92a7-492c-86b1-e08da8e164e6 | | | 2023-09-21T08:48:52Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 8e17a80e-4093-4165-bb13-5eddb8ede7fd | webhook_59f632d6 | CLUSTER_SCALE_OUT | SUCCEEDED | 22514765-c3e2-4872-9a03-c928ffc17107 | | | 2023-09-21T08:53:20Z | 22514765-c3e2-4872-9a03-c928ffc17107 | | 1a3315dc-a77b-42ad-b72f-d3dd7869fecb | node_create_bfe019dc | NODE_CREATE | SUCCEEDED | bfe019dc-1e14-4141-a250-05ec11613186 | | | 2023-09-21T08:53:21Z | 22514765-c3e2-4872-9a03-c928ffc17107 | +--------------------------------------+-------------------------+-----------------------+-----------+--------------------------------------+------------+-------------+----------------------+--------------------------------------+
查看集群的节点成员,已经恢复两个。
1 2 3 4 5 6 7 openstack cluster members list my_cluster +----------+---------------+-------+--------+-------------+----------------------+ | id | name | index | status | physical_id | created_at | +----------+---------------+-------+--------+-------------+----------------------+ | f19c798d | node-BoVRlikF | 2 | ACTIVE | 7eac42bd | 2023-09-21T07:22:29Z | | bfe019dc | node-gy5yc8Q6 | 3 | ACTIVE | 5fb6783a | 2023-09-21T08:53:32Z | +----------+---------------+-------+--------+-------------+----------------------+
查看负载均衡器的成员,可以看到和刚开始创建时成员的地址已经发生了变化。
1 2 3 4 5 6 7 openstack loadbalancer member list senlin-pool-my_cluster +--------------------------------------+------------+----------------------------------+---------------------+---------------+---------------+------------------+--------+ | id | name | project_id | provisioning_status | address | protocol_port | operating_status | weight | +--------------------------------------+------------+----------------------------------+---------------------+---------------+---------------+------------------+--------+ | 7b6382e0-4d4a-459f-919a-e87c6d1e77de | web-server | 9ded7ac44c184871a6e4ea7f07bf3e6e | ACTIVE | 192.168.1.182 | 9527 | ONLINE | 1 | | 2a6ecb36-7da8-402e-93d0-d4cafe11e063 | web-server | 9ded7ac44c184871a6e4ea7f07bf3e6e | ACTIVE | 192.168.1.203 | 9527 | ONLINE | 1 | +--------------------------------------+------------+----------------------------------+---------------------+---------------+---------------+------------------+--------+
1 2 3 groupmod -g 42432 mongodb usermod -u 42486 hacluster usermod -u 42486 hacluster