Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 8. Configuring an external MySQL database
			This guide provides information for externalizing the MySQL database for Chapter 6, 3scale High Availability and Evaluation templates. This can be done by using the default amp.yml file. This is useful where there are several infrastructure issues, such as network or filesystem, using the default system-mysql pod.
		
The difference between this approach and the one in Chapter 6, 3scale High Availability and Evaluation templates is that this provides a way for externalizing a MySQL database in case Red Hat 3scale API Management was initially using the default amp.yml template.
Red Hat supports 3scale configurations that use an external MySQL database. However, the database itself is not within the scope of support.
Prerequisites
- Access to an OpenShift Container Platform 3.11 cluster using an account with administrator privileges.
- A 3scale instance installation on the OpenShift cluster. See Chapter 2, Installing 3scale on OpenShift.
To configure an external MySQL database for High Availability (HA), perform the steps outlined in the following sections:
8.1. External MySQL database limitations
There are limitations with the process of externalizing your MySQL database:
3scale On-premises versions
It has only been tested and verified on the 2.5 On-premises and 2.6 On-premises versions from 3scale.
MySQL database user
The URL must be in the following format:
				<database_scheme>://<admin_user>:<admin_password>@<database_host>/<database_name>
			
				An <admin_user> must be an existing user in the external database with full permissions on the <database_name> logical database. The <database_name> must be an already existing logical database in the external database.
			
MySQL host
Use the IP address from the external MySQL database instead of the hostname or it will not resolve. For example, use 1.1.1.1 instead of mysql.mydomain.com.
8.2. Externalizing the MySQL database
Use the following steps to fully externalize the MySQL database.
This will cause downtime in the environment while the process is ongoing.
Procedure
- Login to the OpenShift node where your 3scale On-premises instance is hosted and change to its project: - oc login -u <user> <url> oc project <3scale-project> - oc login -u <user> <url> oc project <3scale-project>- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Replace - <user>,- <url>, and- <3scale-project>with your own credentials and the project name.
- Follow the steps below in the order shown to scale down all the pods. This will avoid loss of data. - Stop 3scale On-premises - From the OpenShift web console or from the command line interface (CLI), scale down all the deployment configurations to zero replicas in the following order: - 
								apicast-wildcard-routerandzyncfor versions before 3scale 2.6 orzync-queandzyncfor 3scale 2.6 and above.
- 
								apicast-stagingandapicast-production.
- system-sidekiq,- backend-cron, and- system-sphinx.- 
										3scale 2.3 includes system-resque.
 
- 
										3scale 2.3 includes 
- 
								system-app.
- 
								backend-listenerandbackend-worker.
- backend-redis,- system-memcache,- system-mysql,- system-redis, and- zync-database.- The following example shows how to perform this in the CLI for - apicast-wildcard-routerand- zync:- oc scale dc/apicast-wildcard-router --replicas=0 oc scale dc/zync --replicas=0 - oc scale dc/apicast-wildcard-router --replicas=0 oc scale dc/zync --replicas=0- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow Note- The deployment configuration for each step can be scaled down at the same time. For example, you could scale down - apicast-wildcard-routerand- zynctogether. However, it is better to wait for the pods from each step to terminate before scaling down the ones that follow. The 3scale instance will be completely inaccessible until it is fully started again.
 
- 
								
- To confirm that no pods are running on the 3scale project use the following command: - oc get pod - oc get pod- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - The command should return No resources found. 
- Scale up the database level pods again using the following command: - oc scale dc/{backend-redis,system-memcache,system-mysql,system-redis,zync-database} --replicas=1- oc scale dc/{backend-redis,system-memcache,system-mysql,system-redis,zync-database} --replicas=1- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Ensure that you are able to login to the external MySQL database through the - system-mysqlpod before proceeding with the next steps:- oc rsh system-mysql-<system_mysql_pod_id> mysql -u root -p -h <host> - oc rsh system-mysql-<system_mysql_pod_id> mysql -u root -p -h <host>- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - <system_mysql_pod_id>: The identifier of the system-mysql pod.
- The user should always be root. For more information see External MySQL database limitations. - 
										The CLI will now display mysql>. Type exit, then press return. Type exit again at the next prompt to go back to the OpenShift node console.
 
- 
										The CLI will now display 
 
