Chinaunix首页 | 论坛 | 博客
  • 博客访问: 745719
  • 博文数量: 256
  • 博客积分: 3502
  • 博客等级: 中校
  • 技术积分: 3988
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-17 21:13
文章分类

全部博文(256)

文章存档

2014年(11)

2013年(134)

2012年(111)

我的朋友

分类: 系统运维

2012-05-04 20:43:24

一.实践环境
三台服务器,一台做lvs+keepalived,两台是lvs_web,因为只有三台机器环境测试所以lvs+keepalived没有做heartbeat来做备份
LVS+keepalived -----------------192.168.2.17
Lvs_web01------------------------192.168.2.165
Lvs_web02------------------------192.168.2.166
Web_vip---------------------------192.168.2.190
 二.安装步骤
1.  安装ipvsadm
ipvsadm下载地址
[root@lvs-dr1 ~]# tar zxvf ipvsadm-1.24.tar.gz  # 解压缩ipvsadm包 #
[root@lvs-dr1 ~]# ln -s /usr/src/kernels/2.6.18-53.el5-i686 /usr/src/linux # 做一个目录的链接 #
[root@lvs-dr1 ~]# ls -l /usr/src/  # 查看ln过的链接状态#
[root@lvs-dr1 ~]# cd ipvsadm-1.24
[root@lvs-dr1 ipvsadm-1.24]make && make install  # 编译并安装 #
root@lvs-dr1 ipvsadm-1.24]# find / -name ipvsadm  # 查看ipvsadm的位置 #
2.安装keepalived
keepalived下载地址
[root@lvs-dr1 ~]# tar zxvf keepalived-1.1.15.tar.gz  # 解压缩keepalived包 #
[root@lvs-dr1 ~]# cd keepalived-1.1.15
[root@lvs-dr1 keepalived-1.1.15]# ./configure
# 最好按照默认配置参数不要指定prefix,可能会出现问题 #
[root@lvs-dr1 keepalived-1.1.15]# make && make install  # 编译并安装 #
[root@lvs-dr1 keepalived-1.1.15]# find / -name keepalived  # 查看keepalived位置 #
3. 配置keepalived:
[root@lvs-dr1 keepalived]# pwd
/usr/local/etc/keepalived  # keepalived配置文件的路径 #
[root@lvs-dr1 keepalived]# ll keepalived.conf
-rw-r--r-- 1 root root 1627 Aug 16 09:13 keepalived.conf  # keepalived配置文件名 #
[root@lvs-dr1 keepalived]# more 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 LVS_DEVEL
}
# 2008-08-19 by hjw
# VIP1
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.190
#        192.168.1.220
    }
}
virtual_server 192.168.2.190 80 {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    persistence_timeout 50
    protocol TCP
    real_server 192.168.2.165 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.2.166 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
}
 
# shell end
 
4.启动keepalived:
 /usr/local/sbin/keepalived -D -f /usr/local/etc/keepalived/keepalived.conf
在/etc/rc.local中添加,脚本开机启动:
Vi /etc/rc.d/rc.local
添加:
/usr/local/sbin/keepalived -D -f /usr/local/etc/keepalived/keepalived.conf
 
3.配置LVS_DR的模式
LVS端的配置
(1)写脚本ipvsadm.sh如下:
#!/bin/bash
ipvsadm -C
#VS/DR
ipvsadm -A -t 192.168.2.190:80 -s wlc
ipvsadm -a -t  192.168.2.190:80 -r 192.168.2.165:80 -g
ipvsadm -a -t  192.168.2.190:80 -r 192.168.2.166:80 -g
ipvsadm –Ln
(2)在eth0上绑定ifcfg-eth0:0的IP为192.168.2.190
Ifcfg-eth0:0的配置文件为:
DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.2.190
NETMASK=255.255.255.0
#GATEWAY=192.168.2.254
#HWADDR=00:E0:4C:E9:33:7B
两台LVS_Web端的配置:
1)         Vi  /etc/sysctl.conf
#for ipvs
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.rp_filter = 1
#end of ipvs
2)         配置ifcfg-lo:0的IP为192.168.2.190
Vi  /etc/ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.2.190
NETMASK=255.255.255.255
ONBOOT=yes
3)         配置两台LVS_web的apache服务,至此结束
三.  测试服务
1.   启动两台lvs_web的apache服务
2.   启动lvs_keepalived服务器的keepalived和lvs的服务
3.   访问并不断刷新页面开是否平均落到两台服务器上
4.   停到一台lvs_web的apache服务,在访问
阅读(763) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~