DB Replication
CloudStack supports database
replication from one MySQL node to another. This is achieved using standard
MySQL replication. You may want to do this as insurance against MySQL server or
storage loss. MySQL replication is implemented using a master/slave model. The master
is the node that the Management Servers are configured to use. The slave is a
standby node that receives all write operations from the master and applies
them to a local, redundant copy of the database. The following steps are a
guide to implementing MySQL replication.
DB Replication
Master server
1)Ensure that this is a fresh install with no data in
the master.
Edit my.cnf on the master
and add the following in the [mysqld] section below datadir.
# vi /etc/my.cnf
log_bin=mysql-bin
server_id=1
2)Restart the MySQL service:
#service mysqld restart
3)Create a replication account on the master and give it
privileges. We will use the "cloud-repl" user with the password
"password". This assumes that master and slave run on the
192.168.0.0/24 network.
#mysql
-u root -p
Mysql> create user
'cloud-repl'@'192.168.0.%' identified by 'XXXX';
Mysql>grant replication slave on *.* TO
'cloud-repl'@'192.168.0.%';
Mysql> flush privileges;
Mysql>flush tables with read lock;
4)Leave the current MySQL session running.In a new shell
start a second MySQL session. Retrieve the current position of the database.
#mysql -u root -p
Mysql>show master status;
+------------------+--------+--------------+------------------+-----------------+
------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+-----------------+----
| mysql-bin.000007 |
175307681| | |
+------------------+----------+--------------+------------------+
-----------------+----
5)Note the file and the
position that are returned by your instance. Exit from this session.
Complete the master setup.
Returning to your first session on the master, release the locks and exit
MySQL.
#mysql>unlock tables;
Slave server
1)Edit my.cnf and add the following lines in the
[mysqld] section below datadir.
#vi /etc/my.cnf
#log_bin=mysql-bin(comment the line)
server_id=2
2)Restart MySQL.
#service mysqld restart
3)Instruct the slave to
connect to and replicate from the master. Replace the IP address, password, log
file, and position with the values you have used in the previous steps.
Mysql>change master
to master_host='192.168.0.23',master_user='cloud-repl',
master_password='XXXX', master_log_file='mysql-bin.000007',
master_log_pos=175307681;
4)Then start replication on the slave.
#start slave;
#Show slave status;
Test For DB Replication
1)Create an account in UI
as a administrator
2)Go to Slave DB
log in to my sql
Use cloud database
Show account
Find new user account
details with time stamp
No comments:
Post a Comment