IPVS

ipvs全称为IP虚拟服务器(IP Virtual Server,简写为IPVS)。是运行在LVS下的提供负载平衡功能的一种技术。ipvs是在linux内核netfilter模块之上实现的四层负载均衡模块。

开启ipvs模块

添加sysctl配置

/etc/sysctl.conf
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1

使配置生效

sysctl -p

加载内核模块

modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
modprobe nf_conntrack_ipv4

安装ipvsadm

yum install -y ipvsadm

运行参数

使用

例子:查看已有规则

例子:添加一个虚拟服务192.168.1.100:80,负载到172.17.10.1:8080和172.10.10.2:8080上,以round robin为负载策略和snat转发方式。

例子:将虚拟服务192.168.1.100:80的负载策略修改为wrr

例子:删除虚拟服务192.168.1.100:80

例子:清理所有规则

最后更新于