CentOS 8
Sponsored Link

OpenStack Victoria : Trove 利用方法2020/11/20

 
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     |   |        L2 Agent       |   |     Nova Compute      |
|  Keystone   Glance    |   |        L3 Agent       |   |      Open vSwitch     |
|  Nova API             |   |     Metadata Agent    |   |        L2 Agent       |
|  Neutron Server       |   |     Cinder Volume     |   |                       |
|  Metadata Agent       |   |   Heat API   API-CFN  |   |                       |
|  Cinder API           |   |   Heat 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 |
+--------------------------------------+--------------+--------+
| 8507b98f-3e9d-4ac9-92f9-9ee8d7f69339 | CentOS8      | active |
| 6244e89a-54a2-472a-a7da-4e2405dbc790 | Trove-Ubuntu | active |
+--------------------------------------+--------------+--------+

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

+-------------+--------------------------------------+
| Field       | Value                                |
+-------------+--------------------------------------+
| description | None                                 |
| id          | 3fcbb4a4-e2a8-4f0a-b13e-f77605b68dea |
| is_public   | False                                |
| name        | lvm-trove                            |
+-------------+--------------------------------------+
[3] Trove API が稼働するノード (当例では Network ノード) で、使用したいデータストアを登録しておきます。
当例では、MariaDB, MySQL, 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 mysql ''"

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

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

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

