IPVS/LVS集群测试NAT/DR模式

准备WEB环境

安装web软件

yum install httpd
systemctl start httpd
[root@server1 ~]# echo "Welcom to server1.exapmle.com! " > /var/www/html/index.html
[root@server2 ~]# echo "Welcom to server2.exapmle.com! " > /var/www/html/index.html

测试web访问

默认配置时,端口监听在IPV6上

[root@server1 etc]# grep Listen /etc/httpd/conf/httpd.conf
Listen 80
[root@server2 ~]# ss -tuan4 |grep 80
[root@server2 ~]# ss -tuan |grep 80
tcp    LISTEN     0      128      :::80                   :::* 
修改为IPV4
Listen 0.0.0.0:80
[root@server1 etc]# ss -tuan4|grep 80
tcp    LISTEN     0      128       *:80                    *:*                  
[root@server1 etc]# ss -tuan6|grep 80
[root@server1 etc]# 

两种模式下都可以在本机正常访问 links http://127.0.0.1/
但在其他机器无法访问 http://s1/

修改防火墙,增加http服务

[root@server1 etc]# firewall-cmd --permanent --add-service=http
success
[root@server1 etc]# firewall-cmd --reload
success
[root@server1 etc]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: ssh dhcpv6-client http
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

通过firefox访问http://192.168.122.213/及http://s1/正常

[root@server2 ~]# ss -tuan4|grep 80
[root@server2 ~]# ss -tuan6|grep 80
tcp    LISTEN     0      128      :::80                   :::*                  
[root@server2 ~]# grep Listen /etc/httpd/conf/httpd.conf |tail -1
Listen 80

按上述方法放开防火墙后,在其他机器可以正常访问。
** 因此,Listen 80这样的配置是可以支持IPV4的。 **

LVS软件

把LVS(安装ipvsadm)所在机器成为负载均衡器Director。

安装LVS软件及命令说明

[root@server1 ~]# yum install ipvsadm
[root@server1 ~]# rpm -q ipvsadm
ipvsadm-1.27-7.el7.x86_64

ipvsadm --help可以查看说明
[root@server1 etc]# ipvsadm --help
ipvsadm v1.27 2008/5/15 (compiled with popt and IPVS v1.2.1)
Usage:
  ipvsadm -A|E -t|u|f service-address [-s scheduler] [-p [timeout]] [-M netmask] [--pe persistence_engine] [-b sched-flags]
  ipvsadm -a|e -t|u|f service-address -r server-address [options]
Commands:
Either long or short options are allowed.
  --add-service     -A        add virtual service with options
  --add-server      -a        add real server with options
  --clear           -C        clear the whole table
  --restore         -R        restore rules from stdin
  --save            -S        save rules to stdout
Options:
  --tcp-service  -t service-address   service-address is host[:port]
  --real-server  -r server-address    server-address is host (and port)
  --weight       -w weight            capacity of real server
调度算法
  --scheduler    -s scheduler         one of rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq,
                                      the default scheduler is wlc.
三种模式
  --gatewaying   -g                   gatewaying (direct routing) (default)
  --ipip         -i                   ipip encapsulation (tunneling)
  --masquerading -m                   masquerading (NAT)

NAT模式配置及验证

LVS作为Director,修改目的地址的IP地址

组网说明:

物理机:xycto
virbr0网卡地址为192.168.122.1/24
wlp7s0网卡地址为192.168.1.126/24
新增一个浮动IP地址作为web服务对外 192.168.1.10/24
虚拟机2台作为真实服务器RS,网卡eth0地址如下
192.168.122.213 server1.example.com s1
192.168.122.143 server2.example.com s2

在物理机上配置LVS

查看当前配置
ipvsadm -Ln
清空所有配置
ipvsadm -C
增加浮动IP地址(规划为192.168.1.10)
ipvsadm -A -t 192.168.1.10:80
增加2台真实服务器,采用nat模式,未指定权重相同
ipvsadm -a -t 192.168.1.10:80 -r 192.168.122.213:80 -m
ipvsadm -a -t 192.168.1.10:80 -r 192.168.122.143:80 -m
检查配置

[root@xycto ~]# 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.1.126:80 wlc
  -> 192.168.122.143:80           Masq    100    0          0         
  -> 192.168.122.213:80           Masq    100    0          0 

