CentOS Stream 9
Sponsored Link

OpenStack Dalmatian : Trove 利用方法2024/10/17

 

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-jammy.qcow2

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

+--------------------------------------+----------------+--------+
| ID                                   | Name           | Status |
+--------------------------------------+----------------+--------+
| 75e0d976-4075-4488-8f26-87d4a50aebe9 | CentOS-Stream9 | active |
| 664d445f-5a09-4a48-8ad1-80f1b6754ef8 | Trove-Ubuntu   | active |
+--------------------------------------+----------------+--------+

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

+-------------+--------------------------------------+
| Field       | Value                                |
+-------------+--------------------------------------+
| description | None                                 |
| id          | cd4855f4-51bf-477f-b392-d01a4115770c |
| is_public   | False                                |
| name        | lvm-trove                            |
+-------------+--------------------------------------+
[2] Trove API が稼働するノード (当例では Network ノード) で、使用したいデータストアを登録しておきます。
当例では、MariaDB, PostgreSQL をデータストアとして登録します。
# データストア登録

[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 postgresql ''"

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

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

[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.5 mariadb 664d445f-5a09-4a48-8ad1-80f1b6754ef8 mariadb 1" trove

Datastore version '10.5(10.5)' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update postgresql 12 postgresql 664d445f-5a09-4a48-8ad1-80f1b6754ef8 postgresql 1" trove

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

[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 postgresql 12 /usr/lib/python3.9/site-packages/trove/templates/postgresql/validation-rules.json"

Loading config parameters for datastore (postgresql) version (12)
# 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/postgresql.cloudinit

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

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

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 5b10bd2b-0e15-4386-9f12-65fbcb32714c | mariadb    |
| c7dd83c7-e552-4bf4-9a55-091957ecf4e6 | postgresql |
+--------------------------------------+------------+

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

+--------------------------------------+------+---------+
| ID                                   | Name | Version |
+--------------------------------------+------+---------+
| 07463666-87de-410b-9983-4b75bbc24e26 | 10.5 | 10.5    |
+--------------------------------------+------+---------+

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

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

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

+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 7302c07e-c543-4a85-a955-d6cc8a4e4011 | public  | 8fbc394a-e821-47d8-8efc-d5f7c7db0ff8 |
| aa200aa9-ddb2-4d89-aa37-ce3e3a939421 | private | dfb0949d-d775-4c17-9b07-b01ac7d71aac |
+--------------------------------------+---------+--------------------------------------+

# データベースインスタンス作成
[cent@dlp ~(keystone)]$ openstack database instance create MariaDB-105 \
--flavor 2 \
--size 10 \
--nic net-id=aa200aa9-ddb2-4d89-aa37-ce3e3a939421 \
--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                  | 2024-10-17T00:17:47                  |
| datastore                | mariadb                              |
| datastore_version        | 10.5                                 |
| datastore_version_number | 10.5                                 |
| flavor                   | 2                                    |
| id                       | 46a0f7de-8c3e-4f35-8816-9603fde3bc69 |
| name                     | MariaDB-105                          |
| operating_status         |                                      |
| public                   | True                                 |
| region                   | RegionOne                            |
| service_status_updated   | 2024-10-17T00:17:47                  |
| status                   | BUILD                                |
| updated                  | 2024-10-17T00:17:47                  |
| volume                   | 10                                   |
+--------------------------+--------------------------------------+

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

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

+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------+-----------+-----------+------+------+
| ID                                   | Name        | Datastore | Datastore Version | Status | Operating Status | Public | Addresses | Flavor ID | Size | Role |
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------+-----------+-----------+------+------+
| 46a0f7de-8c3e-4f35-8816-9603fde3bc69 | 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 
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------
| 46a0f7de-8c3e-4f35-8816-9603fde3bc69 | MariaDB-105 | mariadb   | 10.5              | ACTIVE | HEALTHY          | True   
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                                                                           | Flavor ID | Size | Role |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.176', 'type': 'private', 'network': 'aa200aa9-ddb2-4d89-aa37-ce3e3a939421'}, {'address': '10.0.0.239', 'type': 'public'}] | 2         |   10 |      |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+

# アクセスして動作確認

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

Enter password:
+---------------+--------------+
| Variable_name | Value        |
+---------------+--------------+
| hostname      | 44cca4e252f0 |
+---------------+--------------+
+--------------------+
| Database           |
+--------------------+
| MyDB               |
| information_schema |
+--------------------+

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

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

Request to delete database instance 46a0f7de-8c3e-4f35-8816-9603fde3bc69 has been accepted.
[4] PostgreSQL を起動する場合の設定です。
[cent@dlp ~(keystone)]$
openstack datastore list

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 5b10bd2b-0e15-4386-9f12-65fbcb32714c | mariadb    |
| c7dd83c7-e552-4bf4-9a55-091957ecf4e6 | postgresql |
+--------------------------------------+------------+

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

+--------------------------------------+------+---------+
| ID                                   | Name | Version |
+--------------------------------------+------+---------+
| 6733783c-ea13-4d35-a6e5-4ac777410d0b | 12   | 12      |
+--------------------------------------+------+---------+

[cent@dlp ~(keystone)]$ openstack database instance create PostgreSQL-12 \
--flavor 2 \
--size 10 \
--nic net-id=aa200aa9-ddb2-4d89-aa37-ce3e3a939421 \
--databases MyDB --users serverworld:password \
--datastore postgresql --datastore-version 12 \
--datastore-version-number 12 --is-public \
--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 
+--------------------------------------+---------------+------------+-------------------+--------+------------------+--------
| 1d988206-329c-4f3d-b957-7911f627065f | PostgreSQL-12 | postgresql | 12                | ACTIVE | HEALTHY          | True   
+--------------------------------------+---------------+------------+-------------------+--------+------------------+--------
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                                                                           | Flavor ID | Size | Role |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.132', 'type': 'private', 'network': 'aa200aa9-ddb2-4d89-aa37-ce3e3a939421'}, {'address': '10.0.0.242', 'type': 'public'}] | 2         |   10 |      |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+

[cent@dlp ~(keystone)]$
psql -h 10.0.0.242 -d MyDB -U serverworld -c "SELECT version();"

Password for user serverworld:
                                                        version
-----------------------------------------------------------------------------------------------------------------------
 PostgreSQL 12.20 (Debian 12.20-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
(1 row)
関連コンテンツ