一:服务器LVS配置
首先准备三台虚拟机,模拟环境:LVSServer,Server1,Server2
1: LVSServer 配置两张网卡,一张与外部通信的host-only(ip:172.60.1.2,netmask 255.255.255.0),另一张是内部通信的(ip:192.168.100.1,netmask 255.255.255.0);外设的host-only ip:172.60.1.3 ,netmask 255.255.255.0,LVSServer要预先安装ipvsadm(yum install -y ipvsadm*)2:
Server1,Server2要安装LAMP(你懂得)三台虚拟机都关闭selinux和iptables(vi /etc/selinux/config修改:SELINUX=disabled,关掉iptables:service iptables stop)ip配置为:ifconfig eth0 192.168.100.2(和3) netmask 255.255.255.0route add default gw 192.168.100.1查看 route,如果网关指向 192.168.100.1就对了3:
LVSServer echo 1 >/proc/sys/net/ipv4/ip_forward;(开启Linux的路由功能)写shell脚本:ipvs.sh:#!/bin/bash#!ipvsadm configipvsadm -C
ipvsadm -At 172.60.1.2:80 -s rripvsadm -at 172.60.1.2:80 -r 192.168.100.2:80 -m(nat 模式)ipvsadm -at 172.60.1.2:80 -r 192.168.100.3:80 -m(nat 模式)保存上面的shell
修改shell权限:chmod a+x ipvs.sh(chmod 0777 ipvs.sh)4:
在 Server1,Server2的 /var/www/html 下写测试文件