环境准备
三台centos虚拟机
三台虚拟机都需要执行
#安装软件包 [root@drlvs ~]# yum install bash* net-tools vim -y [root@drlvs ~]# su root #关闭防火墙 [root@drlvs ~]# systemctl stop firewalld.service #关闭防火墙开机自启 [root@drlvs ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. #临时关闭selinux [root@drlvs ~]# setenforce 0 #永久关闭selinux 把SELINUX的值改成disabled [root@drlvs ~]# vim /etc/selinux/config [root@drlvs ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
lvs虚拟机执行
#添加虚拟ip [root@drlvs ~]# ifconfig ens33:0 192.168.30.8/24 up [root@drlvs ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:92:0e:bb brd ff:ff:ff:ff:ff:ff inet 192.168.30.157/24 brd 192.168.30.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet 192.168.30.8/24 brd 192.168.30.255 scope global secondary ens33:0 valid_lft forever preferred_lft forever inet6 fe80::2c95:f747:b195:41f4/64 scope link noprefixroute valid_lft forever preferred_lft forever #加载lvs模块 [root@drlvs ~]# modprobe ip_vs #安装ipvsadm管理软件 [root@drlvs ~]# yum install ipvsadm -y #清楚ipvsadm策略 [root@drlvs ~]# ipvsadm -C [root@drlvs ~]# ipvsadm -A -t 192.168.30.8:80 -s rr [root@drlvs ~]# ipvsadm -a -t 192.168.30.8:80 -r 192.168.30.158:80 -g [root@drlvs ~]# ipvsadm -a -t 192.168.30.8:80 -r 192.168.30.159:80 -g #保存策略 [root@drlvs ~]# ipvsadm-save > /etc/sysconfig/ipvsadm #查看策略 [root@drlvs ~]# ipvsadm -ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.30.8:80 rr -> 192.168.30.158:80 Route 1 0 0 -> 192.168.30.159:80 Route 1 0 0