[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.2 mariadb 6244e89a-54a2-472a-a7da-4e2405dbc790 mariadb 1" trove

Datastore version '10.2' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mariadb 10.3 mariadb 6244e89a-54a2-472a-a7da-4e2405dbc790 mariadb 1" trove

Datastore version '10.3' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update mysql 5.7 mysql 6244e89a-54a2-472a-a7da-4e2405dbc790 mysql 1" trove

Datastore version '5.7' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update postgresql 10 postgresql 6244e89a-54a2-472a-a7da-4e2405dbc790 postgresql 1" trove

Datastore version '10' updated.
[root@network ~]#
su -s /bin/sh -c "trove-manage datastore_version_update postgresql 12 postgresql 6244e89a-54a2-472a-a7da-4e2405dbc790 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 mysql 5.7 /usr/lib/python3.6/site-packages/trove/templates/mysql/validation-rules.json"

Loading config parameters for datastore (mysql) version (5.7)
[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

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

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 9a853623-6cf5-480d-8ada-9bba20a3dd74 | postgresql |
| 9c40555a-6514-4d36-a848-9586016e1b87 | mariadb    |
| e021680c-b145-441c-a5b6-267be09ca7eb | mysql      |
+--------------------------------------+------------+

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

+--------------------------------------+------+
| ID                                   | Name |
+--------------------------------------+------+
| 02dfe4bd-cc37-4a32-bf29-0732d2bdcb6e | 10.2 |
| 317b4967-74ec-42fc-b248-b4d72512995d | 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           |
+--------------------------------------+----------------+--------------------------------------+------------------+
| 7127bc8a-ff8b-4f37-9434-76797539f47f | private-subnet | 8a3e03ec-41a8-487c-8d43-fbffee4a4461 | 192.168.100.0/24 |
| 781dce3f-0bd1-4d17-9f4f-c0962639ecb6 | public-subnet  | fff92352-d109-4a98-a6e4-d56c6cbac5b0 | 10.0.0.0/24      |
+--------------------------------------+----------------+--------------------------------------+------------------+

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

+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 8a3e03ec-41a8-487c-8d43-fbffee4a4461 | private | 7127bc8a-ff8b-4f37-9434-76797539f47f |
| fff92352-d109-4a98-a6e4-d56c6cbac5b0 | public  | 781dce3f-0bd1-4d17-9f4f-c0962639ecb6 |
+--------------------------------------+---------+--------------------------------------+

# データベースインスタンス作成
[root@dlp ~(keystone)]# openstack database instance create MariaDB-103 \
--flavor 0 \
--size 10 \
--nic net-id=8a3e03ec-41a8-487c-8d43-fbffee4a4461 \
--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                 | 2020-11-20T04:18:45                  |
| datastore               | mariadb                              |
| datastore_version       | 10.3                                 |
| encrypted_rpc_messaging | True                                 |
| flavor                  | 0                                    |
| id                      | 87129012-530d-4cda-9420-8777e2a8bfc0 |
| name                    | MariaDB-103                          |
| public                  | True                                 |
| region                  | RegionOne                            |
| server_id               | None                                 |
| service_status_updated  | 2020-11-20T04:18:45                  |
| status                  | BUILD                                |
| tenant_id               | bd0827a1282f45f28c4100b77289eb0a     |
| updated                 | 2020-11-20T04:18:45                  |
| 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 |
+--------------------------------------+-------------+-----------+-------------------+--------+--------+-----------+-----------+------+------+
| 87129012-530d-4cda-9420-8777e2a8bfc0 | MariaDB-103 | mariadb   | 10.3              | BUILD  | True   |           | 0         |   10 |      |
+--------------------------------------+-------------+-----------+-------------------+--------+--------+-----------+-----------+------+------+

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

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

+--------------------------------------+-------------+-----------+-------------------+---------+--------
| ID                                   | Name        | Datastore | Datastore Version | Status  | Public 
+--------------------------------------+-------------+-----------+-------------------+---------+--------
| 87129012-530d-4cda-9420-8777e2a8bfc0 | MariaDB-103 | mariadb   | 10.3              | HEALTHY | True   
+--------------------------------------+-------------+-----------+-------------------+---------+--------
+--------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                        | Flavor ID | Size | Role |
+--------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.146', 'type': 'private'}, {'address': '10.0.0.244', 'type': 'public'}] | 0         |   10 |      |
+--------------------------------------------------------------------------------------------------+-----------+------+------+

# アクセスして動作確認

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

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.3.27-MariaDB-1:10.3.27+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 75817dd0-d6dd-41cf-8623-99447a97cdc0 has been accepted.
[5] MySQL を起動する場合の設定です。
[root@dlp ~(keystone)]#
openstack datastore list

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 9a853623-6cf5-480d-8ada-9bba20a3dd74 | postgresql |
| 9c40555a-6514-4d36-a848-9586016e1b87 | mariadb    |
| e021680c-b145-441c-a5b6-267be09ca7eb | mysql      |
+--------------------------------------+------------+

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

+--------------------------------------+------+
| ID                                   | Name |
+--------------------------------------+------+
| f1a8ae8f-1269-4726-890c-fa341ea3992a | 5.7  |
+--------------------------------------+------+

[root@dlp ~(keystone)]# openstack database instance create MySQL-57 \
--flavor 0 \
--size 10 \
--nic net-id=8a3e03ec-41a8-487c-8d43-fbffee4a4461 \
--databases MyDB --users serverworld:password \
--datastore mysql --datastore-version 5.7 \
--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  | Public 
+--------------------------------------+----------+-----------+-------------------+---------+--------
| 532aa544-3cfb-44b4-ba7b-59940815d5ea | MySQL-57 | mysql     | 5.7               | HEALTHY | True   
+--------------------------------------+----------+-----------+-------------------+---------+--------
+--------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                        | Flavor ID | Size | Role |
+--------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.237', 'type': 'private'}, {'address': '10.0.0.252', 'type': 'public'}] | 0         |   10 |      |
+--------------------------------------------------------------------------------------------------+-----------+------+------+

[root@dlp ~(keystone)]#
mysql -h 10.0.0.252 -u serverworld -p -e "show variables like 'version';"

Enter password:
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| version       | 5.7.32 |
+---------------+--------+
[6] PostgreSQL を起動する場合の設定です。
[root@dlp ~(keystone)]#
openstack datastore list

+--------------------------------------+------------+
| ID                                   | Name       |
+--------------------------------------+------------+
| 9a853623-6cf5-480d-8ada-9bba20a3dd74 | postgresql |
| 9c40555a-6514-4d36-a848-9586016e1b87 | mariadb    |
| e021680c-b145-441c-a5b6-267be09ca7eb | mysql      |
+--------------------------------------+------------+

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

+--------------------------------------+------+
| ID                                   | Name |
+--------------------------------------+------+
| 1478d1cc-584d-46e3-9a47-82c0505af8ff | 10   |
| 45d6f146-80e2-4845-bc9e-7fdd380a7748 | 12   |
+--------------------------------------+------+

[root@dlp ~(keystone)]# openstack database instance create PostgreSQL-12 \
--flavor 0 \
--size 10 \
--nic net-id=8a3e03ec-41a8-487c-8d43-fbffee4a4461 \
--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  | Public 
+--------------------------------------+---------------+------------+-------------------+---------+--------
| 7908f04e-0e4c-430f-8ac8-f4e27f714d59 | PostgreSQL-12 | postgresql | 12                | HEALTHY | True   
+--------------------------------------+---------------+------------+-------------------+---------+--------
+-------------------------------------------------------------------------------------------------+-----------+------+------+
| Addresses                                                                                       | Flavor ID | Size | Role |
+-------------------------------------------------------------------------------------------------+-----------+------+------+
| [{'address': '192.168.100.20', 'type': 'private'}, {'address': '10.0.0.229', 'type': 'public'}] | 0         |   10 |      |
+-------------------------------------------------------------------------------------------------+-----------+------+------+

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

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