日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

mysql主主互备架构

發(fā)布時(shí)間:2025/3/8 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql主主互备架构 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

mysql主主互備架構(gòu)

企業(yè)級(jí)mysql集群具備高可用,可擴(kuò)展性,易管理,低成本的特點(diǎn)。mysql主主互備就是企業(yè)中常用的一個(gè)解決方案。在這種架構(gòu)中,雖然互為主從,但同一時(shí)刻只有一臺(tái)mysql 可讀寫(xiě),一臺(tái)mysqk只能進(jìn)行讀操作

?

1.配置

環(huán)境: DB1(master)? mysql-5.1.73-3.el6_5.x86_64?? 192.168.32.130

? ? ? ? DB2?(slave)??? mysql-5.1.73-3.el6_5.x86_64??? 192.168.32.129

mysql vip : 192.168.32.100

安裝

yum -y install mysql mysql-devel

/etc/init.d/mysqld start


修改mysql配置文件

DB1配置

[mysqld]

server-id=1

log-bin=mysql-bin

relay-log=mysql-relay-bin

replicate-wild-ignore-table=mysql.%

replicate-wild-ignore-table=test.%

replicate-wild-ignore-table=information_schema.%


DB2配置

[mysqld]

server-id=2

log-bin=mysql-bin

relay-log=mysql-relay-bin

replicate-wild-ignore-table=mysql.%

replicate-wild-ignore-table=test.%

replicate-wild-ignore-table=information_schema.%

?

server-id:節(jié)點(diǎn)標(biāo)識(shí),主從不能相同,必須全局唯一。log-bin是mysql的binlog日志功能,mysql-bin表示日志文件的命名格式。relay-log定義relay-log日志文件的命名格式。replicate-wild-ignore-table是個(gè)復(fù)制過(guò)濾選項(xiàng),可以過(guò)濾不需要復(fù)制的數(shù)據(jù)庫(kù)或表。

?

慎用binlog-do-db(記錄日志的數(shù)據(jù)庫(kù))和binlog-ignore-db(是不要記錄日志的數(shù)據(jù)庫(kù)名,多個(gè)數(shù)據(jù)庫(kù)中間用逗號(hào)逗號(hào)隔開(kāi);),replicate-do-db(可以指定只復(fù)制哪個(gè)庫(kù)的數(shù)據(jù)),replicate-ignore-db(?過(guò)濾不是基于 查詢(xún)的字符串的, 而是基于你used的數(shù)據(jù)庫(kù)

?

建議用replicate-wild-ignore-table和replicate-wild-do-table

?

為什么 MySQL的 binlog-do-db 選項(xiàng)是危險(xiǎn)的-bingqihan-ChinaUnix博客

http://blog.chinaunix.net/uid-24500107-id-2602925.html

?

創(chuàng)建復(fù)制用戶(hù)并授權(quán)

在DB1mysql庫(kù)中創(chuàng)建復(fù)制用戶(hù)

grant replication slave on *.* to 'repl_user'@'192.168.32.129'identified by 'www.123';

show master status;

在DB2mysql庫(kù)中將DB1設(shè)為自己的主服務(wù)器

?

change master tomaster_host='192.168.32.130',master_user='repl_user',master_password='www.123',master_log_file='mysql-bin.000002',master_log_pos=342;

?

這邊的master_log_file和master_log_pos是DB1上通過(guò)show master status查詢(xún)到的結(jié)果

?

啟動(dòng)slave服務(wù)

start slave;

mysql> show slave status\G;

*************************** 1. row***************************

??????????????Slave_IO_State: Waiting for master to send event

?????????????????Master_Host: 192.168.32.130

?????????????????Master_User: repl_user

?????????????????Master_Port: 3306

???????????????Connect_Retry: 60

?????????????Master_Log_File: mysql-bin.000002

?????????Read_Master_Log_Pos: 342

?????????????? Relay_Log_File:mysql-relay-bin.000002

???????????????Relay_Log_Pos: 251

???????Relay_Master_Log_File: mysql-bin.000002

????????????Slave_IO_Running: Yes

???????????Slave_SQL_Running: Yes

?????????????Replicate_Do_DB:

?????????Replicate_Ignore_DB:

?????????? Replicate_Do_Table:

??????Replicate_Ignore_Table:

?????Replicate_Wild_Do_Table:

?Replicate_Wild_Ignore_Table: mysql.%,test.%,information_schema.%

??????????????????Last_Errno: 0

??????????????????Last_Error:

????????????????Skip_Counter: 0

?????????Exec_Master_Log_Pos: 342

?????????????Relay_Log_Space: 406

?????????????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

?

這里需要重點(diǎn)關(guān)注的是Slave_IO_Running和Slave_SQL_Running。這兩個(gè)就是slave節(jié)點(diǎn)運(yùn)行的主從復(fù)制線(xiàn)程。正常情況下這兩個(gè)值都是yes

?

在BD2mysql庫(kù)中創(chuàng)建復(fù)制用戶(hù)

?

grant replication slave on *.* to'repl_user'@'192.168.32.130' identified by 'www.123';

show? masterstatus;

?

在DB1中將DB2設(shè)為自己的主服務(wù)器

?

change master tomaster_host='192.168.32.129',master_user='repl_user',master_password='www.123',master_log_file='mysql-bin.000005',master_log_pos=267;

?

這邊的master_log_file和master_log_pos是DB2上通過(guò)show master status查詢(xún)到的結(jié)果

?

啟動(dòng)slave服務(wù)

start? slave

show slave status\G;

查看slave運(yùn)行狀態(tài)

在DB1上創(chuàng)建數(shù)據(jù)庫(kù)到DB2上查看,在DB2上創(chuàng)建數(shù)據(jù)庫(kù)到DB1上查看,發(fā)現(xiàn)都是同步的

?

show variables like 'server%';查看server_id

?


轉(zhuǎn)載于:https://blog.51cto.com/thedream/1654364

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的mysql主主互备架构的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。