您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Openstack 中 MySQL主主互備結合怎么實現高可用,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
實驗環境 服務器test1(主) 192.168.106.156 服務器test2(主) 192.168.106.158 Mysql版本:5.1.73 VM System OS:CentOS 6 X64
一 安裝配置mysql主主互備 1.安裝Mysql: 需要關閉防火墻、SELINUX,兩臺機子上要安裝同樣版本的mysql數據庫。
yum install mysql-server
2.創建同步用戶:
這里test1和test2互為主從,所以都要分別建立一個同步用戶。 在test1、test2兩臺機子上分別執行:
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服務器。
service mysqld restart
5.分別在test1、test2上查看主服務器狀態:
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;
注:這里鎖表的目的是為了生產環境中不讓進新的數據,好讓從服務器定位同步位置。初次同步完成后,記得解鎖。
6.分別在test1、test2上用change master語句指定同步位置:
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上查看從服務器狀態:
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 … …
查看以上兩項的值, Slave_IO_Running: Yes Slave_SQL_Running: Yes 均為Yes則表示狀態正常。
8.測試: 雙向測試,在test1上創建數據庫db1,從test2上查看信息;同樣,在test2上創建數據庫db2后,從test1上查看信息。
二 安裝和配置keepalived實現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檢測的網絡接口 virtual_router_id 80 #虛擬路由標識,主備相同 priority 100 #定義優先級,test2設置90 advert_int 1 #設定test1和test2之間同步檢查的時間間隔 nopreempt #不搶占模式。只在優先級高的機器上設置即可 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { #設置虛擬IP,可以設置多個,每行一個 192.168.106.200/24 dev eth0 #MySQL對外服務的IP,即VIP } } virtual_server 192.168.106.200 3306 { delay_loop 2 #每隔2秒查詢real server狀態 lb_algo wrr #lvs 算法 lb_kinf DR #LVS模式(Direct Route) persistence_timeout 50 protocol TCP real_server 192.168.106.156 3306 { #監聽本機的IP weight 1 notify_down /etc/keepalived/mysql.sh TCP_CHECK { connect_timeout 10 #10秒無響應超時 bingto 192.168.106.200 nb_get_retry 3 delay_before_retry 3 connect_port 3306 } } }
2.2 keepalived檢測腳本,當其中一臺MySQL服務出現故障down掉時,實現自動切換到正常的MySQL服務器繼續提供服務
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檢測的網絡接口 virtual_router_id 80 #虛擬路由標識,主備相同 priority 90 #定義優先級,test2設置90 advert_int 1 #設定test1和test2之間同步檢查的時間間隔 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { #設置虛擬IP,可以設置多個,每行一個 192.168.106.200/24 dev eth0 #MySQL對外服務的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 { #監聽本機的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.授權VIP的root用戶權限 授權遠程主機可以通過VIP登錄MySQL,并測試數據復制功能
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.測試keepalived高可用功能 在OpenStack中,測試前需要先完成第三部分的設置 4.1遠程主機登錄通過VIP 192.168.106.200 登錄MySQL,查看MySQL連接狀態
mysql> show variables like 'hostname%'; +---------------+--------+ | Variable_name | Value | +---------------+--------+ | hostname | test1 | +---------------+--------+ 1 row in set (0.00 sec)
4.2故障測試,停止test1的MySQL服務,再次查看是否轉移至test2服務器上
mysql> show variables like 'hostname%';
三 OpenStack VM單網卡多IP 實現VIP切換的方法 1.使用port_security_enabled屬性,port_security_enabled 是在kilo版后加入的Ml2擴展驅動,可能針對整個網絡更改,也可針對某個端口更改,默認為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 來擴展端口屬性,允許手動指定端口的mac_address和ip 地址對的流量通過。
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
關于Openstack 中 MySQL主主互備結合怎么實現高可用就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。