第10天 LVS及双机KEEPALIVED

1.yum install ipvsadm或www.linuxvirtualserver.org下载

2.工作模式:NAT|TUN|DR;调度算法:rr,wrr,lc,wlc


3.

DR

ipvsadm -A -t 192.168.8.100:80 -s rr

ipvsadm -A -t 192.168.8.200:80 -s rr -p 60


ipvsadm -a  -t 192.168.8.200:80   -r 192.168.8.11:80  -g -w 100 

ipvsadm -a  -t 192.168.8.200:80   -r 192.168.8.12:80  -g -w 100 

ipvsadm -a  -t 192.168.8.200:80   -r 192.168.8.13:80  -g -w 100 


ipvsadm -d -t 192.168.8.200:80   -r 192.168.8.14:80


写入配置文件 cat /etc/sysconfig/ipvsadm

-A -t 192.168.8.100:80 -s rr

-A -t 192.168.8.200:80 -s rr -p 60

-a -t 192.168.8.200:80 -r 192.168.8.11:80 -g -w 100

-a -t 192.168.8.200:80 -r 192.168.8.12:80 -g -w 100

-a -t 192.168.8.200:80 -r 192.168.8.13:80 -g -w 100


NAT

ip_forward=1

iptables -t nat -A POSTROUTING -s 1.1.1.0/24 -o eth0 -j SNAT --to-source 2.2.2.2


ipvsadm -A -t 192.168.8.150:80 -s rr

ipvsadm -a -t 192.168.8.150:80 -r 172.20.20.20:80 -m -w 20

ipvsadm -a -t 192.168.8.150:80 -r 172.20.20.21:80 -m -w 20

ipvsadm -a -t 192.168.8.150:80 -r 172.20.20.22:80 -m -w 20



4.DR模式,都要关闭VIP共用问题,避免arp解析异常,关闭重定向参数响应

sysctl -w net.ipv4.conf.all.send_redirects=0

sysctl -w net.ipv4.conf.default.send_redirects=0

sysctl -w net.ipv4.conf.em1.send_redirects=0


5.WEB节点REALSERVER服务器

ifconfig lo:0 192.168.8.200 netmask 255.255.255.255

route add -host 192.168.8.200 dev lo:0


 sysctl -w net.ipv4.conf.all.arp_ignore=1

 sysctl -w net.ipv4.conf.all.arp_announce=2

 sysctl -w net.ipv4.conf.default.arp_ignore=1

 sysctl -w net.ipv4.conf.default.arp_announce=2

 sysctl -w net.ipv4.conf.lo.arp_ignore=1

 sysctl -w net.ipv4.conf.lo.arp_announce=2




6. KEEPALVED及LVS双机配置

 

yum install kernel-devel openssl-devel popt-devel

yum install keepalived或www.keepalived.org



7.

! Configuration File for keepalived


global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id webrb1

}


vrrp_instance VI_rb1 {

    state MASTER

    interface em1

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 11112222

    }

    virtual_ipaddress {

        192.168.8.100

        192.168.8.200

    }

}



8.

! Configuration File for keepalived


global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id webrb2

}


vrrp_instance VI_rb1 {

    state BACKUP

    interface em1

    virtual_router_id 51

    priority 90

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 11112222

    }

    virtual_ipaddress {

        192.168.8.100

        192.168.8.200

    }

}



9.

分别启动服务

service keepalived restart

10.查看IP效果

第1台: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

    link/ether 90:b1:1c:11:98:ef brd ff:ff:ff:ff:ff:ff

    inet 172.22.2.180/24 brd 172.22.2.255 scope global em1

    inet 192.168.8.100/32 scope global em1

    inet 192.168.8.200/32 scope global em1

    inet6 fe80::92b1:1cff:fe11:98ef/64 scope link 

       valid_lft forever preferred_lft forever


第2台:

em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

    link/ether 90:b1:1c:0e:97:1a brd ff:ff:ff:ff:ff:ff

    inet 172.22.2.181/24 brd 172.22.2.255 scope global em1

    inet6 fe80::92b1:1cff:fe0e:971a/64 scope link 

       valid_lft forever preferred_lft forever


