trove module使用说明
原文来自:https://github.com/openstack/openstack-manuals/blob/master/doc/user-guide/source/database-module-usage.rst
作者:Peter Stachowski <peter@tesora.com>,Trevor McCasland <TM2086@att.com>
翻译:S-tec
为数据库创建和使用模块
要继续执行此文档,我们建议您已安装数据库服务(trove),并将数据库的镜像填入您想要的数据库的类型和版本,并且可以创建和访问数据库。
此示例显示如何创建和应用模块到MySQL 5.6数据库和redis 3.2.6数据库集群。
创建并应用一个模块到一个mysql数据库
创建模块文件和trove模块
如果要应用模块,则必须首先创建模块,并将其注册到trove服务。 用户不能直接将模块应用于trove实例。
这里创建的模块是一个名为ping的演示模块。 它是用于测试目的的基本类型。 要创建它,就像以下一样简单:command:echo命令:
$ echo“message = Module.V1”> ping1.dat
您可以通过执行以下操作来创建应用模块的测试模块和mysql数据库:
$ trove module-create mymod ping ping1.dat --live_update \ --datastore mysql +----------------------+--------------------------------------+ | Property | Value | +----------------------+--------------------------------------+ | apply_order | 5 | | auto_apply | False | | created | 2017-06-02T17:06:21 | | datastore | all | | datastore_id | None | | datastore_version | all | | datastore_version_id | None | | description | None | | id | 0065a8ed-0668-4db5-a4ad-d88d0a166388 | | instance_count | 2 | | is_admin | True | | live_update | True | | md5 | 7f700cc7b99606615f8b51946f6d3228 | | name | mymod | | priority_apply | False | | tenant | eac1e46e5f7840e39012aff46a92073a | | tenant_id | eac1e46e5f7840e39012aff46a92073a | | type | ping | | updated | 2017-06-02T17:06:21 | | visible | True | +----------------------+--------------------------------------+ $ trove create myinst 15 --size 1 --module mymod --datastore mysql +-------------------------+--------------------------------------+ | Property | Value | +-------------------------+--------------------------------------+ | created | 2017-06-02T17:22:24 | | datastore | mysql | | datastore_version | 5.6 | | encrypted_rpc_messaging | True | | flavor | 15 | | id | 6221b30c-8292-4378-b624-c7e9b0f8ba9e | | name | myinst | | region | RegionOne | | server_id | None | | status | BUILD | | tenant_id | eac1e46e5f7840e39012aff46a92073a | | updated | 2017-06-02T17:22:24 | | volume | 1 | | volume_id | None | +-------------------------+--------------------------------------+
显示和列出模块
您可以通过执行以下操作来查看实例上的模块:
$ trove module-query myinst
+-------+------+-----------+---------+--------+-----------+------------------------+------------------------+
| Name | Type | Datastore | Version | Status | Message | Created | Updated |
+-------+------+-----------+---------+--------+-----------+------------------------+------------------------+
| mymod | ping | all | all | OK | Module.V1 | 2017-06-02 17:23:40.50 | 2017-06-02 17:23:40.50 |
+-------+------+-----------+---------+--------+-----------+------------------------+------------------------+
您可以通过执行以下操作来计算每个模块应用的实例:
$ trove module-instance-count mymod
+-------------+---------------------+---------------------+----------------------------------+---------+-------+
| Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count |
+-------------+---------------------+---------------------+----------------------------------+---------+-------+
| mymod | 2017-06-02T17:22:25 | 2017-06-02T17:22:25 | 7f700cc7b99606615f8b51946f6d3228 | True | 1 |
+-------------+---------------------+---------------------+----------------------------------+---------+-------+
您可以通过执行以下操作列出具有特定模块的实例:
$ trove module-instances mymod
+--------------------------------------+--------+-----------+-------------------+--------+-----------+------+-----------+----------------------------------+
| ID | Name | Datastore | Datastore Version | Status | Flavor ID | Size | Region | Tenant ID |
+--------------------------------------+--------+-----------+-------------------+--------+-----------+------+-----------+----------------------------------+
| 6221b30c-8292-4378-b624-c7e9b0f8ba9e | myinst | mysql | 5.6 | ACTIVE | 15 | 1 | RegionOne | eac1e46e5f7840e39012aff46a92073a |
+--------------------------------------+--------+-----------+-------------------+--------+-----------+------+-----------+----------------------------------+
更新并为redis群集创建第二个模块
要更新模块,您应该有另一个文件准备更新模块:
$ echo "message=Module.V2" > ping2.dat $ trove module-update mymod --file ping2.dat +----------------------+--------------------------------------+ | Property | Value | +----------------------+--------------------------------------+ | apply_order | 5 | | auto_apply | False | | created | 2017-06-02T17:06:21 | | datastore | all | | datastore_id | None | | datastore_version | all | | datastore_version_id | None | | description | None | | id | 0065a8ed-0668-4db5-a4ad-d88d0a166388 | | is_admin | True | | live_update | True | | md5 | ba7c204979c8de54be6efb70a17d40b9 | | name | mymod | | priority_apply | False | | tenant | eac1e46e5f7840e39012aff46a92073a | | tenant_id | eac1e46e5f7840e39012aff46a92073a | | type | ping | | updated | 2017-06-02T17:56:12 | | visible | True | +----------------------+--------------------------------------+
现在展示使用redis集群的用法,创建如下:
$ trove cluster-create myclust redis 3.2.6 \ --instance=flavor=15,volume=1,module=mymod \ --instance=flavor=15,volume=1,module=mymod \ --instance=flavor=15,volume=1,module=mymod +-------------------+--------------------------------------+ | Property | Value | +-------------------+--------------------------------------+ | created | 2017-06-02T18:00:17 | | datastore | redis | | datastore_version | 3.2.6 | | id | e4d91ca6-5980-430c-94d0-bf7abc63f712 | | instance_count | 3 | | name | myclust | | task_description | Building the initial cluster. | | task_name | BUILDING | | updated | 2017-06-02T18:00:17 | +-------------------+--------------------------------------+
原来的:command:count命令将显示第一个实例,除非使用了--include_clustered选项。 您可以从每个应用的模块中看到MD5,并且您知道单个实例不是最新的。
$ trove module-instance-count mymod +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | mymod | 2017-06-02T17:22:25 | 2017-06-02T17:22:25 | 7f700cc7b99606615f8b51946f6d3228 | False | 1 | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ $ trove module-instance-count mymod --include_clustered +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | mymod | 2017-06-02T17:22:25 | 2017-06-02T17:22:25 | 7f700cc7b99606615f8b51946f6d3228 | False | 1 | | mymod | 2017-06-02T18:00:18 | 2017-06-02T18:00:18 | ba7c204979c8de54be6efb70a17d40b9 | True | 3 | +-------------+---------------------+---------------------+----------------------------------+---------+-------+
再次更新模块。 通过这样做,它将导致实例报告其模块不是最新的。
$ echo "message=Module.V3" > ping3.dat $ trove module-update mymod --file ping3.dat +----------------------+--------------------------------------+ | Property | Value | +----------------------+--------------------------------------+ | apply_order | 5 | | auto_apply | False | | created | 2017-06-02T17:06:21 | | datastore | all | | datastore_id | None | | datastore_version | all | | datastore_version_id | None | | description | None | | id | 0065a8ed-0668-4db5-a4ad-d88d0a166388 | | is_admin | True | | live_update | True | | md5 | 869744bdd18e306a96c145df562065ab | | name | mymod | | priority_apply | False | | tenant | eac1e46e5f7840e39012aff46a92073a | | tenant_id | eac1e46e5f7840e39012aff46a92073a | | type | ping | | updated | 2017-06-02T18:06:53 | | visible | True | +----------------------+--------------------------------------+ $ trove module-instance-count mymod --include_clustered +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | mymod | 2017-06-02T17:22:25 | 2017-06-02T17:22:25 | 7f700cc7b99606615f8b51946f6d3228 | False | 1 | | mymod | 2017-06-02T18:00:18 | 2017-06-02T18:00:18 | ba7c204979c8de54be6efb70a17d40b9 | False | 3 | +-------------+---------------------+---------------------+----------------------------------+---------+-------+
要更新群集中的实例,可以使用:命令:`trove module-apply`:
$ trove cluster-instances myclust +--------------------------------------+------------------+-----------+------+--------+ | ID | Name | Flavor ID | Size | Status | +--------------------------------------+------------------+-----------+------+--------+ | 393462d5-906d-4214-af0d-538b7f618b2d | myclust-member-2 | 15 | 1 | ACTIVE | | a3fc5326-e1b6-456a-a8b1-08ad6bbb2278 | myclust-member-3 | 15 | 1 | ACTIVE | | cba31d4b-d038-42c2-ab03-56c6c176b49d | myclust-member-1 | 15 | 1 | ACTIVE | +--------------------------------------+------------------+-----------+------+--------+ $ trove module-apply 393462d5-906d-4214-af0d-538b7f618b2d mymod +-------+------+-----------+---------+--------+-----------+ | Name | Type | Datastore | Version | Status | Message | +-------+------+-----------+---------+--------+-----------+ | mymod | ping | all | all | OK | Module.V3 | +-------+------+-----------+---------+--------+-----------+ $ trove module-instance-count mymod --include_clustered +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | mymod | 2017-06-02T17:22:25 | 2017-06-02T17:22:25 | 7f700cc7b99606615f8b51946f6d3228 | False | 1 | | mymod | 2017-06-02T18:00:18 | 2017-06-02T18:00:18 | ba7c204979c8de54be6efb70a17d40b9 | False | 2 | | mymod | 2017-06-02T18:18:37 | 2017-06-02T18:18:37 | 869744bdd18e306a96c145df562065ab | True | 1 | +-------------+---------------------+---------------------+----------------------------------+---------+-------+
对于在例子中体现多样性,请再创建一个实例和模块:
$ trove create myinst_2 15 --size 1 --module mymod +-------------------------+--------------------------------------+ | Property | Value | +-------------------------+--------------------------------------+ | created | 2017-06-02T18:21:56 | | datastore | redis | | datastore_version | 3.2.6 | | encrypted_rpc_messaging | True | | flavor | 15 | | id | cdd85d94-13a0-4d90-89eb-9c05523d2ac6 | | name | myinst_2 | | region | RegionOne | | server_id | None | | status | BUILD | | tenant_id | eac1e46e5f7840e39012aff46a92073a | | updated | 2017-06-02T18:21:56 | | volume | 1 | | volume_id | None | +-------------------------+--------------------------------------+ $ echo "message=Module.V4" > ping4.dat $ trove module-update mymod --file ping4.dat +----------------------+--------------------------------------+ | Property | Value | +----------------------+--------------------------------------+ | apply_order | 5 | | auto_apply | False | | created | 2017-06-02T17:06:21 | | datastore | all | | datastore_id | None | | datastore_version | all | | datastore_version_id | None | | description | None | | id | 0065a8ed-0668-4db5-a4ad-d88d0a166388 | | is_admin | True | | live_update | True | | md5 | 6e2c81c1547d640b4c6e7752ed0e33ab | | name | mymod | | priority_apply | False | | tenant | eac1e46e5f7840e39012aff46a92073a | | tenant_id | eac1e46e5f7840e39012aff46a92073a | | type | ping | | updated | 2017-06-02T18:26:22 | | visible | True | +----------------------+--------------------------------------+
现在我们有两个单独的实例,在模块的各种版本上有3个集群实例,没有最新的
$ trove list +--------------------------------------+----------+-----------+-------------------+--------+-----------+------+-----------+ | ID | Name | Datastore | Datastore Version | Status | Flavor ID | Size | Region | +--------------------------------------+----------+-----------+-------------------+--------+-----------+------+-----------+ | 6221b30c-8292-4378-b624-c7e9b0f8ba9e | myinst | mysql | 5.6 | ACTIVE | 15 | 1 | RegionOne | | cdd85d94-13a0-4d90-89eb-9c05523d2ac6 | myinst_2 | redis | 3.2.6 | ACTIVE | 15 | 1 | RegionOne | +--------------------------------------+----------+-----------+-------------------+--------+-----------+------+-----------+ $ trove module-instance-count mymod --include_clustered +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | mymod | 2017-06-02T17:22:25 | 2017-06-02T17:22:25 | 7f700cc7b99606615f8b51946f6d3228 | False | 1 | | mymod | 2017-06-02T18:00:18 | 2017-06-02T18:00:18 | ba7c204979c8de54be6efb70a17d40b9 | False | 2 | | mymod | 2017-06-02T18:18:37 | 2017-06-02T18:21:57 | 869744bdd18e306a96c145df562065ab | False | 2 | +-------------+---------------------+---------------------+----------------------------------+---------+-------+
创建最新模块时,未使用--include_clustered。 使用:命令:`trove module-reapply`:
$ trove module-reapply mymod --md5=869744bdd18e306a96c145df562065ab --include_clustered $ trove module-instance-count mymod --include_clustered +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | mymod | 2017-06-02T17:22:25 | 2017-06-02T17:22:25 | 7f700cc7b99606615f8b51946f6d3228 | False | 1 | | mymod | 2017-06-02T18:00:18 | 2017-06-02T18:00:18 | ba7c204979c8de54be6efb70a17d40b9 | False | 2 | | mymod | 2017-06-02T18:38:48 | 2017-06-02T18:38:48 | 6e2c81c1547d640b4c6e7752ed0e33ab | True | 2 | +-------------+---------------------+---------------------+----------------------------------+---------+-------+
现在他们都更新了。如果使用--force标志,则可以重新应用已应用的实例。 请注意,唯一更改的是最小和最大更新日期字段。
$ trove module-reapply mymod --md5=6e2c81c1547d640b4c6e7752ed0e33ab --include_clustered --force $ trove module-instance-count mymod --include_clustered +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | mymod | 2017-06-02T17:22:25 | 2017-06-02T17:22:25 | 7f700cc7b99606615f8b51946f6d3228 | False | 1 | | mymod | 2017-06-02T18:00:18 | 2017-06-02T18:00:18 | ba7c204979c8de54be6efb70a17d40b9 | False | 2 | | mymod | 2017-06-02T18:40:45 | 2017-06-02T18:40:46 | 6e2c81c1547d640b4c6e7752ed0e33ab | True | 2 | +-------------+---------------------+---------------------+----------------------------------+---------+-------+
要使每个实例都到当前版本,请使用一些可选参数来控制同时更新多少个实例。 这对于避免潜在的网络问题(如果模块有效负载很大)是有用的。 由于我们没有使用--force标志,最小更新日期不会改变。
$ trove module-reapply mymod --include_clustered --batch_size=1 --delay=3 $ trove module-instance-count mymod --include_clustered +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | Module Name | Min Updated Date | Max Updated Date | Module MD5 | Current | Count | +-------------+---------------------+---------------------+----------------------------------+---------+-------+ | mymod | 2017-06-02T18:40:45 | 2017-06-02T18:44:10 | 6e2c81c1547d640b4c6e7752ed0e33ab | True | 5 | +-------------+---------------------+---------------------+----------------------------------+---------+-------+