Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7174458
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类:

2012-03-28 20:01:39

原文地址:Centos 5.5 lvs+keepalived 安装配置 作者:

部署:
LVS-MASTER : 192.168.1.2
LVS-BACKUP : 192.168.1.3
LVS-VIP : 192.168.1.4
Realserver-1 : 192.168.1.5
Realserver-2 : 192.168.1.6

1. 系统采用最小化安装

2. 安装ipvsadm
# yum install ipvsadm

3. 安装keepalived前提
# yum install -y wget
# yum install -y gcc gcc-c++ make
# yum install -y openssl-devel kernel-devel

4. 安装keepalived
# wget http://www.keepalived.org/software/keepalived-1.2.1.tar.gz
# ln -s /usr/src/kernels/2.6.18-194.26.1.el5-i686 /usr/src/linux
# tar zxvf keepalived-1.2.1.tar.gz
# cd keepalived-1.2.1
# ./configure
(注意这个步骤要看到以下字样才是正常的)
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
# make && make install

5. 配置
# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
# mkdir /etc/keepalived
# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
# cp /usr/local/sbin/keepalived /usr/sbin/
# chkconfig –add keepalived
# chkconfig –level 2345 keepalived on

# vi /etc/keepalived/keepalived.conf

01! Configuration File for keepalived
02 
03global_defs {
04   notification_email {
05         fjcyz@qq.com
10   }
11   notification_email_from fjcyz@qq.com
16   smtp_server 127.0.0.1
17  # smtp_connect_timeout 30
18   router_id LVS_DEVEL
19}
20 
21vrrp_instance VI_1 {
22    state MASTER # 备份LB将MASTER改为BACKUP
23    interface eth0
24    virtual_router_id 51
25    priority 100 # 优先级,备份LB值改为比这个值小
26    advert_int 1
27    authentication {
28        auth_type PASS
29        auth_pass 1111
30    }
31    virtual_ipaddress {
32        192.168.1.4 # 多个VIP换行写
33    }
34}
35 
36virtual_server 192.168.1.4 80 {
37    delay_loop 6 #每隔6秒查询realserver状态
38    lb_algo wrr # LVS 算法
39    lb_kind DR # LVS模式 DR是直接路由
40    persistence_timeout 60 #同一IP连接60秒内分配到同一台realserver
41    protocol TCP #TCP协议检测realserver状态
42 
43    real_server 192.168.1.5 80 {
44        weight 3 #权重
45        TCP_CHECK {
46        connect_timeout 10 #10秒无响应超时
47        nb_get_retry 3
48        delay_before_retry 3
49        connect_port 80
50        }
51    }
52    real_server 192.168.1.6 80 {
53        weight 3
54        TCP_CHECK {
55        connect_timeout 10
56        nb_get_retry 3
57        delay_before_retry 3
58        connect_port 80
59        }
60     }
61}

6. Realserver主机上执行以下脚本

01#!/bin/bash
02 
03VIP=192.168.1.4
04 
05. /etc/rc.d/init.d/functions
06 
07case "$1" in
08start)
09    ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
10    /sbin/route add -host $VIP dev lo:0
11    echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
12    echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
13    echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
14    echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
15    sysctl -p >/dev/null 2>&1
16    echo "RealServer Start OK"
17    ;;
18stop)
19    ifconfig lo:0 down
20    route del $VIP >/dev/null 2>&1
21    echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
22    echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
23    echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
24    echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
25    echo "RealServer Stoped"
26    ;;
27*)
28    echo "Usage: $0 {start|stop}"
29    exit 1
30esac
31 
32exit 0

7. 检查测试
主备LB上执行
# service keepalived start
# ipvsadm -ln
检查ipvsadm是否服务正常

再把主LB执行
# service keepalived stop
查看备LB是否会自动接管VIP

另外就是做Realserver停止服务的测试,具体就不详说了.

阅读(1413) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~