LVS的安装配置教程网上有不少,但是都是在Linux AS4或者更低版本下的。在AS 5上按照那些教程来安装发现有些问题,为了让大家以后少走弯路,以下奉上小弟的详细安装步骤(DR方式)。
假设以下环境
LB master 为 192.168.0.50
LB slave 为 192.168.0.51
Real server1 为192.168.40.20
Real server2 为192.168.40.21
外部虚拟IP为192.168.30.60,Real server群集的网关是192.168.40.254。
在安装LVS前,首先检查你的系统是否已经安装好以下包:
Kernel-devel
gcc
openssl
openssl-devel
popt
首先下载ipvadmin的安装文件,注意AS 5的对应安装文件应该是这个
http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
接着运行以下命令:
# ln -s /usr/src/kernels/2.6.18-8.el5-i686/ /usr/src/linux
# tar zxvf ipvsadm-1.24.tar.gz
# cd ipvsadm-1.24
# make && make install
接着,我们下载keepalived并安装,http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
运行以下命令:
# tar zvfx keepalived-1.1.15.tar.gz
# cd keepalived-1.1.15
#./configure
会有以下信息:
Keepalived configuration ------------------------ Keepalived version : 1.1.15 Compiler : gcc Compiler flags : -g -O2 Extra Lib : -lpopt -lssl -lcrypto Use IPVS Framework : Yes IPVS sync daemon support : Yes Use VRRP Framework : Yes Use LinkWatch : No Use Debug flags : No
如果Use IPVS Framework这项为“No”,请确认# ln -s /usr/src/kernels/2.6.18-8.el5-i686/ /usr/src/linux是否正确,可能你的安装跟我的路径有所不同。接着运行:
# make && make install
安装完后,我们就可以对keepalived进行配置了
# vi /usr/local/etc/rc.d/init.d/keepalived
把第一行的#!/bin/sh改为
#!/usr/local/sbin/keepalived
修改. /etc/sysconfig/keepalived为
. /usr/local/etc/sysconfig/keepalived
运行以下命令连接开机脚本
# ln -s /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/rc3.d/S99keepalived
# ln -s /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/rc5.d/S99keepalived
接下来就是修改keepalived的配置文件使其符合你的环境。
修改keepalived.conf
# vi /etc/keepalived/keepalived.conf
vrrp_sync_group VG1 { group { VI_1 VI_2 } } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1234 } virtual_ipaddress { 192.168.30.60 } } vrrp_instance VI_2 { state MASTER interface eth1 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.40.254 } } global_defs { router_id LB } virtual_server 192.168.30.60 80 { delay_loop 10 lb_algo wlc lb_kind DR persistence_timeout 2 protocol TCP real_server 192.168.40.20 80 { weight 1 TCP_CHECK { connect_port 80 connect_timeout 3 } } real_server 192.168.40.21 80 { weight 1 TCP_CHECK { connect_port 80 connect_timeout 3 } } }
最后把系统的sysctl.conf中的net.ipv4.ip_forward项设为1。
备份LB哪台机的配置只需要把 state MASTER 改为 state BACKUP。
另外我们还要对Real server群进行VIP配置
在每台Real server上创建一个文件
/etc/sysconfig/network-scripts/ifcfg-lo:0 并加入
DEVICE=lo:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.30.60
NETMASK=255.255.255.255
然后关闭ARP reply
# vi /etc/sysctl.conf加入
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo:0.arp_ignore=8
大功告成,reboot全部机器看看成果吧。