Linux负载均衡解决方案 -- LVS-NAT 模式 案例实战

LVS-NAT 模式 案例实战

  • 一、环境准备
  • 二、案例实战
  • 三、测试

一、环境准备

架构设计
Linux负载均衡解决方案 -- LVS-NAT 模式 案例实战_第1张图片
环境配置

硬件配置

操作系统:centos-7.8 cpu:1*1 硬盘:20G 内存:2G

网络配置

role host ip getway OS
Client node05 192.168.5.5 WAN网出口 Centos-7.8
Director-Server node01 192.168.5.4、172.24.8.100 WAN网出口 Centos-7.8
Web1 node02 172.24.8.11 172.24.8.100 Centos-7.8
Web2 node03 172.24.8.12 172.24.8.100 Centos-7.8
Web3 node04 172.24.8.13 172.24.8.100 Centos-7.8

二、案例实战

配置时间同步

服务端:# vim /etc/chrony.conf
server 172.24.8.100 iburst
allow 172.24.8.0/24
local stratum 10
启动:# systemctl restart chronyd
客户端:
server 172.24.8.100 iburst
启动:# systemctl restart chronyd

[root@node01 ~]# date
Fri Feb 19 15:05:53 CST 2021
[root@node02 ~]# date
Fri Feb 19 15:05:53 CST 2021
[root@node03 ~]# date
Fri Feb 19 15:05:53 CST 2021
[root@node04 ~]# date
Fri Feb 19 15:05:53 CST 2021

负载调度开启路由转发

# 临时开启
--- 方法一
[root@node01 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
--- 方法二
[root@node01 ~]# sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1

# 永久开启
[root@node01 ~]# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
[root@node01 ~]# sysctl -p
net.ipv4.ip_forward = 1

RS 节点部署nginx服务

# 以Web1为例演示
[root@node02 ~]# ll nginx-1.10.0-1.el7.ngx.x86_64.rpm 
-rw-r--r--. 1 root root 655648 Feb 19 15:41 nginx-1.10.0-1.el7.ngx.x86_64.rpm
[root@node02 ~]# yum install nginx-1.10.0-1.el7.ngx.x86_64.rpm  -y
[root@node02 ~]# cd /usr/share/nginx/html/
[root@node02 html]# mv index.html{,.bak}
[root@node02 html]# echo web1 test page > index.html
[root@node02 html]# systemctl enable --now nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@node02 html]# netstat -lnutp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12220/nginx: master 

Director-Server 配置 LVS-DR

ipvsadm 主要选项

>--add-service     -A        add virtual service with options
>--edit-service    -E        edit virtual service with options
>--delete-service  -D        delete virtual service
>--clear           -C        clear the whole table
>--restore         -R        restore rules from stdin
>--save            -S        save rules to stdout
>--add-server      -a        add real server with options
>--edit-server     -e        edit real server with options
>--delete-server   -d        delete real server
>--list            -L|-l     list the table
>--tcp-service     -t service-address   service-address is host[:port]
>--udp-service     -u service-address   service-address is host[:port]
>--gatewaying      -g                   gatewaying (direct routing) (default)
>--ipip            -i                   ipip encapsulation (tunneling)
>--masquerading    -m                   masquerading (NAT)
>--weight          -w weight            capacity of real server
# 安装ipvsadm
[root@node01 ~]# yum install ipvsadm -y
# 查看集群节点空
[root@node01 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
# 添加集群
[root@node01 ~]# ipvsadm -A -t 192.168.5.4:80 -s rr
[root@node01 ~]# ipvsadm -a -t 192.168.5.4:80 -r 172.24.8.11:80 -m
[root@node01 ~]# ipvsadm -a -t 192.168.5.4:80 -r 172.24.8.12:80 -m
[root@node01 ~]# ipvsadm -a -t 192.168.5.4:80 -r 172.24.8.13:80 -m
# 查看集群节点
[root@node01 ~]# 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.5.4:80 rr
  -> 172.24.8.11:80               Masq    1      0          0         
  -> 172.24.8.12:80               Masq    1      0          0 
  -> 172.24.8.13:80               Masq    1      0          0 

三、测试

实现负载均衡!!!
Linux负载均衡解决方案 -- LVS-NAT 模式 案例实战_第2张图片

你可能感兴趣的:(Web,Server,Clusters,Web集群技术,LVS-DR,模式,案例实战,运维)