這篇文章將為大家詳細(xì)講解有關(guān)Openstack 中 MySQL主主互備結(jié)合怎么實(shí)現(xiàn)高可用,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:國(guó)際域名空間、網(wǎng)站空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、沭陽(yáng)網(wǎng)站維護(hù)、網(wǎng)站推廣。
實(shí)驗(yàn)環(huán)境 服務(wù)器test1(主) 192.168.106.156 服務(wù)器test2(主) 192.168.106.158 Mysql版本:5.1.73 VM System OS:CentOS 6 X64
一 安裝配置mysql主主互備 1.安裝Mysql: 需要關(guān)閉防火墻、SELINUX,兩臺(tái)機(jī)子上要安裝同樣版本的mysql數(shù)據(jù)庫(kù)。
yum install mysql-server
2.創(chuàng)建同步用戶:
這里test1和test2互為主從,所以都要分別建立一個(gè)同步用戶。 在test1、test2兩臺(tái)機(jī)子上分別執(zhí)行:
mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO sync@'%' IDENTIFIED BY '123456'; mysql> flush privileges;
3.修改配置文件:
3.1 test1上mysql的配置文件:
[mysqld] #log-bin=mysql-bin server-id=156 log_bin = /var/lib/mysql/mysql-binlog binlog-ignore-db=mysql binlog-ignore-db=information_schema replicate-ignore-db=mysql,information_schema log-slave-updates sync_binlog=1 auto_increment_offset=1 auto_increment_increment=2
3.2 test2上mysql的配置文件:
[mysqld] #log-bin=mysql-bin server-id=158 auto_increment_offset=2 auto_increment_increment=2 log-slave-updates sync_binlog=1 log_bin = /var/lib/mysql/mysql-binlog binlog-ignore-db=mysql binlog-ignore-db=information_schema replicate-ignore-db=mysql,information_schema
4.然后,分別重啟mysql服務(wù)器。
service mysqld restart
5.分別在test1、test2上查看主服務(wù)器狀態(tài):
test1上: mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql> show master status\G *************************** 1. row *************************** File: mysql-binlog.000001 Position: 106 Binlog_Ignore_DB: mysql,information_schema 1 row in set (0.00 sec) mysql> mysql> unlock tables;
test2上: mysql> stop slave; mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql> show master status\G *************************** 1. row *************************** File: mysql-binlog.000001 Position: 106 Binlog_Ignore_DB: mysql,information_schema 1 row in set (0.00 sec) mysql> unlock tables;
注:這里鎖表的目的是為了生產(chǎn)環(huán)境中不讓進(jìn)新的數(shù)據(jù),好讓從服務(wù)器定位同步位置。初次同步完成后,記得解鎖。
6.分別在test1、test2上用change master語(yǔ)句指定同步位置:
6.1 test1: mysql> change master to master_host='192.168.106.158', master_user='sync', master_password='123456', master_log_file='mysql-binlog.000001', master_log_pos=106; Query OK, 0 rows affected (0.12 sec) mysql> start slave; Query OK, 0 rows affected (0.00 sec)
6.2 test2: mysql> change master to master_host='192.168.106.156', master_user='sync', master_password='123456', master_log_file='mysql-binlog.000001', master_log_pos=106; mysql> start slave; Query OK, 0 rows affected (0.00 sec)
分別在test1、test2上查看從服務(wù)器狀態(tài):
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: 192.168.106.158 Master_User: repli Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-binlog.000001 Read_Master_Log_Pos: 106 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 254 Relay_Master_Log_File: mysql-binlog.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: mysql,information_schema … …
查看以上兩項(xiàng)的值, Slave_IO_Running: Yes Slave_SQL_Running: Yes 均為Yes則表示狀態(tài)正常。
8.測(cè)試: 雙向測(cè)試,在test1上創(chuàng)建數(shù)據(jù)庫(kù)db1,從test2上查看信息;同樣,在test2上創(chuàng)建數(shù)據(jù)庫(kù)db2后,從test1上查看信息。
二 安裝和配置keepalived實(shí)現(xiàn)MySQL雙主高可用 1.安裝 keepalived
yum install keepalived
2.配置keepalived
2.1 test1 192.168.106.156 # vi /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { admin@tcloudsoft.com zhuzy@tcloudsoft.com } notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance HA_1 { state BACKUP #test1和test2都配置為BACKUP interface eth0 #指定HA檢測(cè)的網(wǎng)絡(luò)接口 virtual_router_id 80 #虛擬路由標(biāo)識(shí),主備相同 priority 100 #定義優(yōu)先級(jí),test2設(shè)置90 advert_int 1 #設(shè)定test1和test2之間同步檢查的時(shí)間間隔 nopreempt #不搶占模式。只在優(yōu)先級(jí)高的機(jī)器上設(shè)置即可 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { #設(shè)置虛擬IP,可以設(shè)置多個(gè),每行一個(gè) 192.168.106.200/24 dev eth0 #MySQL對(duì)外服務(wù)的IP,即VIP } } virtual_server 192.168.106.200 3306 { delay_loop 2 #每隔2秒查詢r(jià)eal server狀態(tài) lb_algo wrr #lvs 算法 lb_kinf DR #LVS模式(Direct Route) persistence_timeout 50 protocol TCP real_server 192.168.106.156 3306 { #監(jiān)聽(tīng)本機(jī)的IP weight 1 notify_down /etc/keepalived/mysql.sh TCP_CHECK { connect_timeout 10 #10秒無(wú)響應(yīng)超時(shí) bingto 192.168.106.200 nb_get_retry 3 delay_before_retry 3 connect_port 3306 } } }
2.2 keepalived檢測(cè)腳本,當(dāng)其中一臺(tái)MySQL服務(wù)出現(xiàn)故障down掉時(shí),實(shí)現(xiàn)自動(dòng)切換到正常的MySQL服務(wù)器繼續(xù)提供服務(wù)
vi /etc/keepalived/mysql.sh #!/bin/bash pkill keepalived
2.3 test2 192.168.106.158 # vi /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { root@tcloudsoft.com zhuzy@tcloudsoft.com } notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance HA_1 { state BACKUP #test1和test2都配置為BACKUP interface eth0 #指定HA檢測(cè)的網(wǎng)絡(luò)接口 virtual_router_id 80 #虛擬路由標(biāo)識(shí),主備相同 priority 90 #定義優(yōu)先級(jí),test2設(shè)置90 advert_int 1 #設(shè)定test1和test2之間同步檢查的時(shí)間間隔 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { #設(shè)置虛擬IP,可以設(shè)置多個(gè),每行一個(gè) 192.168.106.200/24 dev eth0 #MySQL對(duì)外服務(wù)的IP,即VIP } } virtual_server 192.168.106.200 3306 { delay_loop 2 lb_algo wrr lb_kinf DR persistence_timeout 50 protocol TCP real_server 192.168.106.158 3306 { #監(jiān)聽(tīng)本機(jī)的IP weight 1 notify_down /etc/keepalived/mysql.sh TCP_CHECK { connect_timeout 10 bingto 192.168.106.200 nb_get_retry 3 delay_before_retry 3 connect_port 3306 } } }
3.授權(quán)VIP的root用戶權(quán)限 授權(quán)遠(yuǎn)程主機(jī)可以通過(guò)VIP登錄MySQL,并測(cè)試數(shù)據(jù)復(fù)制功能
mysql> grant all on *.* to root@'192.168.6.44' identified by '123456'; mysql> grant all on *.* to root@'192.168.106.200' identified by '123456'; mysql> flush privileges;
4.測(cè)試keepalived高可用功能 在OpenStack中,測(cè)試前需要先完成第三部分的設(shè)置 4.1遠(yuǎn)程主機(jī)登錄通過(guò)VIP 192.168.106.200 登錄MySQL,查看MySQL連接狀態(tài)
mysql> show variables like 'hostname%'; +---------------+--------+ | Variable_name | Value | +---------------+--------+ | hostname | test1 | +---------------+--------+ 1 row in set (0.00 sec)
4.2故障測(cè)試,停止test1的MySQL服務(wù),再次查看是否轉(zhuǎn)移至test2服務(wù)器上
mysql> show variables like 'hostname%';
三 OpenStack VM單網(wǎng)卡多IP 實(shí)現(xiàn)VIP切換的方法 1.使用port_security_enabled屬性,port_security_enabled 是在kilo版后加入的Ml2擴(kuò)展驅(qū)動(dòng),可能針對(duì)整個(gè)網(wǎng)絡(luò)更改,也可針對(duì)某個(gè)端口更改,默認(rèn)為true。
neutron port-list neutron port-update --no-security-groups 413b58fe-44c0-4df2-b588-332d5b6030e9 neutron port-update 413b58fe-44c0-4df2-b588-332d5b6030e9 --port_security_enabled=False
2.使用allowed-address-pairs 來(lái)擴(kuò)展端口屬性,允許手動(dòng)指定端口的mac_address和ip 地址對(duì)的流量通過(guò)。
neutron port-list neutron port-show 413b58fe-44c0-4df2-b588-332d5b6030e9 neutron port-update 413b58fe-44c0-4df2-b588-332d5b6030e9 --allowed-address-pairs type=dict list=true ip_address=192.168.106.200 neutron port-update 413b58fe-44c0-4df2-b588-332d5b6030e9 --allowed-address-pairs action=clear
關(guān)于Openstack 中 MySQL主主互備結(jié)合怎么實(shí)現(xiàn)高可用就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。