CentOS Stream 8
Sponsored Link

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

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

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

+--------------------------------------+-----------------+--------+
| ID                                   | Name            | Status |
+--------------------------------------+-----------------+--------+
| 4d7293af-be5b-471b-9507-2a32f1955b11 | CentOS-Stream-8 | active |
| b625e80e-14c5-4e67-babc-378f9bf5e819 | Trove-Ubuntu    | active |
+--------------------------------------+-----------------+--------+

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

+-------------+--------------------------------------+
| Field       | Value                                |
+-------------+--------------------------------------+
| description | None                                 |
| id          | f019a9b4-5f7e-4d86-b9b9-cc38bc84ac61 |
| 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.
# 各データストアのバージョンを登録

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

[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.2 mariadb b625e80e-14c5-4e67-babc-378f9bf5e819 mariadb 1" trove

Datastore version '10.2' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.3 mariadb b625e80e-14c5-4e67-babc-378f9bf5e819 mariadb 1" trove

Datastore version '10.3' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update postgresql 10 postgresql b625e80e-14c5-4e67-babc-378f9bf5e819 postgresql 1" trove

Datastore version '10' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update postgresql 12 postgresql b625e80e-14c5-4e67-babc-378f9bf5e819 postgresql 1" trove

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

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

Loading config parameters for datastore (mariadb) version (10.2)
[root@network ~]#
su -s /bin/bash trove -c "trove-manage db_load_datastore_config_parameters mariadb 10.3 /usr/lib/python3.6/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 postgresql 10 /usr/lib/python3.6/site-packages/trove/templates/postgresql/validation-rules.json"

Loading config parameters for datastore (postgresql) version (10)
[root@network ~]#
su -s /bin/bash trove -c "trove-manage db_load_datastore_config_parameters postgresql 12 /usr/lib/python3.6/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
write_files:
  - path: /etc/trove/controller.conf
    content: |
      CONTROLLER=10.0.0.50
runcmd:
  - chmod 644 /etc/trove/controller.conf

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

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

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

[3] 任意のノードで、データベースインスタンスを作成します。
例として、[admin] ユーザーで MariaDB データベースインスタンスを作成します。
(デフォルトポリシーでは [admin] ユーザーのみがインスタンス作成可)
ちなみに、データベースインスタンスは VM イメージ上で Docker コンテナーとして起動します。
[root@dlp ~(keystone)]#
openstack datastore list

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 6928b0c6-8b36-48e6-8a87-127b4a412ff8 | postgresql |
| 9a7c8915-f11f-49cd-ada5-6f3ddb6bb77d | mariadb    |
+--------------------------------------+------------+

[root@dlp ~(keystone)]#
openstack datastore version list mariadb

+--------------------------------------+------+
| ID                                   | Name |
+--------------------------------------+------+
| fcc41f71-fb87-43bc-bbe2-58455879f60f | 10.2 |
| 6e592fb0-de8d-4795-b2a2-65a1e2da6f3e | 10.3 |
+--------------------------------------+------+

[root@dlp ~(keystone)]#
openstack flavor list

+----+----------+------+------+-----------+-------+-----------+
| ID | Name     |  RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+----------+------+------+-----------+-------+-----------+
| 0  | m1.small | 2048 |   10 |         0 |     1 | True      |
+----+----------+------+------+-----------+-------+-----------+

[root@dlp ~(keystone)]#
openstack subnet list

+--------------------------------------+----------------+--------------------------------------+------------------+
| ID                                   | Name           | Network                              | Subnet           |
+--------------------------------------+----------------+--------------------------------------+------------------+
| 63c29d7b-e870-477d-819b-e5dfe41af1d0 | public-subnet  | ea9725cf-a8bc-4eb5-a374-7d7d0e11453c | 10.0.0.0/24      |
| 94afb0cc-1d58-4615-8fef-8852271bfc16 | private-subnet | 9f53c3b1-ec6b-499d-854a-588d3b0b96d6 | 192.168.100.0/24 |
+--------------------------------------+----------------+--------------------------------------+------------------+

[root@dlp ~(keystone)]#
openstack network list

+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 9f53c3b1-ec6b-499d-854a-588d3b0b96d6 | private | 94afb0cc-1d58-4615-8fef-8852271bfc16 |
| ea9725cf-a8bc-4eb5-a374-7d7d0e11453c | public  | 63c29d7b-e870-477d-819b-e5dfe41af1d0 |
+--------------------------------------+---------+--------------------------------------+

# データベースインスタンス作成
[root@dlp ~(keystone)]# openstack database instance create MariaDB-103 \
--flavor 0 \
--size 10 \
--nic net-id=9f53c3b1-ec6b-499d-854a-588d3b0b96d6 \
--databases MyDB --users serverworld:password \
--datastore mariadb --datastore-version 10.3 \
--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                 | 2021-03-29T06:44:56                  |
| datastore               | mariadb                              |
| datastore_version       | 10.3                                 |
| encrypted_rpc_messaging | True                                 |
| flavor                  | 0                                    |
| id                      | d4a77738-727b-4555-9619-42a41c53b9eb |
| name                    | MariaDB-103                          |
| public                  | True                                 |
| region                  | RegionOne                            |
| server_id               | None                                 |
| service_status_updated  | 2021-03-29T06:44:56                  |
| status                  | BUILD                                |
| tenant_id               | b9bf51c6436a4c5aa7a2df05688afb49     |
| updated                 | 2021-03-29T06:44:56                  |
| volume                  | 10                                   |
| volume_id               | None                                 |
+-------------------------+--------------------------------------+

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

[root@dlp ~(keystone)]#
openstack database instance list

+--------------------------------------+-------------+-----------+-------------------+--------+--------+-----------+-----------+------+------+
| ID                                   | Name        | Datastore | Datastore Version | Status | Public | Addresses | Flavor ID | Size | Role |
+--------------------------------------+-------------+-----------+-------------------+--------+--------+-----------+-----------+------+------+
| d4a77738-727b-4555-9619-42a41c53b9eb | MariaDB-103 | mariadb   | 10.3              | BUILD  | True   |           | 0         |   10 |      |
+--------------------------------------+-------------+-----------+-------------------+--------+--------+-----------+-----------+------+------+

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

[root@dlp ~(keystone)]#
openstack database instance list

+--------------------------------------+-------------+-----------+-------------------+---------+--------
| ID                                   | Name        | Datastore | Datastore Version | Status  | Public 
+--------------------------------------+-------------+-----------+-------------------+---------+--------
| d4a77738-727b-4555-9619-42a41c53b9eb | MariaDB-103 | mariadb   | 10.3              | HEALTHY | True   
+--------------------------------------+-------------+-----------+-------------------+---------+--------
+--------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                        | Flavor ID | Size | Role |
+--------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.177', 'type': 'private'}, {'address': '10.0.0.224', 'type': 'public'}] | 0         |   10 |      |
+--------------------------------------------------------------------------------------------------+-----------+------+------+

# アクセスして動作確認

[root@dlp ~(keystone)]#
mysql -h 10.0.0.224 -u serverworld -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.28-MariaDB-1:10.3.28+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'hostname'; 
+---------------+-------------+
| Variable_name | Value       |
+---------------+-------------+
| hostname      | mariadb-103 |
+---------------+-------------+
1 row in set (0.003 sec)

MariaDB [(none)]> show databases; 
+--------------------+
| Database           |
+--------------------+
| MyDB               |
| information_schema |
+--------------------+
2 rows in set (0.003 sec)

MariaDB [(none)]> exit
Bye

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

[root@dlp ~(keystone)]#
openstack database instance delete MariaDB-103

Request to delete database instance d4a77738-727b-4555-9619-42a41c53b9eb has been accepted.
[4] PostgreSQL を起動する場合の設定です。
[root@dlp ~(keystone)]#
openstack datastore list

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 6928b0c6-8b36-48e6-8a87-127b4a412ff8 | postgresql |
| 9a7c8915-f11f-49cd-ada5-6f3ddb6bb77d | mariadb    |
+--------------------------------------+------------+

[root@dlp ~(keystone)]#
openstack datastore version list postgresql

+--------------------------------------+------+
| ID                                   | Name |
+--------------------------------------+------+
| 1847b8b7-7344-4e77-9910-37d79f0cdffc | 10   |
| 708f1c38-3ead-4123-98d0-75181d65c57a | 12   |
+--------------------------------------+------+

[root@dlp ~(keystone)]# openstack database instance create PostgreSQL-12 \
--flavor 0 \
--size 10 \
--nic net-id=9f53c3b1-ec6b-499d-854a-588d3b0b96d6 \
--databases MyDB --users serverworld:password \
--datastore postgresql --datastore-version 12 \
--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                 | 2021-03-29T06:56:36                  |
| datastore               | postgresql                           |
| datastore_version       | 12                                   |
| encrypted_rpc_messaging | True                                 |
| flavor                  | 0                                    |
| id                      | cf8eb410-7ed1-47ae-a897-c25d93332124 |
| name                    | PostgreSQL-12                        |
| public                  | True                                 |
| region                  | RegionOne                            |
| server_id               | None                                 |
| service_status_updated  | 2021-03-29T06:56:36                  |
| status                  | BUILD                                |
| tenant_id               | b9bf51c6436a4c5aa7a2df05688afb49     |
| updated                 | 2021-03-29T06:56:36                  |
| volume                  | 10                                   |
| volume_id               | None                                 |
+-------------------------+--------------------------------------+

[root@dlp ~(keystone)]#
openstack database instance list

+--------------------------------------+---------------+------------+-------------------+---------+--------
| ID                                   | Name          | Datastore  | Datastore Version | Status  | Public 
+--------------------------------------+---------------+------------+-------------------+---------+--------
| cf8eb410-7ed1-47ae-a897-c25d93332124 | PostgreSQL-12 | postgresql | 12                | HEALTHY | True   
+--------------------------------------+---------------+------------+-------------------+---------+--------
+-------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                       | Flavor ID | Size | Role |
+-------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.34', 'type': 'private'}, {'address': '10.0.0.201', 'type': 'public'}] | 0         |   10 |      |
+-------------------------------------------------------------------------------------------------+-----------+------+------+

[root@dlp ~(keystone)]#
psql -h 10.0.0.201 -d MyDB -U serverworld -c "SELECT version();"

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