Please refer:
http://conheotiensinh.blogspot.com/2009/08/high-availability-http-use-heartbeat.html
http://www.linux-ha.org/USE Pfsense for load balance or Cluster FailOver(http://conheotiensinh.blogspot.com/2009/09/load-balance-and-cluster-failover.html)
Use Pen for Loadbalance(http://conheotiensinh.blogspot.com/2009/09/load-balance-web-server-use-pen.html)
2/Master-Master Replication With MySQL
1.1 System 1
Hostname: mail.test.vn
IP: 192.168.20.203
1.2 System 2
Hostname: mail1.test.vn
IP: 192.168.20.83
Step 1: MySQL Root Password
Both Systems
Set a password for the MySQL root-user on localhost.
mysqladmin -u root password 123
System 1
Set a password for the MySQL root-user on mail.test.vn.
mysqladmin -u root -h 192.168.20.203 password 123
System 2
Set a password for the MySQL root-user on mail1.test.vn.
mysqladmin -u root -h 192.168.20.83 password 123
Step2:MySQL Replication User
System 1
Create the replication user that System 2 will use to access the MySQL database on System 1.
mysql -u root -p
GRANT REPLICATION SLAVE ON *.* TO 'system'@'%' IDENTIFIED BY '123';
FLUSH PRIVILEGES;
quit;
System 2
Create the replication user that System 1 will use to access the MySQL database on System 2.
mysql -u root -p
GRANT REPLICATION SLAVE ON *.* TO 'system'@'%' IDENTIFIED BY '123';
FLUSH PRIVILEGES;
quit;
Step 3: Open port 3306 for connect
Step 4:MySQL Configuration
In the next two steps we adjust the MySQL configuration on both systems for master-master replication.
System 1
vi /etc/my.cnf
Add the following lines to the section [mysqld]:
server-id = 1
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 1
master-host = 192.168.20.83
master-user = system
master-password = 123
master-connect-retry = 60
replicate-do-db =vmail
log-bin = /var/log/mysql/mysql-bin.log
binlog-do-db = vmail
relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index
expire_logs_days = 10
max_binlog_size = 500M
Afterwards restart the MySQL server.
/etc/init.d/mysqld restart
System 2
vi /etc/my.cnf
Add the following lines to the section [mysqld]:
server-id = 2
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 2
master-host = 192.168.20.203
master-user = system
master-password = 123
master-connect-retry = 60
replicate-do-db =vmail
log-bin= /var/log/mysql/mysql-bin.log
binlog-do-db =vmail
relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index
expire_logs_days = 10
max_binlog_size = 500M
Afterwards restart the MySQL server.
/etc/init.d/mysqld restart
Step 5:Export MySQL Dump On System 1
Now we create a dump of the existing database and transfer it to system 2.mysql -u root -p
USE vmail;FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000007 | 30330 | vmail,vmail | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
Open a second terminal for system 1, create the dump and transfer it to system 2. Don't leave the MySQL-shell at this point - otherwise you'll loose the read-lock.
cd /tmp/
mysqldump -u root -p123 --opt vmail > sqldump.sql
scp sqldump.sql root@192.168.20.83:/tmp/
Afterwards close the second terminal and switch back to the first. Remove the read-lock and leave the MySQL-shell.
UNLOCK TABLES;
quit;
Step 6: Import MySQL Dump On System 2
Time to import the database dump on system 2.
mysqladmin --user=root --password=123 stop-slave
cd /tmp/
mysql -u root -p123 vmail <>
Step 7:System 2 As Master
Now we need information about the master status on system 2.
mysql -u root -p
USE vmail;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
The output should look like this. Note down the file and the position - you'll need both later.
+------------------+----------+---------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+---------------------+------------------+
| mysql-bin.000009 | 28816 | vmail,vmail | |
+------------------+----------+---------------------+------------------+
1 row in set (0.00 sec)
Afterwards remove the read-lock.
UNLOCK TABLES;
At this point we're ready to become the master for system 1. Replace %mysql_slaveuser_password% with the password you choose and be sure that you replace the values for MASTER_LOG_FILE and MASTER_LOG_POS with the values that you noted down at step 5!
CHANGE MASTER TO MASTER_HOST='192.168.20.203', MASTER_USER='system', MASTER_PASSWORD='123', MASTER_LOG_FILE='mysql-bin.000007', MASTER_LOG_POS=30330;
Now start the slave ...
START SLAVE;
quit;
Step 8:System 1 As Master
Open a MySQL-shell on system 1 ...
mysql -u root -p
... and stop the slave.
STOP SLAVE;
At this point we're ready to become the master for system 2. Replace %mysql_slaveuser_password% with the password you choose and be sure that you replace the values for MASTER_LOG_FILE and MASTER_LOG_POS with the values that you noted down at step 7!
CHANGE MASTER TO MASTER_HOST='192.168.20.83', MASTER_USER='system', MASTER_PASSWORD='123', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=28816;
Now start the slave ...
START SLAVE;
quit;
Step 10:Test
Check in system 2:192.168.20.83
create mailbox Test2@test.vn and add in mailist ug@test.vn in system2:192.168.20.83
Check in system 1:192.168.20.203
Now i can login 2 Accounts in system1 and system 2
ReplyDeleteI handle such information much. I was looking for this certain info for a long time.,Thanks and best of luck.
ReplyDeleteI handle such information much. I was looking for this certain info for a long time.,Thanks and best of luck.
It's really a nice and helpful piece of information about the real time file replication I am glad that you shared this helpful info with us. Please keep us informed like this.
ReplyDeletereal time file replication