Aug 27 13:11:22 cecgw-zs-cdb01 Keepalived[641]: Stopping Keepalived v1.2.7 (02/21,2013)

Aug 27 13:11:22 cecgw-zs-cdb01 Keepalived_vrrp[643]: VRRP_Instance(VI_rb1) sending 0 priority

Aug 27 13:11:22 cecgw-zs-cdb01 Keepalived_vrrp[643]: VRRP_Instance(VI_rb1) removing protocol VIPs.

Aug 27 13:11:22 cecgw-zs-cdb01 avahi-daemon[9028]: Withdrawing address record for 192.168.8.100 on em1.

Aug 27 13:11:22 cecgw-zs-cdb01 avahi-daemon[9028]: Withdrawing address record for 192.168.8.200 on em1.       


Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Entering MASTER STATE

Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) setting protocol VIPs.

Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Sending gratuitous ARPs on em1 for 192.168.8.100

Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Sending gratuitous ARPs on em1 for 192.168.8.200

Aug 27 13:11:24 cecgw-zs-cdb02 avahi-daemon[1806]: Registering new address record for 192.168.8.100 on em1.IPv4.

Aug 27 13:11:24 cecgw-zs-cdb02 avahi-daemon[1806]: Registering new address record for 192.168.8.200 on em1.IPv4.

Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_healthcheckers[30333]: Netlink reflector reports IP 192.168.8.100 added

Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_healthcheckers[30333]: Netlink reflector reports IP 192.168.8.200 added

Aug 27 13:11:29 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Sending gratuitous ARPs on em1 for 192.168.8.100

Aug 27 13:11:29 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Sending gratuitous ARPs on em1 for 192.168.8.200




11.KEEPALIVED配置LVS

去除/etc/sysconfig/ipvsadm

vi /etc/keepalived/keepalived.conf


! Configuration File for keepalived


global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id webrb1

}


vrrp_instance VI_rb1 {

    state MASTER

    interface em1

    virtual_router_id 51

    priority 100

    advert_int 10

    authentication {

        auth_type PASS

        auth_pass 11112222

    }

    virtual_ipaddress {

        192.168.8.100

        192.168.8.200/24

    }


virtual_server 192.168.8.200 80 {

delay_loop 2

lb_algo wrr

lb_kind DR

persistence_timeout 60

protocol TCP

    real_server 192.168.8.11 80 {

        weight 100

TCP_CHECK {

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

}

    }


    real_server 192.168.8.12 80 {

        weight 100

        TCP_CHECK {

        connect_timeout 10

        nb_get_retry 3

        delay_before_retry 3

        }

    }


    real_server 192.168.8.13 80 {

        weight 100

        TCP_CHECK {

        connect_timeout 10

        nb_get_retry 3

        delay_before_retry 3

        }

    }


}


! Configuration File for keepalived


global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id webrb2

}


vrrp_instance VI_rb1 {

    state BACKUP

    interface em1

    virtual_router_id 51

    priority 90

    advert_int 10

    authentication {

        auth_type PASS

        auth_pass 11112222

    }

    virtual_ipaddress {

     192.168.8.100

     192.168.8.200

    }

}


virtual_server 192.168.8.200 80 {

delay_loop 2

lb_algo wrr

lb_kind DR

persistence_timeout 60

protocol TCP

    real_server 192.168.8.11 80 {

        weight 100

TCP_CHECK {

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

}

    }


    real_server 192.168.8.12 80 {

        weight 100

        TCP_CHECK {

        connect_timeout 10

        nb_get_retry 3

        delay_before_retry 3

        }

    }


    real_server 192.168.8.13 80 {

        weight 100

        TCP_CHECK {

        connect_timeout 10

        nb_get_retry 3

        delay_before_retry 3

        }

    }


}


 

下面下载完整KEEPALIED+LVS操作步骤资料

 










本文转自 jxwpx 51CTO博客,原文链接:http://blog.51cto.com/jxwpx/1283249,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值