[root@lvs-lvs ~]# ipvsadm -Ln查看ipvsadm规则(-n表示以数字方式显示,不解析)
lvs是四层的,不能做到hash(http://vip/test.html),基于传输层,而haproxy和nginx支持7层的,lvs只能四层
--exact显示精确值:[root@lvs-lvs ~]# ipvsadm -Ln --exact
-c显示ipvs连接输出:[root@lvs-lvs ~]# ipvsadm -Ln -c
--stats统计信息:[root@lvs-lvs ~]# ipvsadm -Ln --stats
--rate输出速率信息:[root@lvs-lvs ~]# ipvsadm -Ln --rate
ipvs规则在内存中也有个文件:[root@lvs-lvs ~]# cat /proc/net/ip_vs
连接情况:[root@lvs-lvs ~]# cat /proc/net/ip_vs_conn
清除所有ipvs规则:[root@lvs-lvs ~]# ipvsadm -C
保存规则:[root@lvs-lvs ~]# ipvsadm-save -n > /etc/sysconfig/ipvsadm(必须要-n选项)
LVS-nat的特点:
如上图所示:需要5台机器
第一台做client:IP:10.0.3.64
第二台做router(两块网卡):IP1:10.0.3.32 IP2:192.168.137.133
第三台是lvs服务器:IP:192.168.137.132
第四台是lvs-web1:IP:192.168.137.129
第五台是lvs-web2:IP:192.168.137.129
需要一个VIP:192.168.137.100
还有:10.0.0网段是桥接网段,192.168.137网段是仅主机网段
所有机器关闭防火墙,selinux,清空iptables
[root@lvs-web1 ~]# yum install httpd -y
[root@lvs-web1 ~]# systemctl start httpd
[root@lvs-web1 ~]# vim /var/www/html/index.html
[root@lvs-web1 ~]# cat /var/www/html/index.html
lvs-web1
[root@lvs-web2 ~]# yum install httpd -y
[root@lvs-web2 ~]# systemctl start httpd
[root@lvs-web2 ~]# vim /var/www/html/index.html
[root@lvs-web2 ~]# cat /var/www/html/index.html
lvs-web2
[root@lvs-lvs ~]# ip a a 192.168.137.100/32 dev lo
[root@lvs-lvs ~]# ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet 192.168.137.100/32 scope global lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:c0:5b:59 brd ff:ff:ff:ff:ff:ff
inet 192.168.137.132/24 brd 192.168.137.255 scope global noprefixroute dynamic ens33
valid_lft 1518sec preferred_lft 1518sec
inet6 fe80::20c:29ff:fec0:5b59/64 scope link
valid_lft forever preferred_lft forever
[root@lvs-lvs ~]# ipvsadm -A -t 192.168.137.100:80 -s rr
[root@lvs-lvs ~]# ipvsadm -a -t 192.168.137.100:80 -r 192.168.137.129 -g
[root@lvs-lvs ~]# ipvsadm -a -t 192.168.137.100:80 -r 192.168.137.130 -g
[root@lvs-lvs ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.137.100:80 rr
-> 192.168.137.129:80 Route 1 0 0
-> 192.168.137.130:80 Route 1 0 0
VIP和DIP搞混了
把DIP放到ipvs规则上了
等等