实验:7-1做调度器;7-2和7-3做真实服务器;7-4做客户端;
1.先关闭所有的防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]#
2.怎么看selinux状态
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# setenforce 1
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
3.配置7-1调度服务器
1.配置虚拟ip地址
[root@localhost ~]# ifconfig ens33:0 192.168.91.188/32
[root@localhost ~]# ip a
2.调整/proc响应参数
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
[root@localhost ~]# sysctl -p
3.加载模块
ip_vs是内核模块中的功能
[root@localhost ~]# modprobe ip_vs
[root@localhost ~]#
[root@localhost ~]# cat /proc/net/ip_vs
4.下载并配置ipvsadm
[root@localhost ~]# yum install ipvsadm.x86_64 -y
[root@localhost ~]# ipvsadm-save > /etc/sysconfig/ipvsadm
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# systemctl start ipvsadm.service
[root@localhost ~]# ipvsadm -A -t 192.168.91.188:80 -s rr
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ipvsadm -a -t 192.168.91.188:80 -r 192.168.91.102 -g
[root@localhost ~]# ipvsadm -a -t 192.168.91.188:80 -r 192.168.91.103 -g
[root@localhost ~]#
[root@localhost ~]# ipvsadm -ln
4.配置7-2Web服务器
1.安装并开启httpd服务
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl start httpd
2.添加临时回环地址
[root@localhost ~]# ifconfig lo:0 192.168.91.188/32
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ip a
3.配置在index.html
[root@localhost ~]# cd /var/www/html
[root@localhost html]#
[root@localhost html]# ls
[root@localhost html]# echo 7-2 > index.html
[root@localhost html]#
[root@localhost html]# cat index.html
7-2
4.配置内核参数
[root@localhost html]# sysctl -a | grep arp
[root@localhost html]# vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@localhost html]# sysctl -p
5.配置7-3Web服务器
1.安装并开启httpd服务
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl start httpd
2.添加临时回环地址
[root@localhost ~]# ifconfig lo:0 192.168.91.188/32
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ip a
3.配置index.html
[root@localhost ~]# cd /var/www/html
[root@localhost html]#
[root@localhost html]# echo 7-3 > index.html
[root@localhost html]#
[root@localhost html]# cat index.html
7-3
4.配置内核参数
vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@localhost html]# sysctl -p
6.去7-4客户端curl查看结果
1.先ping一下看看
[root@localhost ~]# ping 192.168.91.188
2.curl看结果
[root@localhost ~]# curl 192.168.91.188
7-3
[root@localhost ~]# curl 192.168.91.188
7-2
[root@localhost ~]# curl 192.168.91.188
7-3