**1.**LVS 两个网关 :仅主机模式192.168.0.100 NAT模式172.25.254.100
(lvs中仅主机模式和NAT模式处于不同VLAN,网段不同)不同网段通信:内核
配置ip、主机名,挂载仓库好后:
vim /etc/NetworkManager/system-connections/eth0.nmconnection #NAT模式的eth0
md-end-block
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=172.25.254.100/24,172.25.254.2
method=manual
dns=114.114.114.114;
vim /etc/NetworkManager/system-connections/eth1.nmconnection #仅主机模式的eth1
md-end-block
[connection]
id=eth1
type=ethernet
interface-name=eth1
[ipv4]
address1=192.168.0.100/24
method=manual
nmcli connection reload
nmcli connection up eth0
nmcli connection up eth1
lvs中打开内核路由功能:
md-end-block
sysctl -a | grep ip_forward #会显示三行,把net.ipv4.ip_forward值改为1
net.ipv4.ip forward =0
net.ipv4.ip forward update priority= 1
net.ipv4.ip forward use pmtu = 0
vim /etc/sysctl.conf
net.ipv4.ip_forward=1 #添加这一行并将值改为1,保存退出
sysctl -p
配置HTTP服务:
yum install httpd -y #才能curl另外两台机子
systemctl enable --now httpd
在lvs的机子测试:
curl 192.168.0.10
curl 192.168.0.20
dnf install ipvsadm -y #lvs中安装lvs软件
安装后不能启服务,它会记录你当下编写的策略,但是重新开机后又没有了
ipvsadm -A -t 172.25.254.100:80 -s rr #rr轮询调度,后续for时调度该IP80端口下的两个 ip,轮询调度先调度10主机一遍,再调度20主机一遍,如此反复 t:tcp协议/u:udp协议 A:添加/ D:删除 s:调度算法 ipvsadm -C :添加的全部删除,清空
ipvsadm -Ln
ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m
ipvsadm -Ln
ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m
ipvsadm -Ln
ipvsadm-save
打开另外一台机子(第四台主机)进行测试:
for i in {1..10} #轮询10遍
do
curl 172.25.254.100
done
**2.**webserver1 仅主机模式192.168.0.10
vim /etc/NetworkManager/system-connections/eth0.nmconnection
md-end-block
<span style="background-color:#f8f8f8"><span style="color:#333333">[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=192.168.0.10/24,192.168.0.100
method=manual
dns=114.114.114.114;</span></span>
nmcli connection reload
nmcli connection up eth0
yum install httpd -y #才有/var/www/html路径,才能echo
systemctl enable --now httpd
echo webserver - 192.168.0.10 >> /var/www/html/index.html
**3.**webserver2 仅主机模式192.168.0.20
vim /etc/NetworkManager/system-connections/eth0.nmconnection
md-end-block
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=192.168.0.20/24,192.168.0.100
method=manual
dns=114.114.114.114;
nmcli connection reload
nmcli connection up eth0
route -n
yum install httpd -y #才有/var/www/html路径,才能echo
systemctl enable --now httpd
echo webserver - 192.168.0.10 >> /var/www/html/index.html