[原创]lvs+ospf+nginx实现高可用大流量web架构

lvs+ospf+nginx实现高可用大流量web架构配置总概述

架构图:

[原创]lvs+ospf+nginx实现高可用大流量web架构_第1张图片

 

配置如下:
1.quagga之zebra配置:
# cat /etc/quagga/zebra.conf 
!
! Zebra configuration saved from vty
!   2015/09/02 13:17:32
!
hostname Router
password zebra
enable password zebra
!
interface eth0
 ipv6 nd suppress-ra
!
interface eth1
 ipv6 nd suppress-ra
!
interface lo
!
access-list 10 deny any
!
route-map denyany deny 10
 match ip address 10
!
!
ip protocol ospf route-map denyany
!
line vty
!

2.quagga之ospf配置:
# cat /etc/quagga/ospfd.conf
!
! Zebra configuration saved from vty
!   2018/03/10 22:27:05
!
hostname ospfd
password zebra
log stdout
log file /var/log/quagga/ospf.log
!
!
!
interface eth0
ip ospf hello-interval 1
ip ospf dead-interval 3
ip ospf priority 0 


!
router ospf
ospf router-id LOCAL_IP
  network LOCAL_IP_net/mask area 0.0.0.0
  network VIP1/32 area 0.0.0.0
  network VIP2/32 area 0.0.0.0
  network VIP3/32 area 0.0.0.0
 !
line vty
!

3.keepalive的配置:
# cat keepalived.conf
# Configuration File for keepalived
global_defs {
    router_id LVS_DEVEL
}

virtual_server VIP1 80 {
    delay_loop 6
    lb_algo  wrr
    lb_kind TUN
    persistence_timeout 0
    protocol TCP

    real_server RS1_IP 80 {
        weight 10
        TCP_CHECK {
            connect_port 80
            connect_timeout 8
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server RS2_IP 80 {
        weight 10
        TCP_CHECK {
            connect_port 80
            connect_timeout 8
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

4.lvs节点的vip配置脚本配置:
# cat lvs_ospf_vip
#!/bin/bash

#description : VIP configuration.
VIP1=xxx.xxx.xxx.xxx
VIP2=xxx.xxx.xxx.xxx
VIP3=xxx.xxx.xxx.xxx

STATUS=0
case "$1" in
    start)
        ip addr add ${VIP1}/32 dev lo:${VIP1#*.} label lo:${VIP1#*.}  || STATUS=1
        ip addr add ${VIP2}/32 dev lo:${VIP1#*.} label lo:${VIP2#*.}  || STATUS=1
        ip addr add ${VIP3}/32 dev lo:${VIP1#*.} label lo:${VIP3#*.}  || STATUS=1 

        [ $STATUS -eq 0 ] && echo 'Start VIP ok.'  || echo 'Start VIP failed.'
    ;;
    stop)
        VIPS=`ip addr show label "lo:*"|awk '{print $2}'|cut -d'/' -f1`
        for VIP in ${VIPS}
        do
            ip addr del ${VIP}/32 dev lo || STATUS=1
        done
        [ $STATUS -eq 0 ] && echo 'Stop VIP ok.' || echo 'Stop VIP failed.'
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    *)
    echo 'Usage: $0 {start|stop|restart}'
    exit 1
esac 

5.nginx后端代理节点的lvs脚本配置:
# cat lvs_real_tun 
#!/bin/bash

#description : start realserver
VIP1=xxx.xxx.xxx.xxx
VIP2=xxx.xxx.xxx.xxx
VIP3=xxx.xxx.xxx.xxx
#/etc/rc.d/init.d/functions
case "$1" in
start)
        echo " start LVS of REALServer"
        /sbin/modprobe ipip
        /sbin/ifconfig tunl0 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
        /sbin/ifconfig tunl0:1 $VIP2 broadcast $VIP2 netmask 255.255.255.255 up
        /sbin/ifconfig tunl0:2 $VIP3 broadcast $VIP3 netmask 255.255.255.255 up
        /sbin/route add -host $VIP1 dev tunl0
        /sbin/route add -host $VIP2 dev tunl0:1
        /sbin/route add -host $VIP3 dev tunl0:2
        #echo "0" >/proc/sys/net/ipv4/ip_forward
        echo "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/tunl0/arp_announce
        echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
        echo "0" >/proc/sys/net/ipv4/conf/tunl0/rp_filter
        echo "0" >/proc/sys/net/ipv4/conf/all/rp_filter
        sysctl -p >/dev/null 2>&1
        /sbin/ifconfig eth0 mtu 1440
;;
stop)
        echo " stop LVS of RealServer"
        echo "0" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
        echo "0" >/proc/sys/net/ipv4/conf/tunl0/arp_announce
        echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
        echo "1" >/proc/sys/net/ipv4/conf/tunl0/rp_filter
        echo "1" >/proc/sys/net/ipv4/conf/all/rp_filter
        /sbin/ifconfig tunl0 down
        /sbin/modprobe -r ipip
        /sbin/ifconfig eth0 mtu 1500
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

 

转载于:https://www.cnblogs.com/wsjhk/p/8943436.html

你可能感兴趣的:([原创]lvs+ospf+nginx实现高可用大流量web架构)