Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

绿色网站无广告
会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux系统 > » 正文

LVS+Keepalived实现高可用和负载均衡的解决方案

来源: 未知 分享至:

                 实验拓扑图:

   

实验ip规划

VIP192.168.1.200

Real server1:192.168.1.195

Real server2:192.168.1.193

心跳线:10.1.1.110.1.1.2

DR1192.168.1.192

DR2192.168.1.1.190

 

实现过程

第一:在主节点上的配置

首先配置LVS

[root@localhost ~]# cd tools/

[root@localhost tools]# ls ipvsadm-1.24.tar.gz

ipvsadm-1.24.tar.gz

[root@localhost tools]# tar zxvf ipvsadm-1.24.tar.gz

[root@localhost tools]# cd ipvsadm-1.24

[root@localhost ipvsadm-1.24]# ln -s /usr/src/kernels/2.6.18-164.el5 /usr/src/linux/

[root@localhost ipvsadm-1.24]# make all && make install

然后安装配置keepalived

[root@localhost tools]# ls keepalived-1.2.2.tar.gz

keepalived-1.2.2.tar.gz

[root@localhost tools]# tar zxvf keepalived-1.2.2.tar.gz

[root@localhost tools]# cd keepalived-1.2.2

[root@localhost keepalived-1.2.2]# vi keepalived/libipvs-2.6/ip_vs.h

找到下面一行:

#include <linux/types.h>        /* For __beXX types in userland */

把他放到下面一行的下面:

#include <sys/types.h>

[root@localhost keepalived-1.2.2]# make && make install

[root@localhost keepalived-1.2.2]# ln -s /usr/local/sbin/keepalived /sbin/

[root@localhost ~]# cd /etc/keepalived/

[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bak   //备份

[root@localhost keepalived]# vi keepalived.conf    //修改设置档如下

! Configuration File for keepalived

 

global_defs {

   notification_email {

     wethnicity@126.com

     38205036@qq.com

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.1.192

   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_typePASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.1.200

    }

}

 

virtual_server 192.168.1.200 80 {

    delay_loop 6

    lb_algo rr

    lb_kind DR

    nat_mask 255.255.255.0

    persistence_timeout 50

    protocol TCP

 

    real_server 192.168.1.193 80 {

        weight 1

        TCP_CHECK {

            connect_timeout 10

            nb_get_retry 3

            delay_before_retry 3

        }

    }

    real_server 192.168.1.195 80 {

        weight 1

        TCP_CHECK {

            connect_timeout 10

            nb_get_retry 3

            delay_before_retry 3

        }

    }

}

在备用节点上的设置和主节点基本完全相同(因为是提供相同的服务),仅仅需要修改的就是keepalived.con

vrrp_instance VI_1 {

    state BACKUP    //修改处

    interface eth0

    virtual_router_id 51

    priority 80        //修改处

    advert_int 1

    authentication {

        auth_typePASS

        auth_pass 1111

    }

第二:在real server上的设置(两个real server基本相同,故这里只设置一个)

[root@localhost ~]# cd /var/www/html/

[root@localhost html]# vi index.html

It\'s 192.168.1.195!!

[root@localhost html]# /etc/init.d/httpd start

[root@localhost ~]# vi /etc/init.d/lvsrs

#!/bin/bash

VIP=192.168.1.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

sysctl -p

#end

[root@localhost ~]# chmod a+x /etc/init.d/lvsrs

[root@localhost ~]# /etc/init.d/lvsrs start

 

第三:测试的部分(开启real serverapache服务)

[root@localhost ~]# ipvsadm

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  192.168.1.200:http rr persistent 50

  -> 192.168.1.193:http           Route   1      0          0         


Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史