keepalived学习

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

转载于:https://my.oschina.net/leeyoung/blog/777633

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值