linux下lvs搭建配置详解

环境:lvs:rhel 6 

   web:centos 5.7

原理:用户访问192.168.100.200(可以使用双网卡或者是绑定VIp),即可跳转到web1或web2,进行负载。



1、安装依赖

rpm安装popt-static-1.13-7.el6.x86_64.rpm包

rpm -ivh popt-static-1.13-7.el6.x86_64.rpm   --nodeps --force

yum -y install kernel-devel make gcc openssl-devel lftp libnl* popt*

2、参数调整

echo 1 >/proc/sys/net/ipv4/ip_forward   默认是0,关闭ip转发;这里需要开启,所以设置值为1

ln -s  /usr/src/kernels/2.6.32-220.el6.x86_64/  /usr/src/linux/

3、安装 ipvsadm

tar xvf  ipvsadm-1.26.tar.gz

cd  ipvsadm-1.26

make && make install

4、安装keepalived

tar xvf keepalived-1.2.2.tar.gz

cd keepalived

./configure 

make && make install

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
 cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
 mkdir /etc/keepalived
 cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
 cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
启动keepalived
service keepalived start|stop|restart

5、配置重定向
#echo "1" >/proc/sys/net/ipv4/ip_forward
#echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects
#echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects
#echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects
#echo "0" >/proc/sys/net/ipv4/conf/eth1/send_redirects
//清除ipvsadm表
#/sbin/ipvsadm -C
//使用ipvsadm安装LVS服务
#add http to VIP with rr scheduling
#/sbin/ipvsadm -A -t 192.168.100.200:80 -s rr
//增加第一台内部服务器RS1
#forward http to realserver 172.168.10.9 using LVS-NAT (-m), with weight=1
/sbin/ipvsadm -a -t 192.168.100.200:80 -r 192.168.254.201:80 -m -w 1


增加第二台内部服务器RS2
#forward http to realserver 172.168.10.10 using LVS-NAT (-m), with weight=1
/sbin/ ipvsadm -a -t 192.168.100.200:80 -r 192.168.254.202:80 -m -w 1


2.配置LVS中的内部服务器


在172.168.10.9(RS1)和172.168.10.9(RS2)上分别将其网关设置为172.168.10.8,并分别启动apache服务。在客户端使用浏览器多次访问:http://210.77.132.8,然后再210.77.132.8上运行ipvsadm命令,应该有类似下面的输出:


IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.100.200:http rr
  -> 192.168.254.201:http         Masq    1      0          0
  -> 192.168.254.202:http         Masq    1      0          0
      
从上面的结果可以看出,我们配置的LVS服务器已经成功运行。


你可能感兴趣的:(server)