Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

on both servers

-----------------1) # sudo apt-get install mysql-server mysql-client


2) Edit /etc/mysql/my.cnf and comment out the bind-address line:
#bind-address = 127.0.0.1
This will make MySQL listen on all available interfaces. Consider firewalling.
3) Create a replication user in MySQL:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl_passwor
d';
mysql> FLUSH PRIVILEGES;
mysql>quit
=================================================================
Configuration on Server 1
--------------------------Create /etc/mysql/conf.d/replication.cnf:
[mysqld]
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 500M
log-slave-updates
auto_increment_increment = 2
auto_increment_offset = 1
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
replicate-wild-ignore-table = mysql.%
Restart MySQL.
# service mysql restart

//now go on server2 and log in to sql


#mysql -u root -p'password'
and make:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File
| Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000015 |
2093 |
|
|
+------------------+----------+--------------+------------------+
save these values and get back to server 1 then make:
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='server2_ip', MASTER_USER='repl', MASTER_PAS
SWORD='repl_password', MASTER_PORT=3306, MASTER_CONNECT_RETRY=60, MASTER_LOG_FIL
E = 'mysql-bin.000015', MASTER_LOG_POS = 2093; ;
mysql> START SLAVE;
=================================================================
Configuration on Server 2

--------------------------[mysqld]
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 500M
log-slave-updates
auto_increment_increment = 2
auto_increment_offset = 2
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
replicate-wild-ignore-table = mysql.%
Restart MySQL.
# service mysql restart

//now go on server1 and log in to sql and make:


mysql> show master status;
+------------------+----------+--------------+------------------+
| File
| Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 |
1201 |
|
|
+------------------+----------+--------------+------------------+
save these values and get back to server 2 then make:
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='server1_ip', MASTER_USER='repl', MASTER_PAS
SWORD='repl_password', MASTER_PORT=3306, MASTER_CONNECT_RETRY=60, MASTER_LOG_FIL
E = 'mysql-bin.000002', MASTER_LOG_POS = 1201;
mysql> START SLAVE;
===================================
check connectivity (not necessary)
--------------------------to check conectivity on each node from node 1 makes:
mysql -h'server2_ip' -urepl -p
to see u connect to node2
and also from node2 makes:
mysql -h'server1_ip' -urepl -p
to see u conect to node1
================================================
on both nodes:
-------------mysql> SHOW MASTER STATUS \G;
mysql> SHOW SLAVE STATUS \G;
to know if it already configured correctly
u have to see these 2 values from command mysql> SHOW SLAVE STATUS \G;
....
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
.....

and each node from the same command aslo mysql> SHOW SLAVE STATUS \G;
shows:
.....
Slave_IO_State: Waiting for master to send event
.....
==================================================
to check it is working well
------------------------on node1
mysql> create database testing;
on node1
mysql> show databases;
it will show u testing database
on node2
mysql> create table testing.dummy (`id` varchar(10));
on node1
mysql> show tables in testing;

:) :)

You might also like