负载均衡集群介绍、LVS NAT模式搭建、LVS DR模式搭建、keepalived lvs

负载均衡集群介绍

负载均衡集群介绍

LVS介绍

LVS介绍

LVS介绍

LVS介绍

LVS的调度算法

LVS的调度算法
LVS NAT模式搭建

LVS NAT模式搭建

所有机器上操作

[root@wsl1 ~]# systemctl stop firewalld
[root@wsl1 ~]# systemctl disable firewalld
[root@wsl1 ~]# systemctl start iptables
[root@wsl1 ~]# iptables -F
[root@wsl1 ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  确定  ]
LVS NAT模式搭建

分发器上操作
$IPVSADM -A -t 192.168.147.144:80 -s wlc -p 3 (-s为指定调度算法,-p为指定链接超时时间)

[root@wsl3 ~]# yum install -y ipvsdam

[root@wsl3 ~]# vim /usr/local/sbin/lvs_nat.sh

#! /bin/bash
# director 服务器上开启路由转发功能
echo 1 > /proc/sys/net/ipv4/ip_forward
# 关闭icmp的重定向
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
# 注意区分网卡名字,阿铭的两个网卡分别为ens33和ens37
echo 0 > /proc/sys/net/ipv4/conf/ens33/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/ens37/send_redirects
# director 设置nat防火墙
iptables -t nat -F
iptables -t nat -X
iptables -t nat -A POSTROUTING -s 172.16.230.0/24  -j MASQUERADE
# director设置ipvsadm
IPVSADM='/usr/sbin/ipvsadm'
$IPVSADM -C
$IPVSADM -A -t 172.16.79.144:80 -s rr
$IPVSADM -a -t 172.16.79.144:80 -r 172.16.230.131:80 -m -w 1
$IPVSADM -a -t 172.16.79.144:80 -r 172.16.230.132:80 -m -w 1

[root@wsl3 ~]# sh /usr/local/sbin/lvs_nat.sh

测试

WSL:~ Martin.Wang$ curl 172.16.79.144 |head -4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   614  100   614    0     0   265k      0 --:--:-- --:--:-- --:--:--  299k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to MASTER!</title>
WSL:~ Martin.Wang$ curl 172.16.79.144 |head -4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   614  100   614    0     0   266k      0 --:--:-- --:--:-- --:--:--  299k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to BACKUP!</title>
WSL:~ Martin.Wang$ curl 172.16.79.144 |head -4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   614  100   614    0     0   298k      0 --:--:-- --:--:-- --:--:--  599k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to MASTER!</title>
WSL:~ Martin.Wang$ curl 172.16.79.144 |head -4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   614  100   614    0     0   237k      0 --:--:-- --:--:-- --:--:--  299k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to BACKUP!</title>

[root@wsl3 network-scripts]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  172.16.79.144:80 rr
  -> 172.16.230.131:80            Masq    1      1          4
  -> 172.16.230.132:80            Masq    1      0          4

扩展
lvs 三种模式详解 http://www.it165.net/admin/html/201401/2248.html
lvs几种算法 http://www.aminglinux.com/bbs/thread-7407-1-1.html
关于arp_ignore和 arp_announce http://www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html
lvs原理相关的 http://blog.csdn.net/pi9nc/article/details/23380589

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容