keepalived学习
keepalived学习
wzyuliyang 发表于2年前
keepalived学习
  • 发表于 2年前
  • 阅读 72
  • 收藏 3
  • 点赞 0
  • 评论 0

移动开发云端新模式探索实践 >>>   

keepalived学习

192.168.10.150 k1
192.168.10.151 k2
192.168.10.152 f1
192.168.10.153 f2
192.168.10.154 f3
192.168.10.155 f4

###备份keepalived的配置文件

! Configuration File for keepalived
global_defs {
   router_id LVS_DEVEL_RGW
}
vrrp_instance VI_RGW_1 {
    state BACKUP
    interface eno16777736
    virtual_router_id 239
    priority 95
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass onest123
    }
    virtual_ipaddress {
        192.168.10.160
  }
}
virtual_server  192.168.10.160 80 { 
    delay_loop 6
    lb_algo wlc
    lb_kind DR
#   persistence_timeout 0
    protocol TCP

    real_server  192.168.10.152 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.10.153 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
    real_server  192.168.10.154 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
}

###主keepalived的配置文件

! Configuration File for keepalived
global_defs {
   router_id LVS_DEVEL_RGW
}
vrrp_instance VI_RGW_1 {
    state MASTER
    interface eno16777736
    virtual_router_id 239
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass onest123
    }
    virtual_ipaddress {
        192.168.10.160
  }
}
virtual_server  192.168.10.160 80 { 
    delay_loop 6
    lb_algo wlc
    lb_kind DR
#   persistence_timeout 0
    protocol TCP

    real_server  192.168.10.152 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.10.153 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
    real_server  192.168.10.154 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
}

###绑定lo虚拟ip脚本

[root@f1 ~]# cat /etc/lvs/lvs_rgw.sh #设置systemctl开机启动
#!/bin/bash
# description: Config realserver
RGW_VIP=192.168.10.160 
. /etc/rc.d/init.d/functions
case "$1" in
start)
       /sbin/ifconfig lo:0 $RGW_VIP netmask 255.255.255.255 broadcast $RGW_VIP up
       /sbin/route add -host $RGW_VIP dev lo:0
       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
       sysctl -p >/dev/null 2>&1
       echo "RealServer Start OK"
       ;;
stop)
       /sbin/ifconfig lo:0 down
       /sbin/route del $RGW_VIP >/dev/null 2>&1
       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
       echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
       echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
       echo "RealServer Stoped"
       ;;
*)
       echo "Usage: $0 {start|stop}"
       exit 1
esac
exit 0

f1.f2.f3.f4上都有192.168.10.160/32

[root@f1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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
       valid_lft forever preferred_lft forever
    inet 192.168.10.160/32 brd 192.168.10.160 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
#开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
#开放keepalived相关端口
firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 --out-interface eno16777736 --destination 224.0.0.18 --protocol vrrp -j ACCEPT
#开放keepalived相关端口
firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --in-interface eno16777736 --destination 224.0.0.18 --protocol vrrp -j ACCEPT
#reload
firewall-cmd --reload    

###并发访问测试

7:19 yuliyang@yuliyang-PC /home/yuliyang
% echo `seq 1 10000` | xargs -n 1 -P 100  sh -c  'curl http://192.168.10.160/'

##不部署lvs的配置

主keepalived:第一个rgw上安装keepalived并且配置/etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {
    notification_email {
        test@example.com
    }
    notification_email_from itsection@example.com
    smtp_server mail.example.com
    smtp_connect_timeout 30
    router_id LVS_DEVEL
}

vrrp_script chk_rgw {
#    script "killall -0 nginx"
    script "/etc/keepalived/check_rgw.sh" 
    interval 2 
    weight -5 
    fall 3  
    rise 2 
}

vrrp_instance VI_1 {
    state MASTER
    interface eno16777728
#   mcast_src_ip 172.29.88.224
    virtual_router_id 51
    priority 101
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.161
    }
    track_script {
       chk_rgw 
    }
}

从keepalived:第二个rgw上安装keepalived并且配置/etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {
    notification_email {
        test@example.com
    }
    notification_email_from itsection@example.com
    smtp_server mail.example.com
    smtp_connect_timeout 30
    router_id LVS_DEVEL
}

vrrp_script chk_rgw {
#    script "killall -0 nginx"
    script "/etc/keepalived/check_rgw.sh"
    interval 2
    weight -5
    fall 3
    rise 2
}

vrrp_instance VI_1 {
    state BACKUP
    interface eno16777728
#   mcast_src_ip 172.29.88.224
    virtual_router_id 51
    priority 100
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.161
    }
    track_script {
       chk_rgw
    }
}

#rgw挂掉再拉起来的脚本

[root@ceph02 ~]# cat /etc/keepalived/check_rgw.sh 
#!/bin/bash
counter=$(ps -C radosgw  --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
    /usr/bin/radosgw -f --cluster ceph --name client.rgw.ceph02 --setuser ceph --setgroup ceph
    sleep 2
    counter=$(ps -C radosgw  --no-heading|wc -l)
    if [ "${counter}" = "0" ]; then
        /etc/init.d/keepalived stop
    fi
fi
标签: Keepalived
  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 3
博文 19
码字总数 16746
作品 1
×
wzyuliyang
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: