你可以使用配置组来管理数据库配置任务。配置组让你批量设置配置参数,一个或多个数据库。
这个例子假设你已经创建了一个MySQL数据库,向你演示如何使用配置组去配置。尽管该例子仅在一个数据库上设置了一个选项,但你可以用相同的步骤去设置你环境中的多个数据库实例的多个选项。这可以显著节约管理云的时间。
列出可用属性
首先,确定你可以设置哪些配置选项。不同的数据存储版本有不同的配置选项。
列出``mysql``数据存储的所有可用版本的名称和ID:
$ trove datastore-version-list mysql
+--------------------------------------+-----------+
| id | name |
+--------------------------------------+-----------+
| eeb574ce-f49a-48b6-820d-b2959fcd38bb | mysql-5.5 |
+--------------------------------------+-----------+
使用:command:`trove configuration-parameter-list`命令传递数据存储版本ID以获取可用的选项:
$ trove configuration-parameter-list DATASTORE_VERSION_ID
+--------------------------------+---------+---------+----------------------+------------------+
| name | type | min | max | restart_required |
+--------------------------------+---------+---------+----------------------+------------------+
| auto_increment_increment | integer | 1 | 65535 | False |
| auto_increment_offset | integer | 1 | 65535 | False |
| autocommit | integer | 0 | 1 | False |
| bulk_insert_buffer_size | integer | 0 | 18446744073709547520 | False |
| character_set_client | string | | | False |
| character_set_connection | string | | | False |
| character_set_database | string | | | False |
| character_set_filesystem | string | | | False |
| character_set_results | string | | | False |
| character_set_server | string | | | False |
| collation_connection | string | | | False |
| collation_database | string | | | False |
| collation_server | string | | | False |
| connect_timeout | integer | 1 | 65535 | False |
| expire_logs_days | integer | 1 | 65535 | False |
| innodb_buffer_pool_size | integer | 0 | 68719476736 | True |
| innodb_file_per_table | integer | 0 | 1 | True |
| innodb_flush_log_at_trx_commit | integer | 0 | 2 | False |
| innodb_log_buffer_size | integer | 1048576 | 4294967296 | True |
| innodb_open_files | integer | 10 | 4294967296 | True |
| innodb_thread_concurrency | integer | 0 | 1000 | False |
| interactive_timeout | integer | 1 | 65535 | False |
| join_buffer_size | integer | 0 | 4294967296 | False |
| key_buffer_size | integer | 0 | 4294967296 | False |
| local_infile | integer | 0 | 1 | False |
| max_allowed_packet | integer | 1024 | 1073741824 | False |
| max_connect_errors | integer | 1 | 18446744073709547520 | False |
| max_connections | integer | 1 | 65535 | False |
| max_user_connections | integer | 1 | 100000 | False |
| myisam_sort_buffer_size | integer | 4 | 18446744073709547520 | False |
| server_id | integer | 1 | 100000 | True |
| sort_buffer_size | integer | 32768 | 18446744073709547520 | False |
| sync_binlog | integer | 0 | 18446744073709547520 | False |
| wait_timeout | integer | 1 | 31536000 | False |
+--------------------------------+---------+---------+----------------------+------------------+
在此示例中,:command:`trove configuration-parameter-list`命令返回适用与MySQL 5.5选项列表。
创建配置组
配置组包含逗号分隔的键值对列表。每对由一个配置选项及其值组成。
可以使用:command:`trove configuration-create`命令创建配置组。此命令的一般语法为:
$ trove configuration-create NAME VALUES --datastore DATASTORE_NAME
将*VALUES*设置为JSON字典,例如:
{"myFirstKey" : "someString", "mySecondKey" : 1}
此示例创建名为``group1``的配置组。group1``只包含一个键值对,这个键值对将``sync_binlog``选项设置为``1
。
$ trove configuration-create group1 '{"sync_binlog" : 1}' --datastore mysql
+----------------------+--------------------------------------+
| Property | Value |
+----------------------+--------------------------------------+
| datastore_version_id | eeb574ce-f49a-48b6-820d-b2959fcd38bb |
| description | None |
| id | 9a9ef3bc-079b-476a-9cbf-85aa64f898a5 |
| name | group1 |
| values | {"sync_binlog": 1} |
+----------------------+--------------------------------------+
检查现有配置
在使用新创建的配置组之前,请查看``sync_binlog``选项是如何在数据库上配置的。将以下示例连接值替换为连接到数据库的值:
$ mysql -u user7 -ppassword -h 172.16.200.2 myDB7
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql> show variables like 'sync_binlog';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sync_binlog | 0 |
+---------------+-------+
正如你所看到的,对于``myDB7``数据库,sync_binlog``选项当前设置为``0
。
使用配置组更改数据库配置
可以通过将配置组附加到数据库实例来更改数据库的配置。可以使用:command:`trove configuration-attach`命令并传递数据库实例ID和配置组ID的方式来执行此操作。
获取数据库实例ID:
$ trove list
+-------------+------------------+-----------+-------------------+--------+-----------+------+
| id | name | datastore | datastore_version | status | flavor_id | size |
+-------------+------------------+-----------+-------------------+--------+-----------+------+
| 26a265dd... | mysql_instance_7 | mysql | mysql-5.5 | ACTIVE | 6 | 5 |
+-------------+------------------+-----------+-------------------+--------+-----------+------+
获取配置组ID:
$ trove configuration-list
+-------------+--------+-------------+---------------------+
| id | name | description |datastore_version_id |
+-------------+--------+-------------+---------------------+
| 9a9ef3bc... | group1 | None | eeb574ce... |
+-------------+--------+-------------+---------------------+
将配置组附加到数据库实例:
注解
此命令语法仅适用于python-troveclient版本1.0.6和更高版本。早期版本要求传递配置组ID作为第一个参数。
$ trove configuration-attach DB_INSTANCE_ID CONFIG_GROUP_ID
重新检查数据库配置
再次显示``sync_binlog``设置:
mysql> show variables like 'sync_binlog';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sync_binlog | 1 |
+---------------+-------+
正如你所看到的,如``group1``配置组中所指定的,sync_binlog``选项现在设置为``1
。
Conclusion. Using a configuration group to set a single option on a single database is obviously a trivial example. However, configuration groups can provide major efficiencies when you consider that:
Used in this way, configuration groups let you modify your database cloud configuration, on the fly, on a massive scale.
Maintenance. There are also a number of useful maintenance features for working with configuration groups. You can:
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.