lvs的nat模式配置

发布于:2024-08-08 ⋅ 阅读:(112) ⋅ 点赞:(0)

lvs的nat模式

准备工作

lvs主机需要两个网络适配器,其中一个为NAT模式,另外一个为仅主机模式,还需要两个server主机,一个为server1还有一个为server2,都为仅主机模式

配置过程

配置ip

lvs主机

[root@lvs ~]# cat /etc/NetworkManager/system-connections/eth1.connection 
[connection]
id=eth1
type=ethernet
interface-name=eth1

[ipv4]
address1=192.168.0.100/24
method=manual

 server1主机

[root@webserver1 ~]# cat /etc/NetworkManager/system-connections/eth0.connection 
[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
address1=192.168.0.10/24,192.168.0.100
method=manual

server2主机配置

[root@webserver2 ~]# cat /etc/NetworkManager/system-connections/eth0.connection 
[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
address1=192.168.0.20/24,192.168.0.100
method=manual

在lvs主机中配置

lvs中打开内核路由功能,ip_forward = 1通常表示启用了 IP 转发功能,使网络适配器分别为nat和仅主机之间连通

vim /etc/sysctl.conf			#在最后一行添加
net.ipv4.ip_forwaed = 1				#启用了 IP 转发功能

sysctl -p 			#使配置生效

下载ipvsadm

yum install ipvsadm -y

配置规则

ipvsadm -A -t 172.25.254.100:80 -s rr
ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10 -m
ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10 -m

ipvsadm -Ln
watch -n 1 ipvsadm -Ln --rate	#也可以使用监控命令来看

在server主机配置

yum install httpd -y        #两个都要下载httpd

echo webserver1-192.168.0.10 > /var/www/html/index.html        #server1中配置
ystemctl restart httpd

echo webserver1-192.168.0.10 > /var/www/html/index.html         #server2中配置
systemctl restart httpd

 

测试结果


网站公告

今日签到

点亮在社区的每一天
去签到