此时用ip addr并不能看到浮动地址,手工添加浮动地址到对外的wlp7s0网卡
[root@xycto ~]# ip address add 192.168.1.10/24 dev wlp7s0
此时在2个RS上可以ping通192.168.1.10
停止防火墙
[root@xycto ~]# systemctl stop firewalld
验证负载均衡正常

[xy@xycto ~]$ curl http://192.168.1.10
Welcom to server2.exapmle.com! 
[xy@xycto ~]$ curl http://192.168.1.10
Welcom to server1.exapmle.com! 
[xy@xycto ~]$ curl http://192.168.1.10
Welcom to server2.exapmle.com! 
[xy@xycto ~]$ curl http://192.168.1.10
Welcom to server1.exapmle.com! 
[xy@xycto ~]$ curl http://192.168.1.10
Welcom to server2.exapmle.com! 
[xy@xycto ~]$

如果用ie或者firefox测试时,由于缓存原因,可能访问内容不会更新,每次测试需要清空缓存。

防火墙问题,xycto上无法访问vip地址

[root@xycto ~]# curl http://192.168.1.10
抓包[root@xycto ~]# tcpdump -i any -s0 port 80 -vv -w /tmp/a.cap
发现发送SYN后,收到[SYN, ACK]未能发送ACK

1	0	192.168.1.126	192.168.122.213	TCP	76	40356 > http [SYN] Seq=0 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=24387358 TSecr=0 WS=128
3	0	192.168.122.143	192.168.1.126	TCP	76	http > 50826 [SYN, ACK] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=4028679 TSecr=23551161 WS=128

尝试1:在public区域增加接口virbr0
[root@xycto ~]# firewall-config
添加后reload生效。默认是Runtime。

