Set up Database Replication in Apache CloudStack

Database Replication in Apache CloudStack
This tutorial explains the steps to implement database (MySQL) replication in Apache CloudStack.

 

Apache CloudStack is a free and open-source Infrastructure as a Service (IaaS) platform that orchestrates and manages pools of the network, storage, and other computer resources to build a private or public IaaS compute cloud. Apache CloudStack allows any IT service provider to offer public cloud services to their customers. It can also be used by companies who wish to offer hybrid and private cloud services to their users. Apache CloudStack has a computer function that assigns virtual machines (VMs) to an individual server. This virtual machine controls the switches that help manage and create block storage systems, logical networks, and a cloud computing management interface. The cloud computing management interface offered by CloudStack can support all of the software components. Apache CloudStack also allows administrators to manage and release large 0networks of virtual machines that can run many hypervisors. With the help of Apache CloudStack, users can allow end-users to provision resources and set up an on-demand elastic cloud computing service.           

Database replication is the electronic copying of data from a database in a system or server to a database in another system or server. Data replication makes sure that all the users share the same level of information. The result of database replication is a distributed database from which users can quickly access relevant data for their tasks without interfering with the work of other users. Various elements in the server contribute to the overall process of managing and creating database replication.

Database replication can either be an ongoing process or a single occurrence. Database replication involves all data sources in an organization’s distributed infrastructure. The distributed management system of the organization is used to replicate and adequately distribute the data amongst all the sources. The database replication involves one or more applications that connect a primary storage location with a secondary location that is often off-site. Those secondary and primary storage locations are most often individual source databases, such as MySQL, Microsoft SQL, Oracle, MongoDB, and data warehouses that amalgamate data from these sources, offering analytics and storage services on larger quantities of data. In this tutorial, we will learn the steps to implement MySQL database replication in Apache CloudStack. 

 

Implement Database Replication 

Apache CloudStack supports database replication from one MySQL node to another node. Data replication is achieved in CloudStack using standard MySQL replication. Users can perform data replication to secure the MySQL server and avoid data loss.MySQL replication is implemented using a master and slave model. The master is the Management Servers node that is configured to use. The slave is a standby node that accepts all write operations from the master and stores them locally as a redundant copy of the database. To implement MySQL replication in Apache CloudStack, follow the below steps:

 

> > Note: Creating a database replica is not a backup solution. Users should develop a backup procedure for the MySQL data that is distinct from replication to avoid data loss fully.

 

1. Make sure that the installation is fresh and there is no data available in the master node.

2. Open the my.cnf file on the master and add the following lines in the [mysqld] section below the datadir.

 

log_bin=mysql-bin
server_id=1

 

 >> Note: Make sure that the server_id mentioned in the above lines is unique with respect to other servers. The recommended way to achieve unique server_id’s is to give the master an ID of 1 and the slave a sequential number greater than 1, such as 2, 3, etc.

 

3. Save the file and execute the following command to restart the MySQL service. 

 

On RHEL/CentOS systems, use:
# service mysqld restart
On Debian/Ubuntu systems, use:
# service mysql restart

 

4. After the restart, create a database replication account on the master and give it privileges. In this tutorial, we will use the “data-repl” user with the password “passwd”. We assume that both the master and slave run on the 172.16.1.0/24 network.

 

# mysql -u root
mysql> create user 'data-repl'@'172.16.1.%' identified by 'passwd';
mysql> grant replication slave on *.* TO 'data-repl'@'172.16.1.%';
mysql> flush privileges;
mysql> flush tables with read lock;

 

5. Next, leave the current MySQL session running and open a new shell.

6. In the new shell, start a second MySQL session and retrieve the current position of the MySQL database.

 

# mysql -u root
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      412 |              |                  |
+------------------+----------+--------------+------------------+

 

7. Make a note of the file and the position detail returned by the instance.

8. Exit from this new MySQLsession and complete the master setup.

9. Return to the first session on the master.

10. After that, release the locks and exit MySQL.

 

mysql> unlock tables;

 

11. Next, install and configure the slave. Run the following commands on the slave.

 

On RHEL/CentOS systems, use:
# yum install mysql-server
# chkconfig mysqld on
On Debian/Ubuntu systems, use:
# apt install mysql-server
# chkconfig mysqld on

 

12. Next, edit the my.cnf file on slave and add the following lines in the [mysqld] section below datadir.

 

server_id=2
innodb_rollback_on_timeout=1
innodb_lock_wait_timeout=600

 

 13. Save the file and restart MySQL. 

 

On RHEL/CentOS systems, use:
# service mysqld restart

On Ubuntu/Debian systems, use:
# service mysql restart

 

14. After that, instruct the slave to connect to the master and replicate the database from the master by executing the following command. Replace the IP address, log file, password, and position with the values used in the previous steps.

 

mysql> change master to
-> master_host='172.16.1.217',
-> master_user='cloud-repl',
-> master_password='password',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=412;

 

 15. Then, run the following to start replication on the slave.

 

mysql> start slave;

 

 16. Finally, open port 3306 on the slave if required. This step is not necessary for replication to work. But if the user chooses not to do this, they will need to do it when failover to the replica happens.

 

Conclusion 

This tutorial presents the steps to implement database replication in Apache CloudStack. Hope this tutorial was helpful, and do reach out to us if you have any query or suggestions.

Share this post

Services to Explore

Stay up to date!

Stay up to date with the Web Hosting, Cloud and Server Management Industry News and Tutorials!

We will send you only the relevant emails, and we respect your privacy. Please review our privacy policy for more info.

Apache CloudStack Management

Focus on your business, and let us take care of your Apache CloudStack!
From what you are reading, it seems you are interested in Apache CloudStack and related technologies. If you have a moment to spare, please take a look at our Apache CloudStack Management plan, which might interest you even more!
Apache CloudStack Management

Value-Added Services

We have services that can help you run a successful business. With us, you don't have to worry about these areas because our experts will take care of it for you.

Introducing - WPHealers!

Complete WordPress Management, 24x7 Support & White Label Agency Plans!

WordPress migration service, security, white-label reseller services and lot more! Grab the introductory deals now!

WPHealers

ServerHealers uses cookies.