您的位置:首页 > 其它

18.6 负载均衡集群介绍;18.7 LVS介绍;18.9 LVS NAT模式搭建(上);18.10 LVS NAT模式搭建(下)

2017-09-05 21:18 901 查看
扩展:
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
18.6 负载均衡集群介绍
1. 主流开源软件LVS、keepalived、haproxy、nginx等
2. 其中LVS属于4层(网络OSI 7层模型),nginx属于7层,haproxy既可以认为是4层,也可以当做7层使用
3. keepalived的负载均衡功能其实就是lvs
4. lvs这种4层的负载均衡是可以分发除80外的其他端口通信的,比如MySQL的,而nginx仅仅支持http,https,mail,haproxy也支持MySQL这种
5. 相比较来说,LVS这种4层的更稳定,能承受更多的请求,而nginx这种7层的更加灵活,能实现更多的个性化需求
18.7 LVS介绍;
1. LVS是由国人章文嵩开发
2. 流行度不亚于apache的httpd,基于TCP/IP做的路由和转发,稳定性和效率很高
3. LVS最新版本基于Linux内核2.6,有好多年不更新了
4. LVS有三种常见的模式:NAT、DR、IP Tunnel
5. LVS架构中有一个核心角色叫做分发器(Load balance),它用来分发用户的请求,还有诸多处理用户请求的服务器(Real Server,简称rs)






18.8 LVS的调度算法
前四条算法较为重要!!!
1. 轮询 Round-Robin rr
2. 加权轮询 Weight Round-Robin wrr
3. 最小连接 Least-Connection lc
4. 加权最小连接 Weight Least-Connection wlc
5. 基于局部性的最小连接 Locality-Based Least Connections lblc
6. 带复制的基于局部性最小连接 Locality-Based Least Connections with Replication lblcr
7. 目标地址散列调度 Destination Hashing dh
8. 源地址散列调度 Source Hashing sh
18.9 LVS NAT模式搭建(上)
NAT模式搭建 – 准备工作
准备三台机器:hao1 hao2 hao3
hao1机器操作:
hao1机器作为:分发器,也叫调度器(简写为dir)
1. 添加一个新网卡,选择仅主机模式
ens33网卡内网:192.168.211.128(ANT模式)
ens37网卡外网:192.168.47.128(仅主机模式)


2. 编辑ens37网卡配置文件:
[root@hao-01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens37
设定ip为(仅主机网段): 192.168.47.128
添加内容(不用设置网关):
NAME=ens37
DEVICE=ens37
ONBOOT=no
IPADDR=192.168.47.128
PREFIX=24



3. 重启网络服务命令:(重启network.service网络服务)
[root@hao-01 ~]# systemctl restart network.service
4. 激活ens37网卡
[root@hao-01 ~]# ifup ens37
5. 在windows系统,ping下ens37(仅主机)外网ip:



hao1 hao2 hao3机器都要执行下面关闭防火墙命令:
1. 关闭firewalld防火墙:
[root@hao-01 ~]# systemctl stop firewalld
设定开机不启动firewalld防火墙:
[root@hao-01 ~]# systemctl disable firewalld
查看firewalld防火墙是否关闭?
[root@hao-01 ~]# iptables -nvL


2. 安装centos 6系统中的iptables防火墙工具:
[root@hao-01 ~]# yum install -y iptables-services
如果上面安装慢,临时重命名epel.repo,再yum 安装
(记得改回重命名!):
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo1
启用iptables:
[root@hao-01 ~]# systemctl enable iptables
开启iptables:
[root@hao-01 ~]# systemctl start iptables
清除防火墙规则:
[root@hao-01 ~]# iptables -F
关闭iptables:
[root@hao-01 ~]# service iptables save
查看firewalld防火墙是否关闭?
[root@hao-01 ~]# iptables -nvL


3. 临时关闭getenforce防火墙:
[root@hao-01 ~]# setenforce 0
永久关闭getenforce防火墙:
[root@hao-01 ~]# vi /etc/selinux/config
更改内容:
SELINUX=disabled


hao2 hao3机器上操作:
ens33网卡网关改成ip段为内网段,ip为hao1内网ip(128)
1. 更改hao2机器ens33网卡配置文件:
[root@hao-02 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33



重启网卡:
[root@hao-02 ~]# systemctl restart network
2. 更改hao3机器ens33网卡配置文件:
[root@hao-03 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33



重启网卡:
[root@hao-03 ~]# systemctl restart network
18.10 LVS NAT模式搭建(下)
hao1机器(dir)上操作:
1. 在hao1机器(dir)上,安装 ipvsadm:
[root@hao-01 ~]# yum install -y ipvsadm
2. 在hao1机器(dir)上,编写lvs_nat.sh脚本:
[root@hao-01 ~]# 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 192.168.211.0/24 -j MASQUERADE
# director设置ipvsadm
IPVSADM='/usr/sbin/ipvsadm'
$IPVSADM -C
$IPVSADM -A -t 192.168.47.128:80 -s rr
$IPVSADM -a -t 192.168.47.128:80 -r 192.168.211.129:80 -m -w 1
$IPVSADM -a -t 192.168.47.128:80 -r 192.168.211.130:80 -m -w 1


3. 执行lvs_nat.sh脚本:
[root@hao-01 ~]# sh /usr/local/sbin/lvs_nat.sh
hao2机器(r)上操作:
1. 启动nginx(yum安装的nginx):
[root@hao-02 ~]# systemctl start nginx
2. 搜索nginx是否启动?
[root@hao-02 ~]# ps aux |grep nginx
3. 清空index.html内容(yum安装的nginx):
[root@hao-02 ~]# > /usr/share/nginx/html/index.html
4. 编辑index.html(yum安装的nginx):
[root@hao-02 ~]# vim /usr/share/nginx/html/index.html
添加内容(便于和hao3区分):
hao2
5. 查看:
[root@hao-02 ~]# curl localhost
hao3机器(r)上操作:
1. 启动nginx(yum安装的nginx):
[root@hao-03 ~]# systemctl start nginx
2. 搜索nginx是否启动?
[root@hao-03 ~]# ps aux |grep nginx
3. 清空index.html内容(yum安装的nginx):
[root@hao-03 ~]# > /usr/share/nginx/html/index.html
4. 编辑index.html(yum安装的nginx):
[root@hao-03 ~]# vim /usr/share/nginx/html/index.html
添加内容(便于和hao2区分):
hao3
5. 查看:
[root@hao-03 ~]# curl localhost
hao1机器(dir)上操作测试:
1. curl访问hao1机器(dir) ens37外网ip:
[root@hao-01 ~]# curl 192.168.47.128
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LVS NAT 模式搭建
相关文章推荐