I needed to replicate my nagios server for disaster recovery. The database was
"db_nagiosql_v32"
On My main server which is master I had, Make sure to create log file and director if doesnot exist , also mysql ownership
[root@nagios ~]# cat /etc/my.cnf
[mysqld]
server-id= 1
log_bin= /var/log/mysql/mysql-bin.log
binlog_do_db = db_nagiosql_v32
Restart the mysql
/etc/init.d/nagios restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
Enter in to mysql prompt
GRANT REPLICATION SLAVE ON *.* TO 'replicant'@'%' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> USE db_nagiosql_v32
mysql> FLUSH TABLES WITH READ LOCK;
Dump the database and scp to the destination server
mysql> UNLOCK TABLES;
mysql> SHOW MASTER STATUS;
+------------------+----------+-----------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+-----------------+------------------+
| mysql-bin.000001 | 789 | db_nagiosql_v32 | |
+------------------+----------+-----------------+------------------+
Slave server
==============
cat /etc/my.cnf
[mysqld]
server-id=2
relay-log=/var/log/mysql/mysql-relay-bin.log
log_bin=/var/log/mysql/mysql-bin.log
binlog_do_db=db_nagiosql_v32
slave-skip-errors=1062
CHANGE MASTER TO MASTER_HOST='master IP',MASTER_USER='replicant', MASTER_PASSWORD='password', MASTER_LOG_POS= 789 ;
START SLAVE;
mysql> SHOW SLAVE STATUS\G
Slave_IO_State: Waiting for master to send event
Master_Host: master ip
Master_User: replicant
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 2484066
Relay_Log_File: mysql-relay-bin.000009
Relay_Log_Pos: 404598
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
make sure below lines are yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
You can see from master
------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+-----------+---------------------+----+-------------+------+----------------------------------------------------------------+------------------+
| 153 | replicant |slaveIP:34474 | | Binlog Dump | 530 | Has sent all binlog to slave; waiting for binlog to be updated | |
| 175 | root | localhost | | Query | 0 | | show processlist |
"db_nagiosql_v32"
On My main server which is master I had, Make sure to create log file and director if doesnot exist , also mysql ownership
[root@nagios ~]# cat /etc/my.cnf
[mysqld]
server-id= 1
log_bin= /var/log/mysql/mysql-bin.log
binlog_do_db = db_nagiosql_v32
Restart the mysql
/etc/init.d/nagios restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
Enter in to mysql prompt
GRANT REPLICATION SLAVE ON *.* TO 'replicant'@'%' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> USE db_nagiosql_v32
mysql> FLUSH TABLES WITH READ LOCK;
Dump the database and scp to the destination server
mysql> UNLOCK TABLES;
mysql> SHOW MASTER STATUS;
+------------------+----------+-----------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+-----------------+------------------+
| mysql-bin.000001 | 789 | db_nagiosql_v32 | |
+------------------+----------+-----------------+------------------+
Slave server
==============
cat /etc/my.cnf
[mysqld]
server-id=2
relay-log=/var/log/mysql/mysql-relay-bin.log
log_bin=/var/log/mysql/mysql-bin.log
binlog_do_db=db_nagiosql_v32
slave-skip-errors=1062
CHANGE MASTER TO MASTER_HOST='master IP',MASTER_USER='replicant', MASTER_PASSWORD='password', MASTER_LOG_POS= 789 ;
START SLAVE;
mysql> SHOW SLAVE STATUS\G
Slave_IO_State: Waiting for master to send event
Master_Host: master ip
Master_User: replicant
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 2484066
Relay_Log_File: mysql-relay-bin.000009
Relay_Log_Pos: 404598
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
make sure below lines are yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
You can see from master
------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+-----------+---------------------+----+-------------+------+----------------------------------------------------------------+------------------+
| 153 | replicant |slaveIP:34474 | | Binlog Dump | 530 | Has sent all binlog to slave; waiting for binlog to be updated | |
| 175 | root | localhost | | Query | 0 | | show processlist |
Comments
Post a Comment