本文阐述 lvs+keepalived 完全安装以及配置教程
安装linux,可以选择完全安装(自带ip_vs,就不需要安装ipvsadm了)。
配置外网网卡地址 172.16.11.94
将LVS外网IP设成自己的内部IP
ifconfig lo:0 172.16.11.94 netmask 255.255.255.255 broadcast 172.16.11.94 up(不一定需要)
修改内网网卡地址为:
IPV6INIT=no
ONBOOT=yes
USERCTL=no
PEERDNS=yes
TYPE=Ethernet
DEVICE=eth1
BOOTPROTO=static
IPADDR=10.0.0.1
NETMASK=255.255.255.0
GATEWAY=10.0.0.1
创建 /usr/local/bin/ipvsadm.sh
文件内容如下:
#open IP Forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# To make the load balancer forward the masquerading packets
iptables -t nat -A POSTROUTING -s 172.16.11.94/24 -d 0.0.0.0/0 -o eth0 -j MASQUERADE
ipvsadm -C
# Choose the Weighted Round Robing
ipvsadm -A -t 172.16.11.94:80 -s wrr
# Set Real Server
ipvsadm -a -t 172.16.11.94:80 -r 10.0.0.2:80 -m -w 2
ipvsadm -a -t 172.16.11.94:80 -r 172.16.10.172:80 -m -w 3
ipvsadm
运行ipvsadm ,/usr/local/bin/ipvsadm.sh
ipvsadm 回车
应该查看到如下显示
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddressort Scheduler Flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
TCP LVS:80 wlc
-> WEB-2:http Masq 1 0 0
TCP LVS:80 wlc
-> WEB-1:http Masq 1 0 0
安装keepalived
安装KEEPALIVED
cd /tmp/keepalived-1.1.13.tar.gz
在做./configure之前:
先 ln -s /usr/src/kernels/2.6.11-1.1369_FC4-i686/ /usr/src/linux
(这台机器需安装SRC, LVS)
启动Keepalived (/etc/rc.local)
/usr/local/sbin/keepalived -C -D-f /usr/local/etc/keepalived/keepalived.conf
输出在 /var/log/message
keepalived.conf? (‘{‘前,一定要有个空格.)
以下是keepalived.conf的配置:
! Configuration File for keepalivedglobal_defs {
##报警功能
notification_email {
}
notification_email_from [email protected]
smtp_server 172.16.0.3
smtp_connect_timeout 5
lvs_id LVS_MAIN
}
##lvs功能
virtual_server 172.16.11.94 80 {
delay_loop 6 #(每隔6秒查询realserver状态)
lb_algo wlc #(weighted least connection)
persistence_timeout 1800 #(同一IP的连接30分钟内被分配到同一台realserver)
lb_kind NAT #(Direct Route)
protocol TCP #(用TCP协议检查realserver状态)
real_server 10.0.0.2 80 {
weight 1 #(权重)
HTTP_GET {
url {
path /index.html
digest 72d27a59262916d9841d9f6a37e2d3d9
}
connect_timeout 8
nb_get_retry 6
delay_before_retry 3
}
}
real_server 10.0.0.3 80 {
weight 1
HTTP_GET {
url {
path /test.htm
digest c5261ea29cf58bdebe5c3bf3d09051ac
}
connect_timeout 8
nb_get_retry 6
delay_before_retry 3
}
}
}
运行 /usr/local/sbin/keepalived -C -D-f /usr/local/etc/keepalived/keepalived.conf
来启动keepalived,通过 查看系统日志返回的参数,获取real server 的
MD5 编码,替换上面配置文件中的MD5 编码
通过上列配置,应该是没有问题的。
keepalived 正常运行后,原来对ipvsadm的配置已经失效了。
原文地址: http://www.linuxtone.org/thread-651-1-1.html
sky
看的不太明白