Ubuntu 20.04
Sponsored Link

OpenStack Xena : Trove 利用方法2021/10/08

 
OpenStack Database Service(Trove)の利用方法です。
当例では以下のような環境を例に Trove をインストールしています。
------------+---------------------------+---------------------------+------------
            |                           |                           |
        eth0|10.0.0.30              eth0|10.0.0.50              eth0|10.0.0.51
+-----------+-----------+   +-----------+-----------+   +-----------+-----------+
|    [ Control Node ]   |   |    [ Storage 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           |   |    Heat API/Engine    |   |     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-bionic.qcow2

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

+--------------------------------------+--------------+--------+
| ID                                   | Name         | Status |
+--------------------------------------+--------------+--------+
| 8fb56d4f-c7b5-4785-afd0-260a64eec462 | Trove-Ubuntu | active |
| ba8781c7-85ef-4872-957e-2c27b55275b2 | Ubuntu2004   | active |
+--------------------------------------+--------------+--------+

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

+-------------+--------------------------------------+
| Field       | Value                                |
+-------------+--------------------------------------+
| description | None                                 |
| id          | 54663030-1415-4182-a419-5292b4211d4c |
| 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.
# 各データストアのバージョンを登録

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

root@network:~#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.2 mariadb 8fb56d4f-c7b5-4785-afd0-260a64eec462 mariadb 1" trove

Datastore version '10.2(10.2)' updated.
root@network:~#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.3 mariadb 8fb56d4f-c7b5-4785-afd0-260a64eec462 mariadb 1" trove

Datastore version '10.3(10.3)' updated.
root@network:~#
su -s /bin/sh -c "trove-manage datastore_version_update postgresql 10 postgresql 8fb56d4f-c7b5-4785-afd0-260a64eec462 postgresql 1" trove

Datastore version '10(10)' updated.
root@network:~#
su -s /bin/sh -c "trove-manage datastore_version_update postgresql 12 postgresql 8fb56d4f-c7b5-4785-afd0-260a64eec462 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.2 /usr/lib/python3/dist-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/dist-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/dist-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/dist-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/postgresql.cloudinit

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

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

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 0f247ec5-29e9-4458-8b47-c056386ebf3b | mariadb    |
| 55237ed4-eeec-4907-b800-6d8137cace8e | postgresql |
+--------------------------------------+------------+

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

+--------------------------------------+------+---------+
| ID                                   | Name | Version |
+--------------------------------------+------+---------+
| 3ebbf164-a2be-4db1-965b-649802f355e1 | 10.2 | 10.2    |
| 655195cb-ec2e-42e6-b09e-370e0bd5f3da | 10.3 | 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           |
+--------------------------------------+----------------+--------------------------------------+------------------+
| 694a93ec-762f-4c2e-b8f3-4f5aa72b631e | public-subnet  | 35816d4c-fa30-4901-8aa5-3749970fa706 | 10.0.0.0/24      |
| 77ab8a8b-9cca-4f4a-90c6-a61f8a58f08d | private-subnet | a5d44a8a-4980-4c19-a53a-26af6aabd732 | 192.168.100.0/24 |
+--------------------------------------+----------------+--------------------------------------+------------------+

root@dlp ~(keystone)#
openstack network list

+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 35816d4c-fa30-4901-8aa5-3749970fa706 | public  | 694a93ec-762f-4c2e-b8f3-4f5aa72b631e |
| a5d44a8a-4980-4c19-a53a-26af6aabd732 | private | 77ab8a8b-9cca-4f4a-90c6-a61f8a58f08d |
+--------------------------------------+---------+--------------------------------------+

# データベースインスタンス作成
root@dlp ~(keystone)# openstack database instance create MariaDB-103 \
--flavor 0 \
--size 10 \
--nic net-id=a5d44a8a-4980-4c19-a53a-26af6aabd732 \
--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-10-08T06:26:19                  |
| datastore                | mariadb                              |
| datastore_version        | 10.3                                 |
| datastore_version_number | 10.3                                 |
| encrypted_rpc_messaging  | True                                 |
| flavor                   | 0                                    |
| id                       | 43a6e4a3-d7e6-4807-99d5-2f3d7964caee |
| name                     | MariaDB-103                          |
| operating_status         |                                      |
| public                   | True                                 |
| region                   | RegionOne                            |
| server_id                | None                                 |
| service_status_updated   | 2021-10-08T06:26:19                  |
| status                   | BUILD                                |
| tenant_id                | f4431102f2d9415590e3ac11c616858a     |
| updated                  | 2021-10-08T06:26:19                  |
| volume                   | 10                                   |
| volume_id                | None                                 |
+--------------------------+--------------------------------------+

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

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

+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------+-----------+-----------+------+------+
| ID                                   | Name        | Datastore | Datastore Version | Status | Operating Status | Public | Addresses | Flavor ID | Size | Role |
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------+-----------+-----------+------+------+
| 43a6e4a3-d7e6-4807-99d5-2f3d7964caee | MariaDB-103 | mariadb   | 10.3              | BUILD  |                  | True   |           | 0         |   10 |      |
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------+-----------+-----------+------+------+

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

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

+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------
| ID                                   | Name        | Datastore | Datastore Version | Status | Operating Status | Public 
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------
| 43a6e4a3-d7e6-4807-99d5-2f3d7964caee | MariaDB-103 | mariadb   | 10.3              | ACTIVE | HEALTHY          | True   
+--------------------------------------+-------------+-----------+-------------------+--------+------------------+--------
+---------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                                                                         | Flavor ID | Size | Role |
+---------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.7', 'type': 'private', 'network': 'a5d44a8a-4980-4c19-a53a-26af6aabd732'}, {'address': '10.0.0.201', 'type': 'public'}] | 0         |   10 |      |
+---------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+

# アクセスして動作確認

root@dlp ~(keystone)#
mysql -h 10.0.0.201 -u serverworld -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 21
Server version: 10.3.31-MariaDB-1:10.3.31+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      | 33633c23a2af |
+---------------+--------------+
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 43a6e4a3-d7e6-4807-99d5-2f3d7964caee has been accepted.
[4] PostgreSQL を起動する場合の設定です。
root@dlp ~(keystone)#
openstack datastore list

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 0f247ec5-29e9-4458-8b47-c056386ebf3b | mariadb    |
| 55237ed4-eeec-4907-b800-6d8137cace8e | postgresql |
+--------------------------------------+------------+

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

+--------------------------------------+------+---------+
| ID                                   | Name | Version |
+--------------------------------------+------+---------+
| 0ee64425-a2f2-4473-b272-ecd3d1cc8073 | 10   | 10      |
| ed0d745a-3cc7-465d-b228-4a01992a51be | 12   | 12      |
+--------------------------------------+------+---------+

root@dlp ~(keystone)# openstack database instance create PostgreSQL-12 \
--flavor 0 \
--size 10 \
--nic net-id=a5d44a8a-4980-4c19-a53a-26af6aabd732 \
--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 

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

+--------------------------------------+---------------+------------+-------------------+--------+------------------+--------
| ID                                   | Name          | Datastore  | Datastore Version | Status | Operating Status | Public 
+--------------------------------------+---------------+------------+-------------------+--------+------------------+--------
| 1a99b179-9d12-45f5-b071-30d25bf38d63 | PostgreSQL-12 | postgresql | 12                | ACTIVE | HEALTHY          | True   
+--------------------------------------+---------------+------------+-------------------+--------+------------------+--------
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                                                                           | Flavor ID | Size | Role |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.231', 'type': 'private', 'network': 'a5d44a8a-4980-4c19-a53a-26af6aabd732'}, {'address': '10.0.0.232', 'type': 'public'}] | 0         |   10 |      |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+------+

root@dlp ~(keystone)#
psql -h 10.0.0.232 -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)
関連コンテンツ