您好,登錄后才能下訂單哦!
mysql 中怎么利用master-master實(shí)現(xiàn)雙機(jī)熱備份 ,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
1、環(huán)境描述。
主機(jī):192.168.0.167(A)
主機(jī):192.168.0.251(B)
MYSQL 版本為5.1.11
2、授權(quán)用戶。
A:
> grant replication slave,file on *.* to identified
by 123456;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
B:
mysql> grant replication slave,file on *.* to identified
by 123456;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
然后都停止MYSQL 服務(wù)器。
3、配置文件。
在兩個(gè)機(jī)器上的my.cnf里面都開啟二進(jìn)制日志 。
A:
user = mysql
log-bin=mysql-bin
server-id = 1
binlog-do-db=test
binlog-ignore-db=mysql
replicate-do-db=test
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
B:
user = mysql
log-bin=mysql-bin
server-id = 2
binlog-do-db=test
binlog-ignore-db=mysql
replicate-do-db=test
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2
至于這些參數(shù)的說明具體看手冊(cè)。
紅色的部分非常重要,如果一個(gè)MASTER 掛掉的話,另外一個(gè)馬上接管。
紫紅色的部分指的是服務(wù)器頻繁的刷新日志。這個(gè)保證了在其中一臺(tái)掛掉的話,日志刷新到另外一臺(tái)。從而保證了數(shù)據(jù)的同步 。
4、重新啟動(dòng)MYSQL服務(wù)器。
在A和B上執(zhí)行相同的步驟
[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe &
[1] 4264
[root@localhost ~]# 071213 14:53:20 mysqld_safe Logging to /usr/local/mysql/data/localhost.localdomain.err.
/usr/local/mysql/bin/mysqld_safe: line 366: [: -eq: unary operator expected
071213 14:53:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
5、進(jìn)入MYSQL的SHELL。
A:
mysql> flush tables with read lockG
Query OK, 0 rows affected (0.00 sec)
mysql> show master statusG
*************************** 1. row ***************************
File: mysql-bin.000007
Position: 528
Binlog_Do_DB: test
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
B:
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
mysql> show master statusG
*************************** 1. row ***************************
File: mysql-bin.000004
Position: 595
Binlog_Do_DB: test
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
然后備份自己的數(shù)據(jù),保持兩個(gè)機(jī)器的數(shù)據(jù)一致。
方法很多。完了后看下一步。
6、在各自機(jī)器上執(zhí)行CHANGE MASTER TO命令。
A:
mysql> change master to
-> master_host=192.168.0.251,
-> master_user=backup_251,
-> master_password=123456,
-> master_log_file=mysql-bin.000004,
-> master_log_pos=595;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
B:
mysql> change master to
-> master_host=192.168.0.167,
-> master_user=backup_167,
-> master_password=123456,
-> master_log_file=mysql-bin.000007,
-> master_log_pos=528;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
7、查看各自機(jī)器上的IO進(jìn)程和 SLAVE進(jìn)程是否都開啟。
A:
mysql> show processlistG
*************************** 1. row ***************************
Id: 2
User: repl
Host: 192.168.0.251:54475
db: NULL
Command: Binlog Dump
Time: 1590
State: Has sent all binlog to slave; waiting for binlog to be updated
Info: NULL
*************************** 2. row ***************************
Id: 3
User: system user
Host:
db: NULL
Command: Connect
Time: 1350
State: Waiting for master to send event
Info: NULL
*************************** 3. row ***************************
Id: 4
User: system user
Host:
db: NULL
Command: Connect
Time: 1149
State: Has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
*************************** 4. row ***************************
Id: 5
User: root
Host: localhost
db: test
Command: Query
Time: 0
State: NULL
Info: show processlist
4 rows in set (0.00 sec)
B:
mysql> show processlistG
*************************** 1. row ***************************
Id: 1
User: system user
Host:
db: NULL
Command: Connect
Time: 2130
State: Waiting for master to send event
Info: NULL
*************************** 2. row ***************************
Id: 2
User: system user
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。