mysql主主互备架构
mysql主主互備架構(gòu)
企業(yè)級mysql集群具備高可用,可擴展性,易管理,低成本的特點。mysql主主互備就是企業(yè)中常用的一個解決方案。在這種架構(gòu)中,雖然互為主從,但同一時刻只有一臺mysql 可讀寫,一臺mysqk只能進行讀操作
?
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é)點標識,主從不能相同,必須全局唯一。log-bin是mysql的binlog日志功能,mysql-bin表示日志文件的命名格式。relay-log定義relay-log日志文件的命名格式。replicate-wild-ignore-table是個復制過濾選項,可以過濾不需要復制的數(shù)據(jù)庫或表。
?
慎用binlog-do-db(記錄日志的數(shù)據(jù)庫)和binlog-ignore-db(是不要記錄日志的數(shù)據(jù)庫名,多個數(shù)據(jù)庫中間用逗號逗號隔開;),replicate-do-db(可以指定只復制哪個庫的數(shù)據(jù)),replicate-ignore-db(?過濾不是基于 查詢的字符串的, 而是基于你used的數(shù)據(jù)庫)
?
建議用replicate-wild-ignore-table和replicate-wild-do-table
?
為什么 MySQL的 binlog-do-db 選項是危險的-bingqihan-ChinaUnix博客
http://blog.chinaunix.net/uid-24500107-id-2602925.html
?
創(chuàng)建復制用戶并授權(quán)
在DB1mysql庫中創(chuàng)建復制用戶
grant replication slave on *.* to 'repl_user'@'192.168.32.129'identified by 'www.123';
show master status;
在DB2mysql庫中將DB1設(shè)為自己的主服務器
?
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上通過show master status查詢到的結(jié)果
?
啟動slave服務
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
?
這里需要重點關(guān)注的是Slave_IO_Running和Slave_SQL_Running。這兩個就是slave節(jié)點運行的主從復制線程。正常情況下這兩個值都是yes
?
在BD2mysql庫中創(chuàng)建復制用戶
?
grant replication slave on *.* to'repl_user'@'192.168.32.130' identified by 'www.123';
show? masterstatus;
?
在DB1中將DB2設(shè)為自己的主服務器
?
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上通過show master status查詢到的結(jié)果
?
啟動slave服務
start? slave
show slave status\G;
查看slave運行狀態(tài)
在DB1上創(chuàng)建數(shù)據(jù)庫到DB2上查看,在DB2上創(chuàng)建數(shù)據(jù)庫到DB1上查看,發(fā)現(xiàn)都是同步的
?
show variables like 'server%';查看server_id
?
轉(zhuǎn)載于:https://blog.51cto.com/thedream/1654364
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的mysql主主互备架构的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pyotherside 试用
- 下一篇: linux cmake编译源码,linu