How To Move MySQL to an External CentOS/7 Server

The following is a description of the process for moving MySQL server off of an existing CloudBolt appliance and to an external server or virtual machine.

This document assumes that you have a single server running all CloudBolt services and have already created a new CentOS 7.X server for the new MySQL Server to live on.

1. Setting up the new MySQL Server

All processes in this step will be run on the newly created CentOS 7.x server.

1. Import MySQL Yum Repo

yum localinstall -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm 

2. Install MySQL 5.7.X (latest)

yum --disablerepo=mysql80-community --enablerepo=mysql57-community install -y mysql-community-server 

3. Locate temporary root password

grep "temporary password" /var/log/mysqld.log | awk -F ": " '{print $2}' | tail -1  

4. Secure MySQL Instance

mysql_secure_installation --password=YOUR_TEMPORARY_ROOT_PASSWORD

a. Enter new root password when prompted. (To make the transition to the new MySQL server easier you may want to use the same root password from your original CloudBolt instance.)

**** SAVE THIS PASSWORD!!! **** You WILL need the root password for future upgrades and maintenance. 

b. When asked “Change the password for root ? (Press y/Y for Yes, any other key for No) :” type “No” and press enter. This will save the password you just entered above.

c. “Remove anonymous users?”: y

d. “Disallow root login remotely?”: n

e. “Remove test database and access to it?”: y

f. “Reload privilege tables now?": y 

5. Open a MySQL command prompt

mysql -u root -p 

When prompted, enter the root password you created in step 4a.

6. Setup new CloudBolt database and user

a. Create CloudBolt database

CREATE DATABASE cloudbolt;

b. Turn off password validation policy

SET GLOBAL validate_password_policy = 0;

c. Create CloudBolt user account. Replace CloudBolt user and password values with your values.

CREATE USER 'YOUR_CLOUDBOLT_USER'@'%' IDENTIFIED BY 'CLOUDBOLT_USER_PASSWORD'; 

If you would like to keep the same username and password as your existing CloudBolt instance you can find this information on your CloudBolt server in the following file:
/var/opt/cloudbolt/proserv/customer_settings.py

d. Grant access to the CloudBolt database to your newly created user.Replace CloudBolt user with your CloudBolt username

GRANT ALL PRIVILEGES ON cloudbolt.* TO 'YOUR_CLOUDBOLT_USER'@'%'; 

e. Refresh MySQL Privileges

FLUSH PRIVILEGES; 

7. Enable firewall and add rule for port 3306. As sudo run:

systemctl start firewalld
systemctl enable firewalld
firewall-cmd --zone=public --permanent --add-port=3306/tcp 

2. Transfer MySQL data to new MySQL Server

This section involves both the newly created MySQL server and the original CloudBolt server. Make sure to pay attention to which server you are working on.

1. Login into CloudBolt server via SSH

2. Put CloudBolt in maintenance mode

/opt/cloudbolt/utilities/maintenance_mode.py on

3. Dump the existing MySQL database

mysqldump -u root -p --opt cloudbolt > /tmp/cloudbolt.sql 

When prompted, enter the local root password

4. Copy the database dump to new MySQL server

scp /tmp/cloudbolt.sql root@NEW_MYSQL_SERVER_IP:/tmp/​

5. Login to the new MySQL server via SSH

6. Import the database dump

mysql -h 127.0.0.1 -u root -p cloudbolt < /tmp/cloudbolt.sql 

3. Reconfigure CloudBolt to use new MySQL Server

In this section we will reconfigure the CloudBolt service to use the new MySQL Server.

1. Login to the CloudBolt server via SSH

2. Edit the customer settings file to use the new MySQL Server.

a. Open the customer settings file:

vim /var/opt/cloudbolt/proserv/customer_settings.py 

If this file does not exist, then create it and add the following to the file:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'cloudbolt',
        'USER': 'NEW_MYSQL_CB_USER',
        'PASSWORD': 'NEW_MYSQL_CB_USER_PASSWORD',
        'HOST': 'NEW_MYSQL_SERVER_IP', # or hostname if dns enabled
        'PORT': '3306', 
        # uncomment the OPTIONS line to have django create tables
        # using the InnoDB engine as opposed to the MyISAM engine
        # Django will automatically create FK mappings and support
        # transactions when using InnoDB based tables
        # this option only affects the tables at schema creation time
        'OPTIONS': {
            "charset": "utf8mb4",
            "init_command": "SET DEFAULT_STORAGE_ENGINE=INNODB; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED" 
              "
        },
    }
} 

b. Change the HOST, USER, and PASSWORD values to match the new MySQL database and save the file.

3. Take the CloudBolt server out of maintenance mode

/opt/cloudbolt/utilities/maintenance_mode.py off 

4. Restart the CloudBolt server

reboot

If the server cannot be rebooted, restart the Httpd service instead.

service httpd restart

5. Go to CloudBolt URL in browser and ensure that you can login to the CloudBolt service.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.