兩個 haproxy 不搶佔
- 環境
- haproxy 服務器
- haproxy101: 10.1.1.101
- haproxy102: 10.1.1.102
- 虛擬地址
- ip: 10.1.1.100
- haproxy 服務器
- 在全部 haproxy 服務器上安裝 keepalived
yum install keepalived
- 在全部 haproxy 服務器上配置 haproxy 和 keepalived 自啓動
systemctl enable haproxy systemctl enable keepalived
- MASTER/BACKUP 完整配置
global_defs { router_id haproxy101 #BACKUP 這裏是 haproxy102 script_user root enable_script_security } vrrp_script chk_haproxy { script "/usr/bin/systemctl status haproxy" interval 2 weight 0 fall 2 rise 2 } vrrp_instance VI_1 { state BACKUP #MASTER 和 BACKUP 這裏都是 BACKUP virtual_router_id 1 priority 150 #BACKUP 這裏是 100 advert_int 2 nopreempt #BACKUP 優先級低,需註釋此行 interface eth0 track_script { chk_haproxy } authentication { auth_type PASS auth_pass 1011100 } virtual_ipaddress { 10.1.1.100/24 dev eth0 } }
兩個 LVS-DR 調度器不搶佔均衡後端 MySQL 和 Ceph 負載
- 環境
- keepalived 服務器
- ka101: 10.1.1.101
- ka102: 10.1.1.102
- 虛擬地址
- ip: 10.1.1.100
- mysqld 服務器
- mysql103: 10.1.1.103
- mysql104: 10.1.1.104
- mysql105: 10.1.1.105
- ceph-radosgw 服務器
- ceph106: 10.1.1.106
- ceph107: 10.1.1.107
- ceph108: 10.1.1.108
- keepalived 服務器
- 在全部 keepalived 服務器上安裝 keepalived
yum install keepalived
- 在全部 keepalived 服務器上配置 keepalived 自啓動
systemctl enable keepalived
- MASTER/BACKUP 完整配置
- 全局和實例配置
global_defs { router_id keepalive101 #BACKUP 配置 keepalive102 } vrrp_instance V1_1 { state BACKUP #BACKUP 也配置 BACKUP interface eth0 virtual_router_id 1 priority 150 #BACKUP 配置 100 advert_int 1 nopreempt #BACKUP 優先級低,需註釋此行 authentication { auth_type PASS auth_pass 1011100 } virtual_ipaddress { 10.1.1.100/24 dev eth0 } }
- LVS 均衡 mysql galera cluser 負載
virtual_server 10.1.1.100 3306 { delay_loop 16 lb_algo sh lb_kind DR protocol TCP real_server 10.1.1.103 3306 { weight 1 TCP_CHECK { connect_timeout 4 delay_before_retry 2 connect_port 3306 } } real_server 10.1.1.104 3306 { weight 1 TCP_CHECK { connect_timeout 4 delay_before_retry 2 connect_port 3306 } } real_server 10.1.1.105 3306 { weight 1 TCP_CHECK { connect_timeout 4 delay_before_retry 2 connect_port 3306 } } }
- LVS 均衡 ceph radosgw 負載
virtual_server 10.1.1.100 7480 { delay_loop 16 lb_algo sh lb_kind DR protocol TCP real_server 10.1.1.106 7480 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 8 nb_get_retry 2 delay_before_retry 2 connect_port 7480 } } real_server 10.1.1.107 7480 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 8 nb_get_retry 2 delay_before_retry 2 connect_port 7480 } } real_server 10.1.1.108 7480 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 8 nb_get_retry 2 delay_before_retry 2 connect_port 7480 } } }
- 全局和實例配置
- 在全部 mysql 和 ceph-radosgw 服務器上配置虛擬 ip
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce ip addr add 10.1.1.100/32 brd 10.1.1.100 dev lo ip route add 10.1.1.100 dev lo
不搶佔自動切換兩臺 Redis 主從狀態
- 環境
- Redis 服務器
- redis101: 10.1.1.101
- redis102: 10.1.1.102
- 虛擬地址
- ip: 10.1.1.100
- Redis 服務器
- 在全部 redis 服務器上安裝 keepalived
yum install keepalived
- 在全部 redis 服務器上配置 redis 和 keepalived 自啓動
systemctl enable redis systemctl enable keepalived
- MASTER/BACKUP 完整配置
global_defs { router_id redis101 #BACKUP 這裏是 redis102 script_user root enable_script_security } vrrp_script chk_redis { script "/usr/bin/systemctl status redis" interval 2 weight 0 fall 2 rise 2 } vrrp_instance VI_1 { state BACKUP #MASTER 和 BACKUP 這裏都是 BACKUP virtual_router_id 51 priority 150 #BACKUP 這裏是 100 advert_int 1 nopreempt #BACKUP 優先級低,需註釋此行 interface eth0 notify_master /etc/keepalived/scripts/master.sh notify_backup /etc/keepalived/scripts/backup.sh track_script { chk_redis } authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 10.1.1.100/24 dev eth0 } }
- 在全部 redis 服務器上創建 /etc/keepalived/scripts/master.sh 腳本,內容如下
#!/bin/bash # /usr/bin/sed -i '/^slaveof/d' /etc/redis.conf /usr/bin/systemctl restart redis
- 在 redis101 上創建 /etc/keepalived/scripts/backup.sh 腳本,內容如下
#!/bin/bash # /usr/bin/sed -i '/^slaveof/d' /etc/redis.conf echo 'slaveof 10.1.1.102 6379' >> /etc/redis.conf /usr/bin/systemctl restart redis
- 在 redis102 上創建 /etc/keepalived/scripts/backup.sh 腳本,內容如下
#!/bin/bash # /usr/bin/sed -i '/^slaveof/d' /etc/redis.conf echo 'slaveof 10.1.1.101 6379' >> /etc/redis.conf /usr/bin/systemctl restart redis
- 在全部 redis 服務器上賦予腳本可執行權限
chmod 0755 /etc/keepalived/scripts/*.sh
- 在全部 redis 服務器上啓動 redis 和 keepalived 服務
systemctl start redis systemctl start keepalived