枫叶飞翔 发表于 2019-1-4 09:12:24

Linux服务器负载均衡LB Cluster的LVS(NAT,DR)

  一 基础知识:
  1 群集种类:
  1.1 LB 负载均衡;解决大量的并发的连接请求;
  scale on(单机处理能力的增强)
  scale out
  1.2 HA 高可用性群集;应用于企业网中高可用性体系,提供时时的在线服务99.999%能够正常运行;
  1.3 HP 高性能群集;应用于大量的复杂的计算时使用;
  2 群集分发装置(director dispather):将请求分发到群集中的各个主机中
  2.1 从表现形式上划分:
  2.1.1 通过硬件实现(F5)
  2.1.2 通过软件(比如Linux中的2.4、2.6、ipvs-->lvs)
  2.2 从层次上划分:
  2.2.1 四层交换:协议端口号【包括:F5、lvs】
  2.2.2 七层交换:squidnginx
  3 为了实现LVS-DR模型需要解决相关问题:
  3.1 每个real server上都需要配置vip;vip配置在lookback接口上;
  3.2 解决多个相同vip导致的arp应答混乱;
  3.3 通过arp_arpannounce和arp_ignore来控制realserver的arp应答;
  3.4 解决realserver的应答报文的源地址,源地址应该为VIP;
  4 LVS三种模型:
  4.1 LVS-NAT模型:
  特点:VS-NAT 最易于配置 ; 可扩展性差 ;所有流量都要经过分发装置,容易形成瓶颈;
  数据包流向:CIP-DGW-VIP-RIP-DIP-DGW-CIP
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794993y1vH.png
  4.2 LVS-DR模型:直接路由模型;
  特点:能够处理比nat模型更过的节点;
  数据包流向:CIP-DGW-VIP-RIP-DGW-CIP
  Rip和dip需在同一个网络中;
  Realserver的网关不再是rip;
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794994eJmg.png
  4.3 LVS-TUN:隧道模型;
  特点:可以夸广播域,即不再同一局域网内;可扩展性好;仅修改请求进入IP;
  数据包流向:CIP-DGW-VIP-RIP-DGW-CIP
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794994SHHx.png
  5 ipvsadmin 常用命令:   
         ipvsadm -Ln         查看分发规测和分发情况   
         ipvsadm -Ln -c         查看连接状态   
         ipvsadm -L -n --rate    查看当前连接数   
         ipvsadm -L -n --stats    查看总连接数   
         ipvsadm -C            清空规则
  6 客户端的arp控制:
  6.1 详解arp_arpannounce:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794994Bkkb.png
  //将使用2integer;
  6.2 详解arp_ignore:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794995OYdd.png
  //将使用1integer;
  二 案例一:实现基于LVS-NAT模型的服务器群集
  1 拓扑图:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794995hUSR.png
  2 案例说明:
  实现基于LVS-NAT模型的服务器群集,采用轮训调度(RR);
  3 配置步骤:
  3.1 配置realserver1
  3.1.1 网络参数:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794996KXSd.png
  3.1.2 重启网络服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794996m0Qs.png
  3.1.3 挂在光盘:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794996WJM6.png
  3.1.4 安装realserver1的httpd服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_13497949975V41.png
  3.1.5 创建realserver1的测试页:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794997vWWb.png
  3.1.6 启动httpd服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794998VRKU.png
  3.2 配置realserver2
  3.2.1 网络参数:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794998qW9w.png
  3.2.2 重启网络服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794998Gz9a.png
  3.2.3 挂在光盘:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794999NDVu.png
  3.2.4 安装realserver1的httpd服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349794999VtVC.png
  3.2.5 创建realserver1的测试页:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795000pAxN.png
  3.2.6 启动httpd服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795000ZF5f.png
  3.3 配置director群集服务器
  3.3.1 网络参数:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795000zXLP.png
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795001r3T7.png
  3.3.2 重启网络服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795004BcTG.png
  3.3.3 打开路由转发功能:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795005daNj.png
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795005YZvg.png
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795005jmQd.png
  3.3.4 挂在光盘:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795006sTL0.png
  3.3.5 安装ipvs管理工具:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795006xHda.png
  3.3.6 执行一下命令产生ipvsadm规则文件:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795007eMfu.png
  3.3.7 启动ipvsadm:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_13497950078h3C.png
  3.3.8 添加ipvs规则:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795007nOmx.png
  3.3.9 将ipvsadm规则写入ipvsadm文件中:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795008BYMK.png
  3.4 测试:
  3.4.1 使用http访问192.168.10.100
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795008IjhS.png
  3.4.2 刷新后:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795012i2UF.png
  三 案例二“实现基于LVS-DR模型的服务器群集
  1 拓扑图
