Linux下群集服务之LB集群-lvs-nat模式

本文涉及的产品
传统型负载均衡 CLB,每月750个小时 15LCU
公网NAT网关,每月750个小时 15CU
应用型负载均衡 ALB,每月750个小时 15LCU
简介:

 O:\RHCA\群集_Cluster\Linux下群集服务之LB群集-lvs-nat模式.docx

Linux下群集服务之lvs在企业网络中的应用案例

案例应用拓扑图:

案例应用实现详细步骤如下:

1.   Client-pc客户端配置

2. Director服务器配置

2.1  Director服务器ip地址配置

[root@junjie ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=10.106.6.254
GATEWAY=10.106.6.1

[root@junjie ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.1.1

[root@junjie ~]# service network restart

Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:                                [  OK  ]

Bringing up interface eth1:                                [  OK  ]

[root@junjie ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:66:E1:DA 
          inet addr:10.106.6.254  Bcast:10.106.6.255  Mask:255.255.255.0
 
[root@junjie ~]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:66:E1:E4 
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
 

[root@junjie ~]# hostname director.junjie.com  #注销重新登录

2.2  开启director数据包转发能力

[root@director ~]# vim /etc/sysctl.conf

  7 net.ipv4.ip_forward = 1

[root@director ~]# sysctl -p
net.ipv4.ip_forward = 1

2.3  配置本地yum服务器:

[root@director ~]# vim /etc/yum.repos.d/server.repo

[rhel-server]

name=Red Hat Enterprise Linux server

baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-cluster]

name=Red Hat Enterprise Linux cluster

baseurl=file:///mnt/cdrom/Cluster/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[root@director ~]#mkdir /mnt/cdrom

[root@director ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@director ~]#yum list all

2.4  安装配置dircetor服务器:

[root@director ~]# yum install -y ipvsadm

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

[root@director ~]# ipvsadm -A -t 10.106.6.254:80 -s wrr

[root@director ~]# ipvsadm -a -t 10.106.6.254:80 -r 192.168.1.2 -m -w 1

[root@director ~]# ipvsadm -a -t 10.106.6.254:80 -r 192.168.1.3 -m -w 2

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  10.106.6.254:80 wrr

  -> 192.168.1.3:80               Masq    2      0          0        

  -> 192.168.1.2:80               Masq    1      0          0

[root@director ~]# service ipvsadm save

Saving IPVS table to /etc/sysconfig/ipvsadm:               [  OK  ]

[root@director ~]# service ipvsadm start

Clearing the current IPVS table:                           [  OK  ]

Applying IPVS configuration:                               [  OK  ]

3.     配置real-server-1web服务器:

3.1 ip地址配置

[root@junjie ~]# hostname r1.junjie.com

注销重新登录

[root@r1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:1b:f1:ba
NETMASK=255.255.255.0
IPADDR=192.168.1.2
GATEWAY=192.168.1.1

[root@r1 ~]# service network restart

Shutting down interface eth0:                              [  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:                                [  OK  ]

3.2 配置本地yum服务器:

[root@r1 ~]# vim /etc/yum.repos.d/server.repo

[rhel-server]

name=Red Hat Enterprise Linux server

baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[root@ r1   ~]#mkdir /mnt/cdrom

[root@r1 ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@r1 ~]#yum list all

3.3  Real-server-1Web服务器:

[root@r1 ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm

warning: /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

Preparing...   #################################### [100%]

1:httpd      ########################################### [100%]

[root@r1 ~]#echo "web1" > /var/www/html/index.html

[root@r1 ~]# service httpd start

Starting httpd: httpd: apr_sockaddr_info_get() failed for r1.junjie.com

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

                                                           [  OK  ]

3.4 客户端访问real-server-1web服务:(使用vmnet1

4.     配置real-server2web服务器:

4.1 ip地址配置

[root@junjie ~]# hostname r2.junjie.com
注销重新登录
[root@r2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:1b:f1:ba
NETMASK=255.255.255.0
IPADDR=192.168.1.3
GATEWAY=192.168.1.1

[root@r2 ~]# service network restart

Shutting down interface eth0:                              [  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:                                [  OK  ]

4.2 配置本地yum服务器:

[root@r2 ~]# vim /etc/yum.repos.d/server.repo

[rhel-server]

name=Red Hat Enterprise Linux server

baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[root@r2 ~]#mkdir /mnt/cdrom

[root@r2 ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@r2 ~]#yum list all

4.3  Real-server-2Web服务器:

[root@r2 ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm

warning: /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

Preparing...   #################################### [100%]

1:httpd      ########################################### [100%]

[root@r2 ~]#echo "web2" > /var/www/html/index.html

[root@r2 ~]# service httpd start

Starting httpd: httpd: apr_sockaddr_info_get() failed for r2.junjie.vom

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

                                                           [  OK  ]

4.4 客户端访问real-server-2web服务:(使用vmnet1

5.     客户端测试:wrr

5.1  客户端访问director的群集服务服务:(网卡使用桥接模式)http//10.106.6.254

5.2 客户端不断刷新,发现出现2次web2,一次web1界面,说明按权重轮询

5.3  在director上查看信息如下:轮询调度比几乎为2:1

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  10.106.6.254:80 wrr

  -> 192.168.1.2:80               Masq    1      0          12       

  -> 192.168.1.3:80               Masq    2      0          24

5.4  客户端测试-2:rr

[root@director ~]# ipvsadm –C          #首先清空以前配置

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

[root@director ~]#  ipvsadm -A -t 10.106.6.254:80 -s rr

[root@director ~]# ipvsadm -a -t 10.106.6.254:80 -r 192.168.1.2 -m

[root@director ~]# ipvsadm -a -t 10.106.6.254:80 -r 192.168.1.3 –m

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  10.106.6.254:80 rr

  -> 192.168.1.3:80               Masq    1      0          0        

  -> 192.168.1.2:80               Masq    1      0          0

[root@director ~]# service ipvsadm save

Saving IPVS table to /etc/sysconfig/ipvsadm:               [  OK  ]

[root@director ~]# service ipvsadm restart

Clearing the current IPVS table:                           [  OK  ]

Applying IPVS configuration:                               [  OK  ]

客户端访问director的群集服务服务:(网卡使用桥接模式)http//10.106.6.254

客户端不断刷新,发现web2和web1交替出现,比率为1:1,说明依次轮询rr

在director上查看信息如下:轮询调度比几乎为1:1;

说明lvs调度方法是用的是RR模式

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  10.106.6.254:80 rr

  -> 192.168.1.2:80               Masq    1      0          15       

  -> 192.168.1.3:80               Masq    1      0          15

《完》

关于Linux下集群服务简介和lvs的详解请参看我的博客:

http://xjzhujunjie.blog.51cto.com/3582724/850650




本文转自xjzhujunjie 51CTO博客,原文链接:http://blog.51cto.com/xjzhujunjie/850866

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
相关文章
|
1月前
|
弹性计算 监控 负载均衡
|
1月前
|
运维 负载均衡 算法
|
2月前
|
负载均衡 Kubernetes 区块链
随机密码生成器+阿里k8s负载均衡型服务加证书方法+移动终端设计+ico生成器等
随机密码生成器+阿里k8s负载均衡型服务加证书方法+移动终端设计+ico生成器等
59 1
|
4月前
|
负载均衡 Kubernetes 开发工具
k8s相关服务与负载均衡
k8s相关服务与负载均衡
54 0
|
4月前
|
负载均衡 监控 网络协议
在Linux中,LVS-DR模式原理是什么?
在Linux中,LVS-DR模式原理是什么?
|
4月前
|
负载均衡 算法 Linux
在Linux中,LVS-NAT模式的原理是什么?
在Linux中,LVS-NAT模式的原理是什么?
|
4月前
|
Linux Apache
在Linux中,apache有几种工作模式,分别介绍下其特点,并说明什么情况下采用不同的工作模式?
在Linux中,apache有几种工作模式,分别介绍下其特点,并说明什么情况下采用不同的工作模式?
|
20天前
|
负载均衡 前端开发 应用服务中间件
负载均衡指南:Nginx与HAProxy的配置与优化
负载均衡指南:Nginx与HAProxy的配置与优化
39 3
|
6月前
|
缓存 负载均衡 算法
解读 Nginx:构建高效反向代理和负载均衡的秘密
解读 Nginx:构建高效反向代理和负载均衡的秘密
130 2
|
5月前
|
负载均衡 算法 应用服务中间件
nginx自定义负载均衡及根据cpu运行自定义负载均衡
nginx自定义负载均衡及根据cpu运行自定义负载均衡
100 1
下一篇
DataWorks