LVS和keepalived安装过的配置语句

来源:互联网 发布:unity3d有安卓版吗 编辑:程序博客网 时间:2024/06/05 06:02

1.LB安装
apt-get install ipvsadm
2.LB配置
#!/bin/bash
vip=10.5.0.200
rs1=10.5.0.171
rs2=10.5.0.121
#
/sbin/ifconfig eth0:0 10.43.1.4 broadcast 10.43.1.4 netmask 255.255.255.255 up
/sbin/route add -host 10.43.1.4 dev eth0:0
#clear ipvs tables
/sbin/ipvsadm -C
#set LVS  Server
/sbin/ipvsadm -A -t 10.43.1.4:80 -s rr
/sbin/ipvsadm -a -t 10.43.1.4:80 -r 10.43.1.7:80 -g
/sbin/ipvsadm -a -t 10.43.1.4:80 -r 10.43.1.8:80 -g
#run lvs
/sbin/ipvsadm
# update /etc/sysctl.conf
#echo "0" >/proc/sys/net/ipv4/ip_forward
#echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
#echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
#echo "1" >/proc/sys/net/ipv4/conf/eth0/send_redirects
#/sbin/sysctl -p
3.RS配置
#!/bin/bash
vip=10.5.0.200
/sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
/sbin/route add -host $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
/sbin/sysctl -p

 

在linux安装LVS后,配置的广播地址,以后负载的真实服务器,真实服务器最好要使用物理机,不要用到虚拟机服务器。因为LVS-DR模式,请求数据里通过IP对应的MAC物理地址。(因为虚拟机的MAC地址和物理主机上有关联原因),导致只会找到主机的MAC地址。

======================================================

1.LB安装
apt-get install ipvsadm
2.LB配置
#!/bin/bash
vip=10.43.1.190
rs1=10.43.1.7
rs2=10.43.1.8

/sbin/ifconfig eth4:0 10.43.1.190 broadcast 10.43.1.190 netmask 255.255.255.255 up
/sbin/route add -host 10.43.1.190 dev eth4:0

/sbin/ifconfig eth0:0 10.43.1.190 broadcast 10.43.1.190 netmask 255.255.255.255 up
/sbin/route add -host 10.43.1.190 dev eth0:0

/sbin/ifconfig eth0:0 10.43.1.120 broadcast 10.43.1.120 netmask 255.255.255.255 up
/sbin/route add -host 10.43.1.120 dev eth0:0


#clear ipvs tables
/sbin/ipvsadm -C
#set LVS  Server
/sbin/ipvsadm -A -t 10.43.1.190:8888 -s wrr
/sbin/ipvsadm -a -t 10.43.1.190:8888 -r 10.43.1.9:8888  -w 1
/sbin/ipvsadm -a -t 10.43.1.190:8888 -r 10.43.1.200:8888  -w 1

/sbin/ipvsadm -A -t 10.43.1.120:80 -s rr
/sbin/ipvsadm -a -t 10.43.1.120:80 -r 10.43.1.12:80 -g
/sbin/ipvsadm -a -t 10.43.1.120:80 -r 10.43.1.11:80 -g
/sbin/ipvsadm -a -t 10.43.1.120:80 -r 10.43.1.8:80 -g


#run lvs
/sbin/ipvsadm
update /etc/sysctl.conf
echo "0" >/proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/eth0/send_redirects
/sbin/sysctl -p
3.RS配置
#!/bin/bash
vip=10.43.1.190
/sbin/ifconfig lo:0 10.43.1.180 broadcast 10.43.1.180 netmask 255.255.255.255 up
/sbin/route add -host 10.43.1.180 dev lo:0

/sbin/ifconfig lo:0 10.43.1.120 broadcast 10.43.1.120 netmask 255.255.255.255 up
/sbin/route add -host 10.43.1.120 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
/sbin/sysctl -p


4.windows
netsh interface ipv4 set interface  "本地连接 2" weakhostreceive=enabled

netsh interface ipv4 set interface "本地连接 2" weakhostsend=enabled

netsh interface ipv4 set interface "realserver" weakhostreceive=enabled
netsh interface ipv4 set interface "realserver" weakhostsend=enabled

=========================================

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state SLAVE       #指定Keepalived的角色,MASTER为主机服务器,BACKUP为备用服务器
    interface eth4
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.43.1.180
    }
}

virtual_server 10.43.1.180 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
   
    protocol TCP


    real_server 10.43.1.11 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
    real_server 10.43.1.12 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
}

 

=================================

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state SLAVE       #指定Keepalived的角色,MASTER为主机服务器,BACKUP为备用服务器
    interface eth4
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.43.1.180
    }
}

virtual_server 10.43.1.180 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
   
    protocol TCP


    real_server 10.43.1.11 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
    real_server 10.43.1.12 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
}

 

========================================

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.43.1.120
    }
}

virtual_server 10.43.1.120 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.255
    protocol TCP

    real_server 10.43.1.8 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
    real_server 10.43.1.11 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
    real_server 10.43.1.12 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
}

===========================================

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.43.1.120
    }
}

virtual_server 10.43.1.120 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.255
    protocol TCP

    real_server 10.43.1.8 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
    real_server 10.43.1.11 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }
    real_server 10.43.1.12 80 {
        weight 1
        TCP_CHECK {
          connect_port 80
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
        }
    }

 

0 0