真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

MySQLmaster-master如何配置-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“MySQLmaster-master如何配置”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)彭水苗族土家族免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

MySQLmaster-master怎么配置

1、修改MySQL配置文件
  兩臺(tái)MySQL均如要開啟binlog日志功能,開啟方法:在MySQL配置文件[MySQLd]段中加上log-bin=MySQL-bin選項(xiàng)
  兩臺(tái)MySQL的server-ID不能一樣,默認(rèn)情況下兩臺(tái)MySQL的serverID都是1,需將其中一臺(tái)修改為2即可
  2、將192.168.1.201設(shè)為192.168.1.202的主服務(wù)器
  在192.168.1.201上新建授權(quán)用戶
  MySQL>grantreplicationslaveon*.*to'replication'@'%'identifiedby'replication';QueryOK,0rowsaffected(0.00sec)MySQL>showmasterstatus;+------------------+----------+--------------+------------------+|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|+------------------+----------+--------------+------------------+|MySQL-bin.000003|374|||+------------------+----------+--------------+------------------+1rowinset(0.00sec)
  在192.168.1.202上將192.168.1.201設(shè)為自己的主服務(wù)器
  MySQL>changemastertomaster_host='192.168.1.201',master_user='replication',master_password='replication',master_log_file='MySQL-bin.000003',master_log_pos=374;QueryOK,0rowsaffected(0.05sec)MySQL>startslave;QueryOK,0rowsaffected(0.00sec)MySQL>showslavestatus\G***************************1.row***************************Slave_IO_State:WaitingformastertosendeventMaster_Host:192.168.1.201Master_User:replicationMaster_Port:3306Connect_Retry:60Master_Log_File:MySQL-bin.000003Read_Master_Log_Pos:374Relay_Log_File:MySQL-master2-relay-bin.000002Relay_Log_Pos:235Relay_Master_Log_File:MySQL-bin.000003Slave_IO_Running:YesSlave_SQL_Running:YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:0Last_Error:Skip_Counter:0Exec_Master_Log_Pos:374Relay_Log_Space:235Until_Condition:NoneUntil_Log_File:Until_Log_Pos:0Master_SSL_Allowed:NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master:01rowinset(0.00sec)
  3、將192.168.1.202設(shè)為192.168.1.201的主服務(wù)器
  在192.168.1.202上新建授權(quán)用戶
  MySQL>grantreplicationslaveon*.*to'replication'@'%'identifiedby'replication';QueryOK,0rowsaffected(0.00sec)MySQL>showmasterstatus;+------------------+----------+--------------+------------------+|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|+------------------+----------+--------------+------------------+|MySQL-bin.000003|374|||+------------------+----------+--------------+------------------+1rowinset(0.00sec)
  在192.168.1.201上,將192.168.1.202設(shè)為自己的主服務(wù)器
  MySQL>changemastertomaster_host='192.168.1.202',master_user='replication',master_password='replication',master_log_file='MySQL-bin.000003',master_log_pos=374;QueryOK,0rowsaffected(0.05sec)MySQL>startslave;QueryOK,0rowsaffected(0.00sec)MySQL>showslavestatus\G***************************1.row***************************Slave_IO_State:WaitingformastertosendeventMaster_Host:192.168.1.202Master_User:replicationMaster_Port:3306Connect_Retry:60Master_Log_File:MySQL-bin.000003Read_Master_Log_Pos:374Relay_Log_File:MySQL-master1-relay-bin.000002Relay_Log_Pos:235Relay_Master_Log_File:MySQL-bin.000003Slave_IO_Running:YesSlave_SQL_Running:YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:0Last_Error:Skip_Counter:0Exec_Master_Log_Pos:374Relay_Log_Space:235Until_Condition:NoneUntil_Log_File:Until_Log_Pos:0Master_SSL_Allowed:NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master:01rowinset(0.00sec)
  4、MySQL同步測試
  如上述均正確配置,現(xiàn)在任何一臺(tái)MySQL上更新數(shù)據(jù)都會(huì)同步到另一臺(tái)MySQL,MySQL同步在此不再演示。
  keepalived怎么安裝及配置
  1、192.168.1.201服務(wù)器上keepalived安裝及配置
  安裝keepalived
  #tarzxvfkeepalived-1.1.20.tar.gz#cdkeepalived-1.1.20#./configure--prefix=/usr/local/keepalived--with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686#make&&makeinstall
  配置keepalived
  我們自己在新建一個(gè)配置文件,默認(rèn)情況下keepalived啟動(dòng)時(shí)會(huì)去/etc/keepalived目錄下找配置文件
  #mkdir/etc/keepalived#vi/etc/keepalived/keepalived.conf!ConfigurationFileforkeepalivedglobal_defs{notification_email{luwenju@live.cn}notification_email_fromluwenju@live.cnsmtp_server127.0.0.1smtp_connect_timeout30router_idMySQL-ha}vrrp_instanceVI_1{stateBACKUP#兩臺(tái)配置此處均是BACKUPinterfaceeth0virtual_router_id51priority100#優(yōu)先級(jí),另一臺(tái)改為90advert_int1nopreempt#不搶占,只在優(yōu)先級(jí)高的機(jī)器上設(shè)置即可,優(yōu)先級(jí)低的機(jī)器不設(shè)置authentication{auth_typePASSauth_pass1111}virtual_ipaddress{192.168.1.200}}virtual_server192.168.1.2003306{delay_loop2#每個(gè)2秒檢查一次real_server狀態(tài)lb_algowrr#LVS算法lb_kindDR#LVS模式persistence_timeout60#會(huì)話保持時(shí)間protocolTCPreal_server192.168.1.2013306{weight3notify_down/usr/local/MySQL/bin/MySQL.sh#檢測到服務(wù)down后執(zhí)行的腳本TCP_CHECK{connect_timeout10#連接超時(shí)時(shí)間nb_get_retry3#重連次數(shù)delay_before_retry3#重連間隔時(shí)間connect_port3306#健康檢查端口}}
  編寫檢測服務(wù)down后所要執(zhí)行的腳本
  #vi/usr/local/MySQL/bin/MySQL.sh#!/bin/shpkillkeepalived#chmod+x/usr/local/MySQL/bin/MySQL.sh
  注:此腳本是上面配置文件notify_down選項(xiàng)所用到的,keepalived使用notify_down選項(xiàng)來檢查real_server的服務(wù)狀態(tài),當(dāng)發(fā)現(xiàn)real_server服務(wù)故障時(shí),便觸發(fā)此腳本;我們看到的是,腳本就一個(gè)命令,通過pkillkeepalived強(qiáng)制殺死keepalived進(jìn)程,從而實(shí)現(xiàn)了MySQL故障自動(dòng)轉(zhuǎn)移。另外,我們不用擔(dān)心兩個(gè)MySQL會(huì)同時(shí)提供數(shù)據(jù)更新操作,因?yàn)槊颗_(tái)MySQL上的keepalived的配置里面只有本機(jī)MySQL的IP+VIP,而不是兩臺(tái)MySQL的IP+VIP
  啟動(dòng)keepalived
  #/usr/local/keepalived/sbin/keepalived–D#ps-aux|grepkeepalived
  測試
  找一臺(tái)局域網(wǎng)PC,然后去pingMySQL的VIP,這時(shí)候MySQL的VIP是可以ping的通的
  停止MySQL服務(wù),看keepalived健康檢查程序是否會(huì)觸發(fā)我們編寫的腳本
  2、192.168.1.202上keepalived安裝及配置
  安裝keepalived
  #tarzxvfkeepalived-1.1.20.tar.gz#cdkeepalived-1.1.20#./configure--prefix=/usr/local/keepalived--with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686#make&&makeinstall
  配置keepalived
  這臺(tái)配置和上面基本一樣,但有三個(gè)地方不同:優(yōu)先級(jí)為90、無搶占設(shè)置、real_server為本機(jī)IP
  #mkdir/etc/keepalived#vi/etc/keepalived/keepalived.conf!ConfigurationFileforkeepalivedglobal_defs{notification_email{luwenju@live.cn}notification_email_fromluwenju@live.cnsmtp_server127.0.0.1smtp_connect_timeout30router_idMySQL-ha}vrrp_instanceVI_1{stateBACKUPinterfaceeth0virtual_router_id51priority90advert_int1authentication{auth_typePASSauth_pass1111}virtual_ipaddress{192.168.1.200}}virtual_server192.168.1.2003306{delay_loop2lb_algowrrlb_kindDRpersistence_timeout60protocolTCPreal_server192.168.1.2023306{weight3notify_down/usr/local/MySQL/bin/MySQL.shTCP_CHECK{connect_timeout10nb_get_retry3delay_before_retry3connect_port3306}}
  編寫檢測服務(wù)down后所要執(zhí)行的腳本
  #vi/usr/local/MySQL/bin/MySQL.sh#!/bin/shpkillkeepalived#chmod+x/usr/local/MySQL/bin/MySQL.sh啟動(dòng)keepalived#/usr/local/keepalived/sbin/keepalived–D#ps-aux|grepkeepalived
  測試
  停止MySQL服務(wù),看keepalived健康檢查程序是否會(huì)觸發(fā)我們編寫的腳本
  三、測試
  MySQL遠(yuǎn)程登錄測試
  我們找一臺(tái)安裝有MySQL客戶端的windows,然后登錄VIP,看是否能登錄,在登錄之兩臺(tái)MySQL服務(wù)器都要授權(quán)允許從遠(yuǎn)程登錄
  MySQL>grantallprivilegeson*.*to'root'@'%'identifiedby'123456';QueryOK,0rowsaffected(0.00sec)MySQL>flushprivileges;QueryOK,0rowsaffected(0.00sec)
  使用客戶端登錄VIP測試
  C:\MySQL\bin>MySQL.exe-uroot-p123456-h292.168.1.200-P3306WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis224Serverversion:5.0.89-logSourcedistributionType'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.MySQL>
  ●keepalived故障轉(zhuǎn)移測試
  ※在windows客戶端一直去pingVIP,然后關(guān)閉192.168.1.201上的keepalived,正常情況下VIP就會(huì)切換到192.168.1.202上面去
  ※開啟192.168.1.201上的keepalived,關(guān)閉192.168.1.202上的keepalived,看是否能自動(dòng)切換,正常情況下VIP又會(huì)屬于192.168.1.201
  注:keepalived切換速度還是非常塊的,整個(gè)切換過程只需1-3秒
  ●MySQL故障轉(zhuǎn)移測試
  ※在192.168.1.201上關(guān)閉MySQL服務(wù),看VIP是否會(huì)切換到192.168.1.202上
  ※開啟192.168.1.201上的MySQL和keepalived,然后關(guān)閉192.168.1.202上的MySQL,看VIP是否會(huì)切換到192.168.1.201上
  下面是用windows客戶端連接的MySQL的VIP,在切換時(shí)我執(zhí)行了一個(gè)MySQL查詢命令,從執(zhí)行showdatabases到顯示出結(jié)果時(shí)間為3-5秒(大家看到的是上面有個(gè)錯(cuò)誤提示,不過不用擔(dān)心,因?yàn)槲覀兊膋eepalived切換大概為3秒左右,這3秒左右VIP是誰都不屬于的)
  MySQL>showdatabases;ERROR2006(HY000):MySQLserverhasgoneawayNoconnection.Tryingtoreconnect...Connectionid:592Currentdatabase:***NONE***+--------------------+|Database|+--------------------+|information_schema||MySQL||test|+--------------------+3rowsinset(9.01sec)

“MySQLmaster-master如何配置”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!


網(wǎng)站標(biāo)題:MySQLmaster-master如何配置-創(chuàng)新互聯(lián)
路徑分享:http://weahome.cn/article/dgocjj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部