您好,登錄后才能下訂單哦!
Keepalived+MariaDB10配置雙主高可用數據庫
OS | RS | 子網掩碼 | 路由網關 |
Centos6.6 MariaDB10 Keepalived
| Eth0:192.168.26.210 | 255.255.252.0 | 192.168.25.3 |
VIP:192.168.27.210 | 255.255.255.252 | ||
Centos6.6 MariaDB10 Keepalived | Eth0:192.168.26.211 | 255.255.252.0 | 192.168.25.3 |
VIP:192.168.27.210 | 255.255.255.255 | ||
Win7(client) | IP:192.168.26.70 | 255.255.252.0 | 192.168.25.3 |
yum -y install MariaDB (這里略)
安裝完后配置雙主模型:
編輯配置文件26.210:vim /etc/my.cnf.d/server.cnf
在配置文件中加入以前幾個參數設置:
log-bin=mysql-bin
server-id = 210
relay-log =relay-bin
編輯配置文件26.211:vim /etc/my.cnf.d/server.cnf
log-bin =mysql-bin
server-id = 211
relay-log = relay-bin
分別啟動兩臺服務器的MYSQL服務:service mysql start
服務器設置雙主:
26.210:
mysql
grant replication slave ,replication client on *.* to 'jerry'@'192.168.%.%' identified by 'jerrypass';
change master to master_host='192.168.26.211',master_user='jerrymy',master_password='jerrypass',master_log_file='mysql-bin.000006',master_log_pos=558;
start slave;
show slave status\G; #查看從狀態IO和SQL 運行狀態均為YES表示配置成功
26.211:
mysql
grant replication slave ,replication client on *.* to 'jerrymy'@'192.168.%.%' identified by 'jerrypass';
change master to master_host='192.168.26.210',master_user='jerry',master_password='jerrypass',master_log_file='mysql-bin.000007',master_log_pos=540;
start slave;
show slave status\G; #查看從狀態IO和SQL 運行狀態均為YES表示配置成功
顯示狀態為成功,我們再創建數據庫來測試,看看雙主是否運行正常。
雙主設置成功。
26.210:安裝Keepalived
安裝報錯未安裝gcc
yum -y install gcc
yum -y install openssl-devel
安裝組件后編譯成功:
編輯配置文件:vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 20
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.27.210
}
}
virtual_server 192.168.27.210 3306 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.26.210 3306 {
weight 1
notify_down /etc/keepalived/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 2
delay_before_retry 1
}
}
}
保存退出啟動Keepalived服務。
service keepalived start
26.211:安裝Keepalived。
編輯配置文件26.211: vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 20
priority 99
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.27.210
}
}
virtual_server 192.168.27.210 3306 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.26.211 3306 {
weight 1
notify_down /etc/keepalived/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 2
delay_before_retry 1
}
}
}
保存退出啟動26.211上的Keepalived
service keepalived start
測試VIP是否可用:ping 192.168.27.210 -t
回到26.210或211都可以 上,創建一個數據庫訪問測試用戶賬號密碼。
grant all on *.* to 'jerrytest'@'192.168.%.%' identified by 'jerrypass';
下面通過 VIP訪問數據庫觀察訪問:
VIP在26.210這臺服務器上,因此我們訪問的26.210上的數據庫。
下面停掉26.210上的MYSQL觀察:
首先觀察VIP網絡出現波動后恢復。
數據庫訪問成功:
VIP已經轉移動26.211服務器上了。
我們再恢復26.210上的MYSQL數據庫服務觀察。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。