一、配置VIP
# cd /etc/sysconfig/network-scripts/
# mv ifcfg-enp2s0 ifcfg-eth0
这里改名请注意:
vim /etc/default/grub(修改前先备份)
GRUB_CMDLINE_LINUX这条语句里加下面两个参数
net.ifnames=0 biosdevname=0
为GRUB_CMDLINE_LINUX变量增加2个参数(net.ifnames=0 biosdevname=0),修改完成如下:
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet"
注意前后以空格相隔。
重建grub配置文件
执行命令:grub2-mkconfig -o /boot/grub2/grub.cfg
修改/etc/sysconfig/network-scripts/ifcfg-ens33
将文件名修改为ifcfg-eth0
打开文件,将NAME和DEVICE参数都修改为eth0.。
重启系统
ifconfig,发现已经修改完成
# cp ifcfg-eth0 ifcfg-eth0:0
# vim ifcfg-eth0:0 将虚拟IP设为200
IPADDR=10.66.1.200
# service network restart
[root@localhost network-scripts]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.66.1.128 netmask 255.255.255.0 broadcast 10.66.1.255
inet6 fe80::17e3:3e0:f300:7d56 prefixlen 64 scopeid 0x20<link>
ether 44:8a:5b:50:13:1f txqueuelen 1000 (Ethernet)
RX packets 586319 bytes 35633730 (33.9 MiB)
RX errors 0 dropped 962 overruns 0 frame 0
TX packets 4607 bytes 377345 (368.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 6
eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.66.1.200 netmask 255.255.255.0 broadcast 10.66.1.255
ether 44:8a:5b:50:13:1f txqueuelen 1000 (Ethernet)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 84 bytes 7248 (7.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 84 bytes 7248 (7.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
二、安装ipvsadm
yum -y install ipvsadm
# ipvsadm -A -t 10.66.1.128:80 -s rr
# ipvsadm -a -t 10.66.1.128:80 -r 10.66.1.123 -g
# ipvsadm -a -t 10.66.1.128:80 -r 10.66.1.223 -g
[root@localhost ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.66.1.128:80 rr
-> 10.66.1.123:80 Route 1 0 0
-> 10.66.1.223:80 Route 1 0 0
[root@localhost ~]#
# cp ifcfg-lo ifcfg-lo:1
# vim ifcfg-lo:1
# echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
# echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
待明天继续