http://blog.运维网.com/attachment/201210/204649975.jpg
  2 案例说明
  实现基于LVS-DR模型的服务器群集,采用轮训调度(RR);
  3 配置步骤
  3.1 配置realserver1
  3.1.1 在系统控制文件sysctl.conf中添加arp内核参数:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795016JPNB.png
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_13497950176gO7.png
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795020wkXM.png
  3.1.2 在eth0网卡上配置RIP:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795026EAsI.png
  3.1.3 在loopback接口上配置VIP:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795026j9vu.png
  3.1.4 重启网络服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795027vj0D.png
  3.1.5 添加路由:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795027UWZV.png
  //为了实现使用vip来对访问进行应答,需要使从realserver1到任何地址的数据包从lo:0的接口使用vip发送;
  3.1.6 挂在光盘:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795028eydG.png
  3.1.7 安装realserver1的httpd服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795028DjlT.png
  3.1.8 创建realserver1的测试页:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795037UjgG.png
  3.1.9 启动httpd服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795041hcyF.png
  3.2 配置realserver2
  3.2.1 在系统控制文件sysctl.conf中添加arp内核参数:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_13497950417z0R.png
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795042O2ku.png
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795042ewFC.png
  3.2.2 在eth0网卡上配置RIP:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_13497950435XPl.png
  3.2.3 在loopback接口上配置VIP:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_134979504353s3.png
  3.2.4 重启网络服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795043oInx.png
  3.2.5 添加路由:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_13497950470eDF.png
  //为了实现使用vip来对访问进行应答,需要使从realserver1到任何地址的数据包从lo:0的接口使用vip发送;
  3.2.6 挂在光盘:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795050NxPZ.png
  3.2.7 安装realserver1的httpd服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795053yLUl.png
  3.2.8 创建realserver1的测试页:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795056pMyj.png
  3.2.9 启动httpd服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_13497950601Ot9.png
  3.3 配置director群集服务器
  3.3.1 配置director的RIP:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795060NXAr.png
  3.3.2 配置director的VIP:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795061arx8.png
  3.3.3 重启网络服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795064JCJd.png
  3.3.4 挂载光盘:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795064qs57.png
  3.3.5 安装ipvsadm服务:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795065J2jU.png
  3.3.6 执行一下命令产生ipvsadm规则文件:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795065t8Rm.png
  3.3.7 启动ipvsadm:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795065EmyJ.png
  3.3.8 添加ipvs规则:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795066WBMv.png
  3.3.9 将ipvsadm规则写入ipvsadm文件中:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_13497950666SQ4.png
  3.4 测试:
  3.4.1 使用http访问192.168.10.10
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795067zyIo.png
  3.4.2 刷新后:
http://cexpert.blog.运维网.com/attachment/201210/9/5251990_1349795067oYZ2.png
四 案例三“实现基于LVS-DR模型的服务器群集,并实现基于NFS的简单存储“
1 拓扑图
http://blog.运维网.com/attachment/201210/205146740.jpg


2 案例说明
实现基于LVS-DR模型的服务器群集,采用轮训调度(RR);
Web服务器的页面文件从NFS网络文件系统中读取
3 配置步骤:基于案例2的群集模型,只是在web服务中加入了存储;
3.1 配置nfs服务器:
3.1.1 网络配置:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
1 # Advanced Micro Devices 79c970
2 DEVICE=eth0
3 BOOTPROTO=none
4 ONBOOT=yes
5 HWADDR=00:0c:29:58:6b:94
6 NETMASK=255.255.255.0
7 IPADDR=192.168.10.103
8 TYPE=Ethernet
3.1.2 重启网络服务:
# service network restart
3.2 NFS服务是默认安装的,使用时直接启动即可;
3.2.1 启动nfs服务:
# service nfs start
3.2.2 创建一个共享文件和测试页面:
# mkdir /public
# echo 'from nfs server!' >/public/index.html
3.2.3 编写共享清单:
# vim /etc/exports
    1 /public 192.168.10.0/24(ro)
3.2.4 导出共享清单:
# exportfs -rv
exporting 192.168.10.0/24:/public
-r 导出;
-v 详细信息;
3.3 在realserver1服务器上进行nfs客户端配置:
3.3.1 编辑自动挂载文件:
# vim /etc/auto.master
9 /misc   /etc/auto.misc
10 /var/www /etc/auto.htmount --timeout
3.3.2 创建并编辑nfs共享文件挂载点的监控文件:
# cp -p /etc/auto.misc /etc/auto.htmount
# vim /etc/auto.htmount
18 html            -ro,soft,intr         192.168.10.103:/public
3.3.3 重启autofs服务:
# service autofs restart
3.3.4 重启httpd服务:
# service httpd restart
3.3.5 查看当前挂载情况:
# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
192.168.10.103:/public on /var/www/html type nfs (ro,timeout,soft,intr,addr=192.168.10.103)
//此时httpd的主配置文件成功挂载;
3.4 在realserver2服务器上进行nfs客户端配置:
3.4.1 编辑自动挂载文件:
# vim /etc/auto.master
9 /misc   /etc/auto.misc
10 /var/www /etc/auto.htmount --timeout
3.4.2 创建并编辑nfs共享文件挂载点的监控文件:
# cp -p /etc/auto.misc /etc/auto.htmount
# vim /etc/auto.htmount
18 html            -ro,soft,intr         192.168.10.103:/public
3.4.3 重启autofs服务:
# service autofs restart
3.4.4 重启httpd服务:
# service httpd restart
3.4.5 查看当前挂载情况:
# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
192.168.10.103:/public on /var/www/html type nfs (ro,timeout,soft,intr,addr=192.168.10.103)
3.5 测试:
http://blog.运维网.com/attachment/201210/205210771.png
  测试成功!!



页: [1]
查看完整版本: Linux服务器负载均衡LB Cluster的LVS(NAT,DR)