CentOS Stream 9
Sponsored Link

OpenStack Antelope : Trove 利用方法2023/04/20

 
OpenStack Database Service(Trove)の利用方法です。
当例では以下のような環境を例に Trove をインストールしています。
------------+--------------------------+--------------------------+------------
            |                          |                          |
        eth0|10.0.0.30             eth0|10.0.0.50             eth0|10.0.0.51
+-----------+-----------+  +-----------+-----------+  +-----------+-----------+
|   [ dlp.srv.world ]   |  | [ network.srv.world ] |  |  [ node01.srv.world ] |
|     (Control Node)    |  |     (Network Node)    |  |     (Compute Node)    |
|                       |  |                       |  |                       |
|  MariaDB    RabbitMQ  |  |      Open vSwitch     |  |        Libvirt        |
|  Memcached  Nginx     |  |     Neutron Server    |  |      Nova Compute     |
|  Keystone   httpd     |  |      OVN-Northd       |  |      Open vSwitch     |
|  Glance     Nova API  |  |  Nginx  iSCSI Target  |  |   OVN Metadata Agent  |
|  Cinder API           |  |     Cinder Volume     |  |     OVN-Controller    |
|                       |  |     Trove Services    |  |                       |
+-----------------------+  +-----------------------+  +-----------------------+

[1] Trove 用の VM イメージを公式サイトからダウンロードして Glance に登録します。
また、[trove.conf] で [cinder_volume_type] に設定したボリュームタイプを作成しておきます。
[root@dlp ~(keystone)]#
wget https://tarballs.opendev.org/openstack/trove/images/trove-master-guest-ubuntu-focal.qcow2

[root@dlp ~(keystone)]#
openstack image create Trove-Ubuntu --file=trove-master-guest-ubuntu-focal.qcow2 --disk-format=qcow2 --container-format=bare --tag=trove --private
[root@dlp ~(keystone)]#
openstack image list

+--------------------------------------+----------------+--------+
| ID                                   | Name           | Status |
+--------------------------------------+----------------+--------+
| 17d50b54-c009-45ff-96ed-58086f79065f | CentOS-Stream9 | active |
| d89904d0-c4ca-47cc-abcc-19aca966ffba | Trove-Ubuntu   | active |
+--------------------------------------+----------------+--------+

[root@dlp ~(keystone)]#
openstack volume type create lvm-trove --private

+-------------+--------------------------------------+
| Field       | Value                                |
+-------------+--------------------------------------+
| description | None                                 |
| id          | 4cee9671-6b97-40f3-96eb-7d9dc866ff9c |
| is_public   | False                                |
| name        | lvm-trove                            |
+-------------+--------------------------------------+
[2] Trove API が稼働するノード (当例では Network ノード) で、使用したいデータストアを登録しておきます。
当例では、MariaDB, MySQL をデータストアとして登録します。
# データストア登録

[root@network ~]#
su -s /bin/bash trove -c "trove-manage datastore_update mariadb ''"

Datastore 'mariadb' updated.
[root@network ~]#
su -s /bin/bash trove -c "trove-manage datastore_update mysql ''"

Datastore 'mysql' updated.
# 各データストアのバージョンを登録

# [d89904d0-***] の部分は [2] で作成した Trove 用のイメージ ID

