设为首页 收藏本站
查看: 1359|回复: 0

[经验分享] 18.6 负载均衡集群介绍;18.7 LVS介绍;18.9 LVS NAT模式搭建(上);18.10 LVS NAT模式搭建(下)

[复制链接]

尚未签到

发表于 2019-1-5 15:10:41 | 显示全部楼层 |阅读模式
  扩展:
  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




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-659748-1-1.html 上篇帖子: linux下基于lvs 下篇帖子: 实现LVS负载均衡NAT模式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表