[root@xycto ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: virbr0 wlp7s0
  sources: 
  services: dhcpv6-client ftp http ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:

重启firewalld后,配置恢复,策略接口中不包括virbr0

[root@xycto ~]# systemctl start firewalld
[root@xycto ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: wlp7s0
此时是开放了端口转发的
[root@xycto ~]# sysctl -a|grep ip_forward
net.ipv4.ip_forward = 1
防火墙基础欠缺,暂未解决。

DR直接路由模式配置及验证

LVS作为Director,修改目的地址的MAC

组网说明:

物理机:xycto
virbr0网卡地址为192.168.122.1/24
虚拟机2台作为真实服务器RS,网卡eth0地址如下
192.168.122.213 server1.example.com s1
192.168.122.143 server2.example.com s2

在物理机上配置LVS

查看当前配置
ipvsadm -Ln
清空所有配置
ipvsadm -C
增加浮动IP地址(规划为192.168.122.20)
ipvsadm -A -t 192.168.122.20:80
增加2台真实服务器,采用nat模式,未指定权重相同
ipvsadm -a -t 192.168.122.20:80 -r 192.168.122.213:80 -g
ipvsadm -a -t 192.168.122.20:80 -r 192.168.122.143:80 -g
检查配置

[root@xycto ~]# 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.122.20:80 wlc
  -> 192.168.122.143:80           Route   1      0          0         
  -> 192.168.122.213:80           Route   1      0          0

此时用ip addr并不能看到浮动地址,手工添加浮动地址到同RS网段的virbr0网卡
[root@xycto ~]# ip address add 192.168.122.20/32 dev virbr0

为了避免出现IP地址冲突,需要关闭真实服务器的ARP广播,指定网卡为eth0
sysctl net.ipv4.conf.eth0.arp_ignore=1
sysctl net.ipv4.conf.eth0.arp_announce=2

在2台真实服务器的lo网卡配置相同的地址
[root@server1 ~]# ip address add 192.168.122.20/32 dev lo

验证需要注意:

curl http://192.168.122.20
1、在LVS所在服务器验证,会一直没有反应。
估计是自己发给自己搞晕了,我也晕了。
[root@xycto ~]# lsof -i:80 -nP
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
curl 27404 xy 3u IPv4 1091220 0t0 TCP 192.168.122.20:48976->192.168.122.20:80 (SYN_SENT)

2、在真实服务器验证,总是返回本机内容。
3、只在第四台机器上验证。

不能监控故障机器:

[root@server2 ~]# systemctl stop httpd
[root@server2 ~]# curl http://192.168.122.20
curl: (7) Failed connect to 192.168.122.20:80; Connection refused

本机总是出现上述错误。
第四台机器随机出现上面的错误。
查阅资料,LVS只能分发请求,不能对服务器访问情况进行检测。后续安装PaceMaker,Keepalived进行测试,而编译安装HeartBeat3.0.6失败。
PS:《CentOS7系统管理与运维实践》书上对NAT样例没有采用多网卡测试,而且认为LVS会自动监控服务器状态。

参考资料:
Linux系统(五)负载均衡LVS集群之DR模式
《CentOS7系统管理与运维实践》ISBN 978-7-302-42395-9 清华大学出版社

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 30%的系统效率提升的数据来源可能是通过对系统的能测试和比较获得的,比如在同样的负载下,新系统的响应时间更短,吞吐量大等。 2. 数据库索引类型包括主键索引、唯一索引、普通索引、全文索引等。 3. GROUP BY是SQL语句中用于对查询结果进行分组的关键字。它可以将查询结果按照指定的列进行分组,并计算每个组的聚合值,如COUNT、SUM等。 4. MHA是一个用于MySQL高可用性的解决方案,可以实现自动故障检测、主从切换等功能。MHA通过监控MySQL Master服务器的状态,当Master出现故障时,自动将Slave提升为新的Master,从而保证服务的连续性。 5. 生产环境中Redis的版本会根据实际情况进行选择,比如需要支持集群模式、主从复制等功能。 6. Redis Cluster集群一般采用6个节点的架构,其中3个为Master节点,3个为Slave节点,Master和Slave节点分别均匀分布在不同的物理服务器上。 7. 磁盘IO是指计算机向磁盘读写数据的过程,包括磁盘读写速度、磁盘空间等指标。 8. 在生产环境中,K8S的版本选择应该根据实际情况进行评估和选择,比如需要支持的功能、稳定性等。 9. Deployment是K8S中用于部署应用程序的资源对象,而DaemonSet是一种特殊的Deployment,用于在每个节点上运行一个Pod。 10. Service是K8S中用于提供服务访问的资源对象,它可以将后端Pod的IP地址和端口暴露给外部。Service有三种类型:ClusterIP、NodePort、LoadBalancer。 11. NodePort和ClusterIP都是Service的类型,但NodePort会将Pod的端口映射到Node的端口上,而ClusterIP只是将Pod的IP地址和端口暴露给集群内部。 12. Service的转发实现是通过K8S的iptables规则或者IPVS规则实现的。 13. kube-proxy有两种模式iptables模式IPVS模式Iptables模式是默认模式,而IPVS模式可以提高Service的性能和稳定性。 14. Calico和Flannel都是K8S中常用的网络插件,Calico通常使用BGP协议实现网络互联,而Flannel则使用VXLAN协议实现网络互联。 15. IPVSiptables都是Linux系统中常用的负载均衡工具。LVS是一种高性能的负载均衡软件,可以通过IPVS实现流量转发。 16. Zabbix可以通过监控Docker API获取容器的状态信息,也可以通过Zabbix Agent在容器内部获取监控数据。 17. 在实际生产环境中,Ansible可以维护数百台甚至上千台服务器。 18. Ansible模块自带的事实功能包括:ansible_distribution、ansible_architecture、ansible_os_family等。 19. 一个生产环境中的Playbook可能包括多个任务,比如部署应用程序、安装依赖、配置环境变量等。 20. 调研某个应用可以从官方文档、社区论坛、用户手册、源代码等多个方面入手,还可以通过搭建测试环境进行实际测试和验证。 21. 如果客户应用系统打不开,可以先检查服务器的网络连接是否正常,同时可以查看应用日志和系统日志,尝试定位问题。 22. 如果客户应用打开比较慢,可以先检查应用程序的配置是否正确,同时可以通过性能测试和监控工具定位问题。 23. 数据库缓存优化可以使用Memcached、Redis、EHCache等技术。 24. 提高数据库读写效率可以使用索引、分区、缓存等技术。同时,还可以采用读写分离、负载均衡等技术来提高数据库的性能和可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值