2011-08-29 60 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!