Skip to main content

Mysql master slave replication

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 |

Comments

Popular posts from this blog

Modsecurity block rule for XMLRPC and wp-login attack

SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000134  <Locationmatch "/wp-login.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000135,msg:'ip address blocked for 5 minutes, more than 10 login attempts in 3 minutes.'"  SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.bf_counter=0,id:5000136"  SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,setvar:ip.bf_counter=+1,deprecatevar:ip.bf_counter=1/180,id:5000137"  SecRule ip:bf_counter "@gt 10" "t:none,setvar:user.bf_block=1,expirevar:user.bf_block=300,setvar:ip.bf_counter=0"  </Locationmatch>  SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000234  <Locationmatch "/xmlrpc.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000235,msg:'ip address blocked for 5 m...

How to tweak linux server harddisk using hdparm

hdparm switches explained http://manpages.ubuntu.com/manpages/intrepid/man8/hdparm.8.html   First of all you have to install hdparm in linux. apt-get install hdparm #hdparm /dev/sda /dev/sda: readonly = 0 (off) readahead = 120 (on) geometry = 8850/255/63, sectors = 142182912, start = 0 Hard disk Performance Information # hdparm -tT /dev/hda /dev/hdd: Timing cached reads: 496 MB in 2.00 seconds = 247.42 MB/sec Timing buffered disk reads: 60 MB in 3.03 seconds = 19.81 MB/sec Hard drive set to low, slow settings # hdparm -cuda /dev/hda /dev/hda: IO_support = 0 (default 16-bit) unmaskirq = 0 (off) using_dma = 0 (off) readahead = 256 (on) Use below tweaks to increase disk read write performance. For sda drive ~]# hdparm -a 2048 /dev/sda /dev/sda: setting fs readahead to 2048 readahead = 2048 (on) For sdb drive [root@439298a ~]# hdparm -a 2048 /dev/sdb /dev/sdb: setting fs readahead to 2048 readahead = 2048 (on) ]# echo “anticipatory” >...

Apache tuning documentation

Apache bench marking ======================= Things or checklist to be considered before the test     CPU: avoid power-saving mode. cpufreq-set -g performance.     File descriptors: raise the limit to (at least) the number of concurrent connections you wish to handle, using ulimit -n in your shell, or setrlimit(RLIMIT_NOFILE) in your server. Beware, some systems forbid you to raise the limit, you might need to investigate a bit to find how to unlock it.     Disable the logs of your server (you do not want to lose time logging thousands of requests instead of answering them).     Raise /proc/sys/net/somaxconn to the number of concurrent connections you want to handle. To understand why this is necessary, read the technical report or the excellent paper Measuring the Capacity of a Web Server (Banga and Druschel, Usenix 97). More on the fascinating topic of the accept() queue can be found in accept()able Strategies for Im...