现在购买的国外VPS,偶尔会出现当机几十分钟的情况,或者我想去测试个什么东西,把VPS搞挂掉,不想在服务器挂掉时,让网友们看不到任何提示,于是结合网上的文章,配置了另外一台VPS的mysql,形成服务器A和服务器B主主的备份模式。
原文地址:
http://www.mike.org.cn/articles/mysql-master-slave-sync-conf-detail/
主要步骤如下:
服务器A配置my.cnf
lnmp包的my.cnf文件在/etc/my.cnf下
在mysqld这段增加如下代码:
#test是需要同步的数据库名称
binlog-do-db = test
binlog-ignore-db=mysql
#主主需加入的部分
log-slave-updates
sync_binlog=1
auto_increment_offset=1
auto_increment_increment=2
#test是需要同步的数据库名称
replicate-do-db = test
replicate-ignore-db = mysql,information_schema
replicate-do-db = test
replicate-ignore-db = mysql,information_schema
#主主需要加入部分
binlog-do-db = test
binlog-ignore-db=mysql
log-slave-updates
sync_binlog=1
auto_increment_offset=2
auto_increment_increment=2
以下是服务器A运行的情况:
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000019
Position: 1137
Binlog_Do_DB: 同步数据库名
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
mysql> change master to master_host='服务器BIP', master_user='服务器B mysql同步账户', master_password='服务器B mysql同步账户密码', master_log_file='show master status命令中file的值', master_log_pos=show master status命令中position的值;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 服务器BIP
Master_User: ben_cloud
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 107
Relay_Log_File: ben-relay-bin.000002
Relay_Log_Pos: 252
Relay_Master_Log_File: mysql-bin.000008
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
Replicate_Ignore_DB: mysql,information_schema
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 107
Relay_Log_Space: 405
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
ERROR:
No query specified
服务器B类似
详细的文档,还是见原文地址吧,里面已经写的很详细了。