Table of Contents |
---|
Install MariaDB on
...
replica server
Install the same MariaDB server package that Abiquo API server is using on the slave server. This can be achieve by installing the corresponding replica server. To do this, install your current abiquo-release package on the replica server and executing run the command below:
Code Block |
---|
yum -y install MariaDB-server MariaDB-client |
...
Configure DB replication on
...
the main DB server
Create On the main DB server, create the replication configuration file in master DB server :
Code Block |
---|
cat <<EOF >/etc/my.cnf.d/replication.cnf [server] log-basename=master log-bin binlog-format=row server_id=1 EOF |
Restart the mysql service:
Code Block |
---|
service mysql restart |
Create a replicator user and grant it replication permissions by executing the query below on DB prompt. Replace REPLICA_USER, REPLICA_PASS and SLAVEREPLICA_SERVER as you wishwith values for your environment:
Code Block |
---|
grant replication slave on *.* to 'REPLICA_USER'@'SLAVE_SERVER' identified by 'REPLICA_PASS'; flush privileges; |
...
Code Block |
---|
service mysql restart |
Warning |
---|
Remember that, if you are using multiple slaves, each one must has a different server_id defined To use multiple replica servers, in |
...
Initial replication
Open a new session on master DB server and execute the commands below at the mysql prompt. This will show master current status To perform the initial replication, get the current status of the main db, including the file and the current position in the log. We will need this later when replicating the DB in the slave. Leave this session as it is until replication is completed:, and then perform a dump of the database with the following steps
Open a new session on the main DB server at the
mysql
promptRun the following commands to get the file and current position
Code Block flush tables with read lock; show master status; +----------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +----------------------+----------+--------------+------------------+ | master-bin.000001 | 3712878 | | | +----------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
...
Leave this session open and don’t make any changes until replication is completed.
On the MariaDB main server, open another session and dump the
kinton
andkinton_accounting
databases
...
using
--single-transaction
optionCode Block mysqldump --databases kinton kinton_accounting --routines --single-transaction > dump.sql
...
Configure slave replication point
Copy
dump.sql
from the previous step from
...
the main DB server to
...
the replica DB server.
...
When the copy finishes, import it into
...
replica DB server. If this is a new installation you may need to create the
kinton
...
databases.
Code Block mysql < dump.sql
...
When the import finishes, configure
...
replica DB server replication.
...
On the replica DB server, go to the
mysql
prompt and run the change master command belowReplace
MAIN_SERVER
,REPLICA_USER
andREPLICA_PASS
.
...
Replace
MASTER_LOG_FILE
andMASTER_LOG_POS
from the show master status
...
above
Code Block change master to MASTER_HOST='
...
MAIN_SERVER', MASTER_USER='REPLICA_USER', MASTER_PASSWORD='REPLICA_PASS', MASTER_PORT=3306, MASTER_LOG_FILE='MASTER_LOG_FILE', MASTER_LOG_POS=MASTER_LOG_POS, MASTER_CONNECT_RETRY=10;
...
For example, using the values from above of
master-bin.000001
and3712878
Code Block change master to MASTER_HOST='services.lab.example.com', MASTER_USER='abiquodb', MASTER_PASSWORD='abiquodbpassword', MASTER_PORT=3306, MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=3712878, MASTER_CONNECT_RETRY=10;
On the replica server, at the
mysql
prompt, start replica DB replicationCode Block start slave;
...
To check replication status
...
, run the following command on the
...
replica DB
Code Block show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event ... 1 row in set (0.00 sec)
When Slave_IO_State is
...
Waiting for master to send event
...
, replication is finished
...
Release locks by closing the first session on master DB server where locks were set and the master status was requested, and you are done!
References
https://mariadb.com/kb/en/setting-up-replication/
...