当前位置: 首页 > article >正文

LVS之net模式实验

总结:

lvs

#配置环境,两个网卡
[root@lvs ~]# cd /etc/NetworkManager/system-connections/
[root@lvs system-connections]# ls
ens160.nmconnection  eth0.nmconnection  eth1.nmconnection
[root@lvs system-connections]# vim eth0.nmconnection 
[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;


[root@lvs system-connections]# vim eth1.nmconnection 
[connection]
id=eth1
type=ethernet
interface-name=eth1
[ipv4]
address1=192.168.0.100/24
method=manual
dns=114.114.114.114;


[root@lvs ~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 0
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0

#打开内核路由功能
[root@lvs ~]# vim /etc/sysctl.conf 
#添加
net.ipv4.ip_forward = 1

#查看
[root@lvs ~]# sysctl -p
net.ipv4.ip_forward = 1

#安装lvs
[root@lvs ~]# dnf install ipvsadm -y

#查看策略
[root@lvs ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags

#-A增加 -t tcp -s指定调度算法 rr静态算法(你一个我一个)
[root@lvs ~]# ipvsadm -A -t 172.25.254.100:80 -s rr

#查看策略
[root@lvs ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  172.25.254.100:80 rr


[root@lvs ~]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m
[root@lvs ~]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m
[root@lvs ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  172.25.254.100:80 rr
-> 192.168.0.10:80              Masq    1      0          3         
-> 192.168.0.20:80              Masq    1      0          2 

#保存设置
[root@lvs ~]# ipvsadm-save > /etc/sysconfig/ipvsadm

web1

#配置IP
[root@webserver1 ~]# cd /etc/NetworkManager/system-connections/
[root@webserver1 system-connections]# vim eth0.nmconnectio
[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;

#下载并启动httpd
[root@webserver1 system-connections]# cd
[root@webserver1 ~]# yum install httpd -y
[root@webserver1 ~]# echo webserver1 - 192.168.0.10 > /var/www/html/index.html
[root@webserver1 ~]# systemctl enable httpd

web2

#配置IP
[root@webserver2 ~]# cd /etc/NetworkManager/system-connections/
[root@webserver2 system-connections]# vim eth0.nmconnectio
[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;

#下载并启动httpd
[root@webserver2 system-connections]# cd
[root@webserver2 ~]# yum install httpd -y
[root@webserver2 ~]# echo webserver1 - 192.168.0.20 > /var/www/html/index.html
[root@webserver2 ~]# systemctl enable httpd

测试

#注意测试的主机不能安装httpd
[root@lvs ~]# curl 172.25.254.100
webserver1 - 192.168.0.10
[root@lvs ~]# curl 172.25.254.100
webserver2 - 192.168.0.20
[root@lvs ~]# curl 172.25.254.100
webserver1 - 192.168.0.10

http://www.kler.cn/news/283752.html

相关文章:

  • MySQL空间管理:查询、优化与碎片清理
  • C#基础(1)复杂数据类型概述
  • 19050 牛牛打气球
  • Training language models to follow instructionswith human feedback
  • 【iOS】iOS中简单的网络请求
  • Openai api via azure error: NotFoundError: 404 Resource not found
  • 优化系统性能:深入探讨Web层缓存与Redis应用的挑战与对策
  • 虹科技术|全新Linux环境PCAN驱动程序发布!CAN/CAN FD通信体验全面升级!
  • C# 什么是属性
  • Linux操作系统在虚拟机VM上的安装【CentOS版本】
  • 深入解析 Maven 子父模块的依赖管理
  • Java 面试题:HTTP版本演变--xunznux
  • Web-gpt
  • UR5e Gazebo仿真
  • Go 服务调试精解
  • 备战秋招60天算法挑战,Day28
  • 个人旅游网(1)——数据库表详解
  • 爬虫入门学习
  • Java Web —— 第十天(AOP切面编程)
  • Dxf文件中多段线弧线的计算
  • 三星与海力士发力决战HBM4
  • 【知识】缓存类型和策略
  • 数据合规性分析:守护信息安全的关键防线
  • 原生开发柱状图
  • 钉钉好用吗?类似钉钉的内部知识库有哪些?
  • 【微信小程序】微信小程序如何使用 MobX 进行状态管理?
  • 【已解决】win11笔记本电脑突然无法检测到其他显示器 / 无法使用扩展屏(2024.8.29 / 驱动更新问题)
  • Linux使用ifconfig配置临时ip地址
  • ET6框架(八)事件系统
  • UE5 摄像机图像采集到材质 映射到 UI 和 物体表面