[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.3 mariadb d89904d0-c4ca-47cc-abcc-19aca966ffba mariadb 1" trove

Datastore version '10.3(10.3)' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.5 mariadb d89904d0-c4ca-47cc-abcc-19aca966ffba mariadb 1" trove

Datastore version '10.5(10.5)' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mysql 8.0 mysql d89904d0-c4ca-47cc-abcc-19aca966ffba mysql 1" trove

Datastore version '8.0(8.0)' updated.
# 各データストアのバージョン用の設定パラメーターを登録

[root@network ~]#
su -s /bin/bash trove -c "trove-manage db_load_datastore_config_parameters mariadb 10.3 /usr/lib/python3.9/site-packages/trove/templates/mariadb/validation-rules.json"

Loading config parameters for datastore (mariadb) version (10.3)
[root@network ~]#
su -s /bin/bash trove -c "trove-manage db_load_datastore_config_parameters mariadb 10.5 /usr/lib/python3.9/site-packages/trove/templates/mariadb/validation-rules.json"

Loading config parameters for datastore (mariadb) version (10.5)
[root@network ~]#
su -s /bin/bash trove -c "trove-manage db_load_datastore_config_parameters mysql 8.0 /usr/lib/python3.9/site-packages/trove/templates/mysql/validation-rules.json"

Loading config parameters for datastore (mysql) version (8.0)
# VM イメージ用の [cloudinit] ファイル作成

[root@network ~]#
mkdir /etc/trove/cloudinit

[root@network ~]#
vi /etc/trove/cloudinit/mariadb.cloudinit
# 新規作成

# [CONTROLLER] に Trove API ホストを指定

#cloud-config
runcmd:
  - echo 'CONTROLLER=network.srv.world' > /etc/trove/controller.conf
  - chmod 644 /etc/trove/controller.conf

[root@network ~]#
cp /etc/trove/cloudinit/mariadb.cloudinit /etc/trove/cloudinit/mysql.cloudinit

[root@network ~]#
chown -R trove /etc/trove/cloudinit

[3] Openstack システムを利用可能な任意のユーザーで認証して、任意のノードで、データベースインスタンスを作成します。
ちなみに、データベースインスタンスは VM イメージ上で Docker コンテナーとして起動します。
[cent@dlp ~(keystone)]$
openstack datastore list

+--------------------------------------+---------+
| ID                                   | Name    |
+--------------------------------------+---------+
| 1e37c0d2-d1a9-448b-91c3-f01a732797e5 | mariadb |
| e1654ce5-86dc-47ab-8b95-a3e3e51fd8b1 | mysql   |
+--------------------------------------+---------+

[cent@dlp ~(keystone)]$
openstack datastore version list mariadb

+--------------------------------------+------+---------+
| ID                                   | Name | Version |
+--------------------------------------+------+---------+
| d0796e3a-f0ed-42e7-899b-5308c08e6e43 | 10.3 | 10.3    |
| b7cb5645-a0f1-43e4-976d-4816c37e4d52 | 10.5 | 10.5    |
+--------------------------------------+------+---------+

[cent@dlp ~(keystone)]$
openstack flavor list

+----+-----------+------+------+-----------+-------+-----------+
| ID | Name      |  RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+-----------+------+------+-----------+-------+-----------+
| 1  | m1.small  | 2048 |   10 |         0 |     1 | True      |
| 2  | m1.medium | 4096 |   10 |         0 |     2 | True      |
| 3  | m1.large  | 8192 |   20 |         0 |     4 | True      |
+----+-----------+------+------+-----------+-------+-----------+

[cent@dlp ~(keystone)]$
openstack network list

+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 913ec733-5a60-4df0-b182-49a393675bca | private | bd8d7602-95e4-4540-971e-a0104dd8b658 |
| c1c6a4c6-776e-4c4f-b557-b9efc4a43ee8 | public  | 68cec7d2-f12f-4272-ac16-8dba6148888b |
+--------------------------------------+---------+--------------------------------------+

# データベースインスタンス作成
[cent@dlp ~(keystone)]$ openstack database instance create MariaDB-105 \
--flavor 2 \
--size 10 \
--nic net-id=913ec733-5a60-4df0-b182-49a393675bca \
--databases MyDB --users serverworld:password \
--datastore mariadb --datastore-version 10.5 \
--is-public \
--allowed-cidr 10.0.0.0/24 \
--allowed-cidr 192.168.100.0/24 
+--------------------------+--------------------------------------+
| Field                    | Value                                |
+--------------------------+--------------------------------------+
| allowed_cidrs            | ['10.0.0.0/24', '192.168.100.0/24']  |
| created                  | 2023-04-20T04:36:18                  |
| datastore                | mariadb                              |
| datastore_version        | 10.5                                 |
| datastore_version_number | 10.5                                 |
| flavor                   | 2                                    |
| id                       | ff74638c-a063-47a6-af67-651ee5ae9f38 |
| name                     | MariaDB-105                          |
| operating_status         |                                      |
| public                   | True                                 |
| region                   | RegionOne                            |
| service_status_updated   | 2023-04-20T04:36:18                  |
| status                   | BUILD                                |
| updated                  | 2023-04-20T04:36:18                  |
| volume                   | 10                                   |
+--------------------------+--------------------------------------+

# 作成中は [BUILD] ステータス

[cent@dlp ~(keystone)]$
openstack database instance list

+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------+-----------+-----------+------+------+
| ID                                   | Name        | Datastore | Datastore Version | Status | Operating Status | Public | Addresses | Flavor ID | Size | Role |
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------+-----------+-----------+------+------+
| ff74638c-a063-47a6-af67-651ee5ae9f38 | MariaDB-105 | mariadb   | 10.5              | BUILD  |                  | True   |           | 2         |   10 |      |
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------+-----------+-----------+------+------+

# 作成が正常に完了すると [HEALTHY] ステータス

[cent@dlp ~(keystone)]$
openstack database instance list

+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------
| ID                                   | Name        | Datastore | Datastore Version | Status | Operating Status | Public 
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------
| ff74638c-a063-47a6-af67-651ee5ae9f38 | MariaDB-105 | mariadb   | 10.5              | ACTIVE | HEALTHY          | True   
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                                                                           | Flavor ID | Size | Role |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.108', 'type': 'private', 'network': '913ec733-5a60-4df0-b182-49a393675bca'}, {'address': '10.0.0.209', 'type': 'public'}] | 2         |   10 |      |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+

# アクセスして動作確認

[cent@dlp ~(keystone)]$
mysql -h 10.0.0.209 -u serverworld -p -e "show variables like 'hostname'; show databases;"

Enter password:
+---------------+--------------+
| Variable_name | Value        |
+---------------+--------------+
| hostname      | 9d11b975e6ec |
+---------------+--------------+
+--------------------+
| Database           |
+--------------------+
| MyDB               |
| information_schema |
+--------------------+

# データベースインスタンスを削除する場合は以下

[cent@dlp ~(keystone)]$
openstack database instance delete MariaDB-105

Request to delete database instance ff74638c-a063-47a6-af67-651ee5ae9f38 has been accepted.
[4] MySQL を起動する場合の設定です。
[cent@dlp ~(keystone)]$
openstack datastore list

+--------------------------------------+---------+
| ID                                   | Name    |
+--------------------------------------+---------+
| 1e37c0d2-d1a9-448b-91c3-f01a732797e5 | mariadb |
| e1654ce5-86dc-47ab-8b95-a3e3e51fd8b1 | mysql   |
+--------------------------------------+---------+

[cent@dlp ~(keystone)]$
openstack datastore version list mysql

+--------------------------------------+------+---------+
| ID                                   | Name | Version |
+--------------------------------------+------+---------+
| bbcdbf43-46d7-434a-b36f-2fdbedc6cec5 | 8.0  | 8.0     |
+--------------------------------------+------+---------+

[cent@dlp ~(keystone)]$ openstack database instance create MySQL-8 \
--flavor 2 \
--size 10 \
--nic net-id=913ec733-5a60-4df0-b182-49a393675bca \
--databases MyDB --users serverworld:password \
--datastore mysql --datastore-version 8.0 \
--is-public \
--allowed-cidr 10.0.0.0/24 \
--allowed-cidr 192.168.100.0/24 

[cent@dlp ~(keystone)]$
openstack database instance list

+--------------------------------------+---------+-----------+-------------------+--------+------------------+--------
| ID                                   | Name    | Datastore | Datastore Version | Status | Operating Status | Public 
+--------------------------------------+---------+-----------+-------------------+--------+------------------+--------
| f3772767-61ac-4dea-9745-78d90a775fc7 | MySQL-8 | mysql     | 8.0               | ACTIVE | HEALTHY          | True   
+--------------------------------------+---------+-----------+-------------------+--------+------------------+--------
+----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                                                                          | Flavor ID | Size | Role |
+----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.77', 'type': 'private', 'network': '913ec733-5a60-4df0-b182-49a393675bca'}, {'address': '10.0.0.243', 'type': 'public'}] | 2         |   10 |      |
+----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+

[cent@dlp ~(keystone)]$
mysql -h 10.0.0.243 -u serverworld -p -e "show variables like 'hostname'; show databases;"

Enter password:
+---------------+--------------+
| Variable_name | Value        |
+---------------+--------------+
| hostname      | d9cb461b8cda |
+---------------+--------------+
+--------------------+
| Database           |
+--------------------+
| MyDB               |
| information_schema |
| performance_schema |
+--------------------+
関連コンテンツ