基於keepalived Mysql雙主熱備配置
基於keepalived雙主熱備:
一.環境:
OS:CentOS 6.5 X64
DB Version:Percona Mysql 5.7.15-9-log
路徑:/app/mysql57
資料檔案路徑:/data/mysql57/data
DB1:192.168.213.4
DB2:192.168.213.5
二.安裝keepalived包(兩臺主機都需操作)
1.下載keepalived包
cd /usr/local/tools
wget
2.安裝所需包
yum -y install openssl-devel
3.安裝keepalived
mkdir -pv /app/keepalived
cd /usr/local/tools
tar xf keepalived-1.2.23.tar.gz
cd keepalived-1.2.23
./configure --prefix=/app/keepalived/
make
make install
4.配置keepalived
cp /app/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
cp /app/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
cp /app/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /app/keepalived/sbin/keepalived /usr/sbin/
db01 keepalived配置
cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
state MASTER
interface eth0 !虛擬IP對應介面,也就是業務介面對應的網路卡編號
virtual_router_id 51
priority 105 !權重
advert_int 1
nopreempt !自己上線後不搶佔當前 master 的位置,即使其權重比自己低
virtual_ipaddress {
192.168.213.100 !VIP
}
track_script {
chk_mysql !啟用頭部定義的檢查MySQL狀態的指令碼
}
}
virtual_server 192.168.213.100 3306 {
delay_loop 3
lb_algo rr
lb_kind NAT
persistence_timeout 60
protocol TCP sorry_server 192.168.213.5 3306 ! real_server 掛掉後臨時使用 sorry_server 頂上
real_server 192.168.213.4 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
}
}
}
db02 keepalived配置
[root@ORADB-213-5 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
state BACKUP
interface eth0 !虛擬IP對應介面,也就是業務介面對應的網路卡編號
virtual_router_id 51
priority 100 !權重
advert_int 1
nopreempt !自己上線後不搶佔當前 master 的位置,即使其權重比自己低
virtual_ipaddress {
192.168.213.100 !VIP
}
track_script {
chk_mysql !啟用頭部定義的檢查MySQL狀態的指令碼
}
}
virtual_server 192.168.213.100 3306 {
delay_loop 3
lb_algo rr
lb_kind NAT
persistence_timeout 60
protocol TCP sorry_server 192.168.213.4 3306 ! real_server 掛掉後臨時使用 sorry_server 頂上
real_server 192.168.213.5 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
}
}
}
5.兩臺DB啟動keepalived
/etc/init.d/keepalived start
檢視VIP
[root@ORA11G-213-4 keepalived-1.2.23]# ip addr
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:c7:d5:27 brd ff:ff:ff:ff:ff:ff
inet 192.168.213.4/24 brd 192.168.213.255 scope global eth0
inet 192.168.213.100/32 scope global eth0
inet6 fe80::20c:29ff:fec7:d527/64 scope link
valid_lft forever preferred_lft forever
測試
[root@ORA11G-213-4 keepalived-1.2.23]# mysql -unetdata -pnetdata -h 192.168.213.100
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2881
Server version: 5.7.15-9-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
netdata@192.168.213.100 23:41: [(none)]> system ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:C7:D5:27
inet addr:192.168.213.4 Bcast:192.168.213.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec7:d527/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:156643 errors:0 dropped:0 overruns:0 frame:0
TX packets:191173 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:39459924 (37.6 MiB) TX bytes:31911844 (30.4 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:17378 errors:0 dropped:0 overruns:0 frame:0
TX packets:17378 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1002566 (979.0 KiB) TX bytes:1002566 (979.0 KiB)
停止掉db01
[root@ORA11G-213-4 keepalived-1.2.23]# /etc/init.d/mysql57 stop
Shutting down MySQL (Percona Server)............. SUCCESS!
檢視db02
[root@ORADB-213-5 ~]# ip addr
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:54:39 brd ff:ff:ff:ff:ff:ff
inet 192.168.213.5/24 brd 192.168.213.255 scope global eth0
inet 192.168.213.100/32 scope global eth0
inet6 fe80::20c:29ff:fe63:5439/64 scope link
valid_lft forever preferred_lft forever
VIP已經飄移過來
一.環境:
OS:CentOS 6.5 X64
DB Version:Percona Mysql 5.7.15-9-log
路徑:/app/mysql57
資料檔案路徑:/data/mysql57/data
DB1:192.168.213.4
DB2:192.168.213.5
二.安裝keepalived包(兩臺主機都需操作)
1.下載keepalived包
cd /usr/local/tools
wget
2.安裝所需包
yum -y install openssl-devel
3.安裝keepalived
mkdir -pv /app/keepalived
cd /usr/local/tools
tar xf keepalived-1.2.23.tar.gz
cd keepalived-1.2.23
./configure --prefix=/app/keepalived/
make
make install
4.配置keepalived
cp /app/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
cp /app/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
cp /app/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /app/keepalived/sbin/keepalived /usr/sbin/
db01 keepalived配置
cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
state MASTER
interface eth0 !虛擬IP對應介面,也就是業務介面對應的網路卡編號
virtual_router_id 51
priority 105 !權重
advert_int 1
nopreempt !自己上線後不搶佔當前 master 的位置,即使其權重比自己低
virtual_ipaddress {
192.168.213.100 !VIP
}
track_script {
chk_mysql !啟用頭部定義的檢查MySQL狀態的指令碼
}
}
virtual_server 192.168.213.100 3306 {
delay_loop 3
lb_algo rr
lb_kind NAT
persistence_timeout 60
protocol TCP sorry_server 192.168.213.5 3306 ! real_server 掛掉後臨時使用 sorry_server 頂上
real_server 192.168.213.4 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
}
}
}
db02 keepalived配置
[root@ORADB-213-5 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
state BACKUP
interface eth0 !虛擬IP對應介面,也就是業務介面對應的網路卡編號
virtual_router_id 51
priority 100 !權重
advert_int 1
nopreempt !自己上線後不搶佔當前 master 的位置,即使其權重比自己低
virtual_ipaddress {
192.168.213.100 !VIP
}
track_script {
chk_mysql !啟用頭部定義的檢查MySQL狀態的指令碼
}
}
virtual_server 192.168.213.100 3306 {
delay_loop 3
lb_algo rr
lb_kind NAT
persistence_timeout 60
protocol TCP sorry_server 192.168.213.4 3306 ! real_server 掛掉後臨時使用 sorry_server 頂上
real_server 192.168.213.5 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
}
}
}
5.兩臺DB啟動keepalived
/etc/init.d/keepalived start
檢視VIP
[root@ORA11G-213-4 keepalived-1.2.23]# ip addr
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:c7:d5:27 brd ff:ff:ff:ff:ff:ff
inet 192.168.213.4/24 brd 192.168.213.255 scope global eth0
inet 192.168.213.100/32 scope global eth0
inet6 fe80::20c:29ff:fec7:d527/64 scope link
valid_lft forever preferred_lft forever
測試
[root@ORA11G-213-4 keepalived-1.2.23]# mysql -unetdata -pnetdata -h 192.168.213.100
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2881
Server version: 5.7.15-9-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
netdata@192.168.213.100 23:41: [(none)]> system ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:C7:D5:27
inet addr:192.168.213.4 Bcast:192.168.213.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec7:d527/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:156643 errors:0 dropped:0 overruns:0 frame:0
TX packets:191173 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:39459924 (37.6 MiB) TX bytes:31911844 (30.4 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:17378 errors:0 dropped:0 overruns:0 frame:0
TX packets:17378 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1002566 (979.0 KiB) TX bytes:1002566 (979.0 KiB)
停止掉db01
[root@ORA11G-213-4 keepalived-1.2.23]# /etc/init.d/mysql57 stop
Shutting down MySQL (Percona Server)............. SUCCESS!
檢視db02
[root@ORADB-213-5 ~]# ip addr
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:54:39 brd ff:ff:ff:ff:ff:ff
inet 192.168.213.5/24 brd 192.168.213.255 scope global eth0
inet 192.168.213.100/32 scope global eth0
inet6 fe80::20c:29ff:fe63:5439/64 scope link
valid_lft forever preferred_lft forever
VIP已經飄移過來
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24486203/viewspace-2128669/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Keepalived - Keepalived 實現 tomcat雙機熱備Tomcat
- MySQL 主從複製,雙機熱備MySql
- Keepalived雙機熱備實現高可用
- 基於MySQL雙主複製架構下部署LVS+KeepAlived負載均衡MySql架構負載
- MySQL 高可用性—keepalived+mysql雙主MySql
- linux上mysql MM(雙主)及keepalived搭建LinuxMySql
- 使用Keepalived實現Nginx的自動重啟及雙主熱備高可用Nginx
- MySQL雙主雙從配置MySql
- MySQL叢集搭建(6)-雙主+keepalived高可用MySql
- keepalived 主備使用
- MySQL主從配置及haproxy和keepalived搭建MySql
- mysql雙主雙從 搭建配置MySql
- Redis高可用方案:使用Keepalived實現主備雙活Redis
- 使用Keepalived實現Nginx的雙機主備高可用Nginx
- 基於Linux的mysql主從配置LinuxMySql
- MySQL備份與主備配置MySql
- 防火牆的雙機熱備1:主備、負載方式防火牆負載
- MySQL雙機互備熱備自動切換KVMySql
- keepalived配置redis主從切換Redis
- MySQL主從配置及mysqldump備份MySql
- MySQL主主模式+Keepalived高可用MySql模式
- 怎麼在linux完成MySQL主從熱備?LinuxMySql
- MySQL進階:主主複製+Keepalived高可用MySql
- 你需要了解的高可用方案之使用keepalived搭建雙機熱備一覽
- mysql5.6主主複製及keepalived 高可用MySql
- 9、雙機熱備
- MySQL 主備MySql
- 生產環境部署Nginx伺服器雙機熱備部署-keepalived(多種模式教程)Nginx伺服器模式
- 基於GTID搭建主從MySQLMySql
- Mysql 基於GTID主從複製MySql
- 基於MySQL Cluster + LVS + KeepAlived部署負載均衡高可用架構MySql負載架構
- centos7上配置mysql8的雙主互寫CentOSMySql
- MYSQL8+CENTOS7.6 主從+keepalived搭建總結MySqlCentOS
- 解讀MySQL雙主複製的主備資料一致性GPMySql
- 基於Linux的docker mysql主從搭建LinuxDockerMySql
- mysql主從配置MySql
- HCIE Security 雙機熱備 備考筆記(幕布)筆記
- mysql 5.7+keepalived主從切換步驟簡述MySql
- mysql的冷備份與熱備份MySql