- Perform a full MySQL dump using the following command: - oc rsh system-mysql-<system_mysql_pod_id> /bin/bash -c "mysqldump -u root --single-transaction --routines --triggers --all-databases" > system-mysql-dump.sql - oc rsh system-mysql-<system_mysql_pod_id> /bin/bash -c "mysqldump -u root --single-transaction --routines --triggers --all-databases" > system-mysql-dump.sql- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - 
								Replace <system_mysql_pod_id> with your unique system-mysqlpod ID .
- Validate that the file - system-mysql-dump.sqlcontains a valid MySQL level dump as in the following example:- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
 
- 
								Replace <system_mysql_pod_id> with your unique 
- Scale down the - system-mysqlpod and leave it with 0 (zero) replicas:- oc scale dc/system-mysql --replicas=0 - oc scale dc/system-mysql --replicas=0- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Find the base64 equivalent of the URL - mysql2://root:<password>@<host>/system, replacing <password> and <host> accordingly:- echo "mysql2://root:<password>@<host>/system" | base64 - echo "mysql2://root:<password>@<host>/system" | base64- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a default 'user'@'%' on the remote MySQL database. It only needs to have SELECT privileges. Also find its base64 equivalents: - echo "user" | base64 echo "<password>" | base64 - echo "user" | base64 echo "<password>" | base64- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Replace <password> with the password for 'user'@'%'.
 
- Perform a backup and edit the OpenShift secret - system-database:- oc get secret system-database -o yaml > system-database-orig.bkp.yml oc edit secret system-database - oc get secret system-database -o yaml > system-database-orig.bkp.yml oc edit secret system-database- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - URL: Replace it with the value from [step-8].
- DB_USER and DB_PASSWORD: Use the values from the previous step for both.
 
- 
						Send system-mysql-dump.sqlto the remote database server and import the dump into it. Use the command to import it:
- Use the command below to send - system-mysql-dump.sqlto the remote database server and import the dump into the server:- mysql -u root -p < system-mysql-dump.sql - mysql -u root -p < system-mysql-dump.sql- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Ensure that a new database called system was created: - mysql -u root -p -se "SHOW DATABASES" - mysql -u root -p -se "SHOW DATABASES"- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Use the following instructions to Start 3scale On-premises, which scales up all the pods in the correct order. - Start 3scale On-premises - 
								backend-redis,system-memcache,system-mysql,system-redis, andzync-database.
- 
								backend-listenerandbackend-worker.
- 
								system-app.
- system-sidekiq,- backend-cron, and- system-sphinx- 
										3scale 2.3 includes system-resque.
 
- 
										3scale 2.3 includes 
- 
								apicast-stagingandapicast-production.
- apicast-wildcard-routerand- zyncfor versions before 3scale 2.6 or- zync-queand- zyncfor 3scale 2.6 and above.- The following example shows how to perform this in the CLI for - backend-redis,- system-memcache,- system-mysql,- system-redis, and- zync-database:- oc scale dc/backend-redis --replicas=1 oc scale dc/system-memcache --replicas=1 oc scale dc/system-mysql --replicas=1 oc scale dc/system-redis --replicas=1 oc scale dc/zync-database --replicas=1 - oc scale dc/backend-redis --replicas=1 oc scale dc/system-memcache --replicas=1 oc scale dc/system-mysql --replicas=1 oc scale dc/system-redis --replicas=1 oc scale dc/zync-database --replicas=1- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - The - system-apppod should now be up and running without any issues.
 
- 
								
- After validation, scale back up the other pods in the order shown.
- 
						Backup the system-mysqlDeploymentConfig object. You may delete after a few days once you are sure everything is running properly. Deletingsystem-mysqlDeploymentConfig avoids any future confusion if this procedure is done again in the future.
8.3. Rolling back
				Perform a rollback procedure if the system-app pod is not fully back online and the root cause for it could not be determined or addressed after following step 14.
			
- Edit the secret - system-databaseusing the original values from- system-database-orig.bkp.yml. See [step-10]:- oc edit secret system-database - oc edit secret system-database- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Replace URL, DB_USER, and DB_PASSWORD with their original values. 
- Scale down all the pods and then scale them back up again, including - system-mysql. The- system-apppod and the other pods to be started after it should be up and running again. Run the following command to confirm all pods are back up and running:- oc get pods -n <3scale-project> - oc get pods -n <3scale-project>- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.4. Additional information
- For more information about 3scale and MySQL database support, see Red Hat 3scale API Management Supported Configurations.