10.0.0.41 lvs
10.0.0.42
10.0.0.43
1.配置VIP:192.168.1.110
[root@c7-41 network-scripts]# cat ifcfg-ens33:0
IPADDR=10.0.0.110
NETMASK=255.255.255.0
GATEWAY=10.0.0.254
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
[root@c7-41 network-scripts]# ifup ens33:0
[root@c7-41 network-scripts]# ip addr show
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:49:48:c7 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.41/24 brd 10.0.0.255 scope global ens33
valid_lft forever preferred_lft forever
inet `10.0.0.110`/24 brd 10.0.0.255 scope global secondary ens33:0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe49:48c7/64 scope link
valid_lft forever preferred_lft forever
2.安装LVS软件
[root@c7-41 ~]# yum -y install ipvsadm
3.41上运行
[root@c7-41 ~]# cat lvs.sh
#!/bin/sh
VIP=10.0.0.110
RIP1=10.0.0.42
RIP2=10.0.0.43
#. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS of DirectorServer"
#set the Virtual IP Address
ifconfig ens33:0 $VIP/24
#/sbin/route add -host $VIP dev ens160:0
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:80 -s wrr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
#Run LVS
/sbin/ipvsadm
#end
;;
stop)
echo "close LVS Directorserver"
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
4.42|43上运行
[root@c7-42 ~]# cat re.sh
#!/bin/sh
VIP=10.0.0.110
#. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "Start LVS of RealServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
echo "Stop LVS of RealServer"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage:$0{start|stop}"
exit 1
esac
5.安装apache服务
[root@c7-42 ~]# yum -y install httpd
6.创建测试页面
[root@c7-42 ~]# cat /var/www/html/index.html
web1
[root@c7-42 ~]# cat /var/www/html/index.html
web2
7.开启httpd服务
[root@c7-42 ~]# systemctl start httpd