Red Hat Training

A Red Hat training course is available for Red Hat OpenStack Platform

16.3. Configure Database-as-a-Service

  1. Create a keystone user and add role for the Database-as-a-Service:
    [root@rhosp-trove ~(keystone_admin)]# openstack user create --password trove --email trove@localhost --project services trove
    +------------+----------------------------------+
    | Field      | Value                            |
    +------------+----------------------------------+
    | email      | trove@localhost                  |
    | enabled    | True                             |
    | id         | 8740fd0cba314fe68cf0ca95144d2766 |
    | name       | trove                            |
    | project_id | 42e1efb4bd5e49a49cb2b346078d6325 |
    | username   | trove                            |
    +------------+----------------------------------+
    [root@rhosp-trove ~(keystone_admin)]# openstack role add --project services --user trove admin
    +-----------+----------------------------------+
    | Field     | Value                            |
    +-----------+----------------------------------+
    | domain_id | None                             |
    | id        | 63aa6177a61b44aca25dd88a917353bc |
    | name      | admin                            |
    +-----------+----------------------------------+
    [root@rhosp-trove ~(keystone_admin)]# openstack user role list --project services trove
    +----------------------------------+----------+----------+-------+
    | ID                               | Name     | Project  | User  |
    +----------------------------------+----------+----------+-------+
    | 63aa6177a61b44aca25dd88a917353bc | admin    | services | trove |
    | 9fe2ff9ee4384b1894a90878d3e92bab | _member_ | services | trove |
    +----------------------------------+----------+----------+-------+
  2. Optionally, set up verbose debug information in all configuration files:
    [root@rhosp-trove ~(keystone_admin)]# for conf_file in {trove,trove-conductor,trove-taskmanager,trove-guestagent}; do
    > openstack-config --set /etc/trove/$conf_file.conf DEFAULT verbose True;
    > openstack-config --set /etc/trove/$conf_file.conf DEFAULT debug True;
    > done
  3. Create the api-paste.ini file (if not present):
    [root@rhosp-trove ~(keystone_admin)]# cp /usr/share/trove/trove-dist-paste.ini /etc/trove/api-paste.ini
  4. Update keystone authtoken in api-paste.ini:
    [filter:authtoken]
    paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
    auth_uri = http://127.0.0.1:35357/
    identity_uri = http://127.0.0.1:35357/
    admin_password = TROVE_PASSWORD
    admin_user = trove
    admin_tenant_name = services
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove.conf DEFAULT api_paste_config /etc/trove/api-paste.ini
  5. Update trove.conf with the same information as api-paste.ini:
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove.conf keystone_authtoken auth_uri http://127.0.0.1:35357/
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove.conf keystone_authtoken identity_uri http://127.0.0.1:35357/
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove.conf keystone_authtoken admin_password TROVE_PASSWORD
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove.conf keystone_authtoken admin_user trove
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove.conf keystone_authtoken admin_tenant_name = services
  6. Set up nova_proxy information in trove-taskmanager.conf. This needs to be the actual admin user as the Database-as-a-Service will use this user's credentials to issue nova commands:
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove-taskmanager.conf DEFAULT nova_proxy_admin_user admin
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove-taskmanager.conf DEFAULT nova_proxy_admin_password ADMIN_PASSWORD
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name services
  7. Update the configuration files with RabbitMQ host information:
    [root@rhosp-trove trove(keystone_admin)]# cat /etc/rabbitmq/rabbitmq.config
    % This file managed by Puppet
    % Template Path: rabbitmq/templates/rabbitmq.config
    [
      {rabbit, [
        {default_user, <<"guest">>},
        {default_pass, <<"RABBITMQ_GUEST_PASSWORD">>}
      ]},
    [root@rhosp-trove trove(keystone_admin)]# for conf_file in trove.conf trove-taskmanager.conf trove-conductor.conf ; do
    > openstack-config --set /etc/trove/$conf_file DEFAULT rabbit_host 127.0.0.1;
    > openstack-config --set /etc/trove/$conf_file DEFAULT rabbit_password RABBITMQ_GUEST_PASSWORD;
    > done
  8. Add service URLs to all the configuration files:
    [root@rhosp-trove trove(keystone_admin)]# for conf_file in trove.conf trove-taskmanager.conf trove-conductor.conf ; do
    > openstack-config --set /etc/trove/$conf_file DEFAULT trove_auth_url http://127.0.0.1:5000/v2.0
    > openstack-config --set /etc/trove/$conf_file DEFAULT nova_compute_url http://127.0.0.1:8774/v2
    > openstack-config --set /etc/trove/$conf_file DEFAULT cinder_url http://127.0.0.1:8776/v1
    > openstack-config --set /etc/trove/$conf_file DEFAULT swift_url http://127.0.0.1:8080/v1/AUTH_
    > openstack-config --set /etc/trove/$conf_file DEFAULT sql_connection mysql://trove:trove@127.0.0.1/trove
    > openstack-config --set /etc/trove/$conf_file DEFAULT notifier_queue_hostname 127.0.0.1
    > done
    Note that the commands above add a MySQL connection that does not work yet; those permissions are added next.
  9. Update the task manager configuration with cloud-init information:
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set /etc/trove/trove-taskmanager.conf DEFAULT cloud-init_loaction /etc/trove/cloudinit
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set /etc/trove/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
    [root@rhosp-trove trove(keystone_admin)]# mkdir /etc/trove/cloudinit
  10. Update trove.conf with the default datastore (database type), and set the name of the OpenStack Networking network to which instances will be attached. In this case, that network was named private:
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set /etc/trove/trove.conf DEFAULT default_datastore mysql
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set /etc/trove/trove.conf DEFAULT add_addresses True
    [root@rhosp-trove trove(keystone_admin)]# openstack-config --set /etc/trove/trove.conf DEFAULT network_label_regex ^private$
  11. Create the Database-as-a-Service database and add permissions for the trove user:
    [root@rhosp-trove trove(keystone_admin)]# mysql -u root
    MariaDB [(none)]> create database trove;
    Query OK, 1 row affected (0.00 sec)
    
    MariaDB [(none)]> grant all on trove.* to trove@'localhost' identified by 'TROVE_PASSWORD';
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> grant all on trove.* to trove@'%' identified by 'TROVE_PASSWORD';
    Query OK, 0 rows affected (0.00 sec)
  12. Populate the new database and create the initial datastore:
    [root@rhosp-trove trove(keystone_admin)]# trove-manage db_sync
    [root@rhosp-trove trove(keystone_admin)]# trove-manage datastore_update mysql ''
  13. Create the cloud-init file that will be used with an image.

    Note

    When an instance is created by the Database-as-a-Service, it will use whatever image_id you have set in the database to build the instance. Additionally, based on the datastore specified, it will also now look in /etc/trove/cloudinit/ for a .cloudinit file to attach as user data. For example, if you choose mysql as the datastore for a new instance, nova will look for a mysql.cloudinit file in /etc/trove/cloudinit/ to attach as a user-data script. This is used to register and install MySQL at build time.
    Create the /etc/trove/cloudinit/mysql.cloudinit file with the following content, replacing each occurrence of PASSWORD with a suitable password, RHN_USERNAME, RHN_PASSWORD and POOL_ID with your Red Hat credentials and subscription pool ID, and host SSH public key with the key for passwordless SSH login:
    #!/bin/bash
    
    sed -i'.orig' -e's/without-password/yes/' /etc/ssh/sshd_config
    echo "PASSWORD" | passwd --stdin cloud-user
    echo "PASSWORD" | passwd --stdin root
    systemctl restart sshd
    
    subscription-manager register --username=RHN_USERNAME --password=RHN_PASSWORD
    subscription-manager attach --pool POOL_ID
    subscription-manager repos --disable=*
    subscription-manager repos --enable=rhel-7-server-optional-rpms 
    subscription-manager repos --enable=rhel-7-server-rpms 
    subscription-manager repos --enable=rhel-server-rhscl-7-rpms
    yum install -y openstack-trove-guestagent mysql55
    
    cat << EOF > /etc/trove/trove-guestagent.conf
    rabbit_host = 172.1.0.12
    rabbit_password = RABBITMQ_GUEST_PASSWORD
    nova_proxy_admin_user = admin
    nova_proxy_admin_pass = ADMIN_PASSWORD
    nova_proxy_admin_tenant_name = services
    trove_auth_url = http://172.1.0.12:35357/v2.0
    control_exchange = trove
    EOF
    
    echo "host SSH public key" >> /root/.ssh/authorized_keys
    
    echo "host SSH public key" >> /home/cloud-user/.ssh/authorized_keys
    
    systemctl stop trove-guestagent
    systemctl enable trove-guestagent
    systemctl start trove-guestagent

    Note

    The above is written as a bash script, which is supported by cloud-init. This can also be done using cloud-init's YAML-style layout.
  14. Upload a cloud image, specified as the parameter of the --file option, using glance:
    [root@rhosp-trove trove(keystone_admin)]# glance image-create --name rhel7 \
    > --file image.qcow2 \
    > --disk_format qcow2 \
    > --container_format bare \
    > --is-public True \
    > --owner trove
    
    [root@rhosp-trove trove(keystone_admin)]# glance image-list
    +--------------------------------------+--------+-------------+------------------+-----------+--------+
    | ID                                   | Name   | Disk Format | Container Format | Size      | Status |
    +--------------------------------------+--------+-------------+------------------+-----------+--------+
    | b88fa633-7219-4b80-87fa-300840575f91 | cirros | qcow2       | bare             | 13147648  | active |
    | 9bd48cdf-52b4-4463-8ce7-ce81f44205ae | rhel7  | qcow2       | bare             | 435639808 | active |
    +--------------------------------------+--------+-------------+------------------+-----------+--------+
  15. Update the Database-as-a-Service database with a reference to the Red Hat Enterprise Linux 7 image; use the ID from the output of the previous command:
    [root@rhosp-trove trove(keystone_admin)]# trove-manage --config-file=/etc/trove/trove.conf datastore_version_update \
    > mysql mysql-5.5 mysql 9bd48cdf-52b4-4463-8ce7-ce81f44205ae mysql55 1

    Note

    The syntax is: trove-manage datastore_version_update datastore version_name manager image_id packages active
  16. Create the Database-as-a-Service service using keystone to make OpenStack aware of its presence:
    [root@rhosp-trove trove(keystone_admin)]# openstack service create --name trove \
    > --description "OpenStack DBaaS" \
    > database
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | OpenStack DBaaS                  |
    | enabled     | True                             |
    | id          | b05b564d5ac049f49984a827d820c5a5 |
    | name        | trove                            |
    | type        | database                         |
    +-------------+----------------------------------+
  17. Add URL endpoints for the Database-as-a-Service API:
    [root@rhosp-trove trove(keystone_admin)]# openstack endpoint create \
    > --publicurl 'http://127.0.0.1:8779/v1.0/%(tenant_id)s' \
    > --internalurl 'http://127.0.0.1:8779/v1.0/%(tenant_id)s' \
    > --adminurl 'http://127.0.0.1:8779/v1.0/%(tenant_id)s' \
    > --region RegionOne \
    > database
  18. Start the three Database-as-a-Service services and enable them to start at boot:
    [root@rhosp-trove trove(keystone_admin)]# systemctl start openstack-trove-{api,taskmanager,conductor}
    [root@rhosp-trove trove(keystone_admin)]# systemctl enable openstack-trove-{api,taskmanager,conductor}
    ln -s '/usr/lib/systemd/system/openstack-trove-api.service' '/etc/systemd/system/multi-user.target.wants/openstack-trove-api.service'
    ln -s '/usr/lib/systemd/system/openstack-trove-taskmanager.service' '/etc/systemd/system/multi-user.target.wants/openstack-trove-taskmanager.service'
    ln -s '/usr/lib/systemd/system/openstack-trove-conductor.service' '/etc/systemd/system/multi-user.target.wants/openstack-trove-conductor.service'

    Important

    Run systemctl status openstack-trove-{api,taskmanager,conductor} to make sure these services have started properly. If they have failed due to an error with /var/log/trove, you can run these commands to solve the issue:
    [root@rhosp-trove trove(keystone_admin)]# chown -R trove:trove /var/log/trove
    [root@rhosp-trove trove(keystone_admin)]# systemctl restart openstack-trove-{api,taskmanager,conductor}