所有服务安装使用的用户都是root
下面openstack cli client均使用环境变量来提供认证
如果集群状态没有向文章中描述的变化, 不妨停一下, 毕竟是个异步且耗时的操作
本文基于的ussuri版本的senlin, 该版本的senlin由原来的两个服务变成了现在的4个服务:senlin-conductor, senlin-engine, senlin-health-manager, senlin-api.新增了senlin-conductor, senlin-health-manager, 这一改变credit to [email protected]
senlin是一个为openstack云平台打造的集群服务.他可以操作和创建基于openstack平台服务创建的对象的集群. 主要目标便是使相同的对象集合管理更加简单.
profile type
A Profile Type can be treated as the meta-type of a Profile object. A registry of profile types is built in memory when Senlin engine (senlin-engine) is started. In future, Senlin will allow users to provide additional profile type implementations as plug-ins to be loaded dynamically.
A profile type implementation dictates which fields are required. When a profile is created by referencing this profile type, the fields are assigned with concrete values. For example, a profile type can be os.heat.stack that conceptually specifies the properties required:
profile
A Profile is the mould used for creating a Node to be managed by the Senlin service. It can be treated as an instance of a Profile Type with a unique ID. A profile encodes the information needed for node creation in a property named spec.
The primary job for a profile type implementation is to translate user provided JSON data structure into information that can be consumed by a driver. A driver will create/delete/update a physical object based on the information provided.
集群(cluster)
A Cluster is a group of logical objects, each of which is called a Node in Senlin’s terminology. A cluster can contain zero or more nodes. A cluster has a profile_id property that specifies which default Profile to use when new nodes are created/scaled as members of the cluster. It is valid for nodes in a cluster to reference different profile objects because Senlin only mandates that all nodes in a cluster having the same profile type.
Senlin provides APIs and command line supports to manage the cluster membership. Please refer to Cluster Membership for details. Senlin also supports attaching Policy objects to a cluster, customizing the policy properties when attaching a policy to a cluster. Please refer to Cluster-Policy Bindings for details.
节点(node)
A Node is a logical object managed by the Senlin service. A node can be a member of at most one cluster at any time. A node can be an orphan node which means it doesn’t belong to any clusters. Senlin provides APIs and command line supports to manage node’s cluster membership. Please refer to Cluster Membership for details.
A node has a profile_id property when created that specifies which Profile to use when creating a physical object that backs the node. Please refer to Profiles for the creation and management of profile objects.
接收器(receiver)
A Receiver is used to prepare Senlin engine to react to external alarms or events so that a specific Action can be initiated on a senlin cluster automatically. For example, when workload on a cluster climbs high, a receiver can change the size of a specified cluster.
策略(policy)
A Policy is an object instantiated from a Policy Type. Once created, it can be dynamically attached to or detached from a cluster. Such a policy usually contains rules to be checked/enforced when certain Action is about to be executed or has been executed.
One policy can be attached to many clusters, and one cluster can be attached with many policies. In addition to this, a policy on a cluster can be dynamically enabled or disabled. Please refer to Cluster-Policy Bindings for details.
策略类型(policyType)
A Policy Type is an abstract specification of the rules to be checked and/or enforced when an Action is performed on a cluster that contains nodes of certain Profile Type.
A registry of policy types is built in memory when the Senlin engine (senlin-engine) is started. In future, Senlin will allow users to provide additional policy type implementations as plug-ins to be loaded dynamically.
A policy type implementation dictates which fields are required, which fields are optional and sometimes the constraints on field values. When a Policy is created by referencing this policy type, the fields are assigned with concrete values. For example, a policy type senlin.policy.deletion conceptually specifies the properties required:
参考openstack之senlin-api
参考openstack之senlin-conductor
参考openstack之senlin-engine
参考openstack之senlin-health-manager
参考:OpenStack Docs: Install from Git Source Code
mkdir /opt/openstack
cd /opt/openstack
git clone https://git.openstack.org/openstack/senlin.git
cd /opt/openstack/senlin
git checkout -b ussuri origin/stable/ussuri
pip install -e .
source keystonerc admin admin
cd /opt/openstack/senlin
./setup-service 172.31.0.20 senlin
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | f10a5d7f7aba4834a94cdf171d9c4587 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 6e1b45d39396462684c5ec1890c86154 |
| service_name | senlin |
| service_type | clustering |
| url | http://172.31.0.20:8778 |
+--------------+----------------------------------+
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 651e00496f564c26949a275bd3ef3c1e |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 6e1b45d39396462684c5ec1890c86154 |
| service_name | senlin |
| service_type | clustering |
| url | http://172.31.0.20:8778 |
+--------------+----------------------------------+
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 241bd99656a740edbbea8e25d3cf0af6 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 6e1b45d39396462684c5ec1890c86154 |
| service_name | senlin |
| service_type | clustering |
| url | http://172.31.0.20:8778 |
+--------------+----------------------------------+
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| default_project_id | cb20ced7c1ea4f43a35eb15f0ec23650 |
| domain_id | default |
| email | senlin@localhost |
| enabled | True |
| id | 05df0c6831454329876bbbe858cc51a4 |
| name | senlin |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
No role with a name or ID of 'service' exists.
cd /opt/openstack/senlin
tools/gen-config
cp etc/senlin/api-paste.ini /etc/senlin
cp etc/senlin/senlin.conf.sample /etc/senlin/senlin.conf
[default]
debug = true
transport_url = rabbit://openstack:[email protected]:5672//openstack
[database]
connection = mysql+pymysql://senlin:[email protected]/senlin?charset=utf8
[keystone_authtoken]
service_token_roles_required = True
auth_type = password
user_domain_name = Default
project_domain_name = Default
project_name = service
username = senlin
password = senlin
www_authenticate_uri = <http://10.8.8.11:5000
auth_url = http://10.8.8.11:35357
[authentication]
auth_url = http://10.8.8.11:35357
service_username = senlin
service_password = senlin
service_project_name = service
[oslo_messaging_rabbit]
rabbit_qos_prefetch_count = 64
rabbit_userid = openstack
rabbit_hosts = 10.8.8.41
rabbit_password = HBxKktH407Jn2JEGDsaDb2T5kZKIBWsj
[oslo_messaging_notifications]
driver = driver = messagingv2
topics = stacklight_notifications
cd /opt/openstack/senlin
tools/gen-policy
cp etc/senlin/policy.yaml.sample /etc/senlin/policy.yaml
export MYSQL_ROOT_PW=
export MYSQL_SENLIN_PW=
cd /opt/openstack/senlin/tools
./senlin-db-recreate
可以在一个ternail中启动多个服务
senlin-conductor --config-file /etc/senlin/senlin.conf &
senlin-engine --config-file /etc/senlin/senlin.conf &
senlin-health-manager --config-file /etc/senlin/senlin.conf &
senlin-api --config-file /etc/senlin/senlin.conf &
或者通过多个ternal分别启动服务
source /opt/openstack/senlin/.venv/bin/activate
senlin-conductor --config-file /etc/senlin/senlin.conf
senlin-engine --config-file /etc/senlin/senlin.conf
senlin-health-manager --config-file /etc/senlin/senlin.conf
senlin-api --config-file /etc/senlin/senlin.conf
openstack flavor create --public --ram 1024 --vcpus 1 sa1.small.1
openstack image create --disk-format iso --public --file ubuntu-16.04.6-server-amd64.iso ubuntu-16.04
openstack network create --share --enable-port-security --internal gxj-network
创建子网
openstack subnet create --dhcp --network gxj-network --ip-version 4 --subnet-range 192.168.120.0/24 gxj-subnet
openstack keypair create gxj-key
type: os.nova.server
version: 1.0
properties:
name: gxj-server
flavor: sa1.small.1
image: ubuntu-16.04
key_name: gxj-key
networks:
- network: gxj-network
metadata:
test_key: gxj-key
user_data: |
#!/bin/sh
echo 'hello, world from gxj' > /tmp/test_file
openstack cluster profile create --spec-file ubuntu_basic.yml ubuntu_server
openstack cluster create --profile ubuntu_server --desired-capacity 2 ubuntu_cluster
查看集群状态
openstack cluster show ubuntu_cluster
openstack cluster expand ubuntu_cluster
执行结果:
ubuntu@ip-172-31-11-163:~$ openstack cluster expand ubuntu_cluster
Request accepted by action: 3e4e968c-1dea-4aeb-9f2a-46df5c376e36
openstack cluster shrink ubuntu_cluster
查看下ubuntu_cluster的状态
ubuntu@ip-172-31-11-163:~$ openstack cluster show ubuntu_cluster
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MhJpCWqs-1595297316166)(:storage/8be47e2d-2bab-4b49-b8cf-0bbe99226b9f/8a1e3be1.png)]
openstack cluster resize --capacity 4 ubuntu_cluster
例如:
ubuntu@ip-172-31-11-163:~$ openstack cluster resize --capacity 4 ubuntu_cluster
Request accepted by action: 73d4d8f1-80f7-4f3d-9fd9-1ecfefba3d08
openstack cluster node create --profile ubuntu_server new_ubuntu_server
查看行节点的状态
openstack cluster node show new_ubuntu_server
将该节点添加到ubuntu_cluster中
openstack cluster members add --nodes new_ubuntu_server ubuntu_cluster
查看集群节点数量
openstack cluster members list ubuntu_cluster
将new_ubuntu_server从ubuntu_cluster中删除
openstack cluster members del --nodes new_ubuntu_server ubuntu_cluster
执行结果:
ubuntu@ip-172-31-11-163:~$ openstack cluster members del --nodes new_ubuntu_server ubuntu_cluster
Request accepted by action: 744991d3-a7d8-4de3-9483-22a11a09b081
查看集群节点数量
openstack cluster members list ubuntu_cluster
创建一个proxy文件deletion_policy.yaml,内容大概如下:
# 参考openstack官方样例的
type: senlin.policy.deletion
version: 1.0
description: A policy for choosing victim node(s) from a cluster for deletion.
properties:
# The valid values include:
# OLDEST_FIRST, OLDEST_PROFILE_FIRST, YOUNGEST_FIRST, RANDOM
criteria: OLDEST_FIRST
# Whether deleted node should be destroyed
destroy_after_deletion: True
# Length in number of seconds before the actual deletion happens
# This param buys an instance some time before deletion
grace_period: 60
# Whether the deletion will reduce the desired capacity of
# the cluster as well
reduce_desired_capacity: False
创建一个proxy对象:
openstack cluster policy create --spec-file deletion_policy.yaml dp01
验证delete policy dp01是否创建成功
openstack cluster policy list
openstack cluster policy show dp01
将policy绑定到集群上
openstack cluster policy attach --policy dp01 ubuntu_cluster
验证是否产生policy和cluster的绑定
openstack cluster policy binding list ubuntu_cluster
验证cluster:ubuntu_cluster上的policy:dp01是否生效, 根据dp01的策略通过expand和shrink后, 集群中创建时间最早的机器会被删除掉.
openstack cluster members list mycluster
openstack cluster expand mycluster
openstack cluster members list mycluster
openstack cluster shrink mycluster
openstack cluster members list mycluster
recevier是关联在senlin集群的一个事件池.监控软件可以将给定的当事件或者告警通知senlin,senlin收到这些告警或者通知的话会自动触发预先定义的行为.
创建一个receiver
openstack cluster receiver create --cluste ubuntu_cluster --action CLUSTER_SCALE_IN u_scale_in
使用curl命令调一下这个receiver的alarm_url来触发一下这个receiver
curl -X POST http://172.31.0.20:8778/v1/webhooks/7583517c-0b64-4f81-ad63-8f17af05cd3f/trigger?V=2
检查ubuntu_server集群的状态
openstack cluster member list ubuntu_cluster
创建一个scale out的receiver
openstack cluster receiver create --type webhook --cluster ubuntu_cluster --action CLUSTER_SCALE_OUT so_ubuntu_receiver
验证scale outl
curl -X POST http://172.31.0.20:8778/v1/webhooks/8e719498-3b10-45d1-adc7-1120d4b41cb9/trigger?V=2
查看cluster的node数量
openstack cluster member list ubuntu_cluster
到这里, senlin的基本概念和玩法, 我们差不多就了解了.