2011-08-29 61 views
0

我有一個具有2個Web服務器和2個數據庫服務器的Web應用程序。 dbs被設置爲多主複製。 (這是主環境)Mysql複製

我也有在不同的位置充當待機完全相同的設置,在殼體主ENV失敗。 (這是備份env)

我需要的是備份env與主站點的dbs同步。但是,這兩個環境中的所有dbs都已配置了複製。

我該如何實現目標?

感謝

回答

1

如果這是標準的MySQL而不是MySQL集羣(從您的設置,我認爲是必須),你不能AFAIK。

如果你有分層複製,那麼你可以讓它工作,但用multimaster你不能。基本問題是從站只能有一個由CHANGE MASTER TO命令設置的主站。

MySQL集羣在更復雜的方式運行,你必須在每個羣集多臺服務器,然後集羣可以被複制到另一個集羣......什麼的。

我不害怕。

可以將備份服務器同步到其他的大師之一,但直到你有問題,然後你自己去改變主從關係的備份服務器不會大師對方。

0
1 Configure The Master 
First we have to edit /etc/mysql/my.cnf. or /etc/my.cnf We have to enable networking for MySQL, and MySQL should listen on all IP addresses, therefore we comment out these lines (if existant): 
#skip-networking 
skip-external-locking 
bind-address=0.0.0.0 
log-bin=mysql-bin.log 
binlog-do-db=exampledb (database name) 
server-id=1 

Then we restart MySQL: 
/etc/init.d/mysql restart 


Create a user with replication privileges 
GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY '<some_password>'; (Replace <some_password> with a real password!)  
FLUSH PRIVILEGES; 

Take dump of database(exampledb) and run command 
SHOW MASTER STATUS 
It will give you result like 
---------------+----------+--------------+------------------+ 
| File   | Position | Binlog_do_db | Binlog_ignore_db | 
+---------------+----------+--------------+------------------+ 
| mysql-bin.006 | 183  | database name|     | 
+---------------+----------+--------------+------------------+ 
1 row in set (0.00 sec 


Write down this information, we will need it later on the slave! 
Then leave the MySQL shell: 
quit; 

2 Configure The Slave 
On the slave we first have to create the sample database exampledb: 
mysql -u root -p 
Enter password: 
CREATE DATABASE exampledb; 
quit; 

store databse dump on slave 

Now we have to tell MySQL on the slave that it is the slave, that the master is 192.168.0.100, and that the master database to watch is exampledb. Therefore we add the following lines to /etc/mysql/my.cnf or /etc/my.cnf if file doesnot exists copy from other location 

server-id=2 
master-host=192.168.0.100(ip address of master host machine) 
master-user=slave_user(user name) 
master-password=secret (password) 
master-connect-retry=60 
replicate-do-db=exampledb (database name) 

Then we restart MySQL: 
/etc/init.d/mysql restart 

Finally, we must do this: 
mysql -u root -p 
Enter password: 
SLAVE STOP; 
In the next command (still on the MySQL shell) you have to replace the values appropriately: 
CHANGE MASTER TO MASTER_HOST=’master ip address’, MASTER_USER='slave_user', MASTER_PASSWORD='<some_password>', MASTER_LOG_FILE='mysql-bin.006', MASTER_LOG_POS=183; 
MASTER_HOST is the IP address or hostname of the master (in this example it is 192.168.0.100). 
MASTER_USER is the user we granted replication privileges on the master. 
MASTER_PASSWORD is the password of MASTER_USER on the master. 
MASTER_LOG_FILE is the file MySQL gave back when you ran SHOW MASTER STATUS; on the master. 
MASTER_LOG_POS is the position MySQL gave back when you ran SHOW MASTER STATUS; on the master. 
Now all that is left to do is start the slave. Still on the MySQL shell we run 
START SLAVE; 
quit; 
That's it! Now whenever exampledb is updated on the master, all changes will be replicated to exampledb on the slave. Test it!