一、两台服务器作为real server ,一台作为director

director:172.28.18.69 vip:172.28.18.70

real server1:172.28.18.71

real server2:172.28.18.78

二、两台real server上安装nginx

配置nginx yum源

[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=
enabled=

安装

[root@localhost ~]# yum install -y nginx

查看

[root@localhost ~]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx..gz
[root@localhost ~]#

配置文件

查看默认根目录页面地址

[root@localhost ~]# vim /etc/nginx/conf.d/default.conf 

server {
listen ;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

编辑/usr/share/nginx/html/index.html

加上本机IP地址,在测试负载均衡的时候,才知道分发到了哪台real server上

[root@localhost ~]# vim /usr/share/nginx/html/index.html 

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!-</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>

保存、退出

启动nginx

[root@localhost conf.d]# nginx -c /etc/nginx/nginx.conf

在浏览器查看

可以显示IP了,同样172.28.18.78的服务器也安装和配置nginx

三、在172.28.18.69上安装ipvsadm

[root@localhost mysql-5.7.]# yum install -y ipvsadm
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.huaweicloud.com
* updates: mirrors.tuna.tsinghua.edu.cn
base | 3.6 kB ::
extras | 3.4 kB ::
updates | 3.4 kB ::
正在解决依赖关系
--> 正在检查事务
---> 软件包 ipvsadm.x86_64.0.1.-.el7 将被 安装
--> 解决依赖关系完成 依赖关系解决 ===========================================================================================================
Package 架构 版本 源 大小
===========================================================================================================
正在安装:
ipvsadm x86_64 1.27-.el7 base k 事务概要
===========================================================================================================
安装 软件包 总下载量: k
安装大小: k
Downloading packages:
ipvsadm-1.27-.el7.x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
** 发现 个已存在的 RPM 数据库问题, 'yum check' 输出如下:
:postfix-2.10.-.el7.x86_64 有缺少的需求 libmysqlclient.so.()(64bit)
:postfix-2.10.-.el7.x86_64 有缺少的需求 libmysqlclient.so.(libmysqlclient_18)(64bit)
正在安装 : ipvsadm-1.27-.el7.x86_64 /
验证中 : ipvsadm-1.27-.el7.x86_64 / 已安装:
ipvsadm.x86_64 :1.27-.el7 完毕!

四、配置虚拟服务器

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

增加一个虚拟服务器 172.28.18.69, -A:增加一个虚拟服务器  -t:tcp协议 -s:分发算法 rr 轮询

五、增加后端实际服务器

[root@director ~]# ipvsadm -a -t 172.28.18.70: -r 172.28.18.71: -g -w 1
[root@director ~]# ipvsadm -a -t 172.28.18.70: -r 172.28.18.78: -g -w 1

-a :增加后端服务器 -t:对应的虚拟服务器IP -r :对应的后端服务器IP -g: DR模式 -w:权重

六、查看配置规则

[root@director home]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.28.18.70:80 rr
-> 172.28.18.71:80 Route 1 0 0
-> 172.28.18.78:80 Route 1 0 0

七、设置director分发器的虚拟IP到设备em1:0

[root@director home]# ip addr add 172.28.18.70 dev em1:
[root@director home]# ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN group default qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc mq state UP group default qlen
link/ether :fe:b5:dc:2c: brd ff:ff:ff:ff:ff:ff
inet 172.28.18.69/ brd 172.28.18.79 scope global noprefixroute em1
valid_lft forever preferred_lft forever
inet 172.28.18.70/ scope global em1
valid_lft forever preferred_lft forever
inet6 fe80::b3e8:e3b2::a2ed/ scope link noprefixroute
valid_lft forever preferred_lft forever
: em2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu qdisc mq state DOWN group default qlen
link/ether :fe:b5:dc:2c: brd ff:ff:ff:ff:ff:ff
: em3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu qdisc mq state DOWN group default qlen
link/ether :fe:b5:dc:2c:7b brd ff:ff:ff:ff:ff:ff
: em4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu qdisc mq state DOWN group default qlen
link/ether :fe:b5:dc:2c:7d brd ff:ff:ff:ff:ff:ff

ip -a 查看,172.28.18.70已经绑定到em1:0上了

此时,在其他机器上测试curl 172.28.18.70,还是不通,是因为在后端服务器上还需要设置虚拟IP绑定到回环接口上

八、绑定虚拟IP到后端服务器的回环接口上

[root@server- html]# ip addr add 172.28.18.70 dev lo:

九、在其他服务器上测试172.28.18.70

[root@zabbix_server ~]# curl 172.28.18.70
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!-71</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

分发到71上

[root@zabbix_server ~]# curl 172.28.18.70
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!-78</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

再次请求,分发到78上。至此lvsDR模式负载均衡配置完成。

centos7下通过LVS的DR模式实现负载均衡访问的更多相关文章

  1. 三台CentOS 5 Linux LVS 的DR 模式http负载均衡安装步骤

    Linux负载均衡软件LVS(概念篇) 一. LVS简介 LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起的自由软件项目,它的官方站点是ww ...

  2. LVS基于DR模式搭建负载均衡群集

    LVS -DR模式集群架构原理图

  3. LVS基于NAT模式搭建负载均衡群集

    LVS的基本架构图 负载均衡群集中,包括三个层次的组件: 1.第一层,负载调度器(BL) 前段至少有一个负载调度器(Load Balancer 或称为Director)负责响应并分发来自客户端的访问请 ...

  4. 借助LVS+Keepalived通过DR模式实现负载均衡

    1.测试环境4台server,全部初始化一下,该关的关了 # vim /etc/hosts 192.168.1.101 lvs-master DIP 192.168.1.102 lvs-slave D ...

  5. 在centos7下搭建nginx环境,并配置负载均衡,最终能达到通过域名直接访问的目的

    1.关于nginx:个人理解的nginx它的主要用途就是负载均衡,当然可能还有其他一些功能可能我们不长用到,我们通过nginx可以干什么呢?为什么要引入它呢?原因是当有高并发访问服务器时,服务器可能会 ...

  6. LVS的DR模式负载均衡

    参考项目:http://www.cnblogs.com/along21/p/7833261.html#auto_id_3 LVS的DR模式实现负载均衡 1.环境 lvs-server :192.168 ...

  7. LVS:DR模式(Direct Routing)部署实验

    本文介绍怎样在kvm的虚拟环境下,部署实验LVS的DR模式.包含网络结构图,怎样配置.以及使用tcpdump分析ip包. 网络结构图                               kvm ...

  8. LVS的DR模式

    DR模式: 请求由LVS接受,由真实提供服务的服务器(RealServer, RS)直接返回给用户,返回的时候不经过LVS. DR模式下需要LVS和绑定同一个VIP(RS通过将VIP绑定在loopba ...

  9. Lvs Keepalive DR模式高可用配置

    Lvs Keepalive DR模式配置 一.环境 #DIP# eth0:192.168.233.145#VIP# eth0:0 192.168.233.250/32 #RIP1:192.168.23 ...

随机推荐

  1. jquery 登录判断遇到的小问题

    1.碰到的第一个问题是: 往body上加载check,用load不管用,可以用ready试试. 2.原来jquery里获取用的val(),我一直以为是value()... 尴尬 3.两个标志位是为了判 ...

  2. flask url_for后没有带端口号

    问题描述: 在本地运行flask项目,当运行到下面这句代码时,正常重定向 return redirect(url_for('.script_case')) 但项目布署到服务器之后,代码运行一这句话,却 ...

  3. 阶段3 3.SpringMVC·_01.SpringMVC概述及入门案例_08.RequestMapping注解的作用

    用于建立请求URL和处理请求方法之间的对应关系. 增加一个testResuqestMapping方法来测试 把注解放在类上 服务器重新部署 再次重新部署 这次就可以请求到数据 了 注解放在类上:用来表 ...

  4. pcap中不同包功能

    1.不同包协议的功能 EAPoL:基于局域网的扩展认证协议 ICMPv6:(一般是四个连在一起)互联网控制协议第六套 DHCP Discover:请求分配IP DHCP Offer:你的IP是***, ...

  5. 【MM系列】SAP S/4 HANA 1511的BP角色创建及供应商数据的创建方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP S/4 HANA 1511的 ...

  6. LeetCode.989-数组形式的整数做加法(Add to Array-Form of Integer)

    这是悦乐书的第371次更新,第399篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第233题(顺位题号是989).对于非负整数X,X的数组形式是从左到右顺序的数字数组.例 ...

  7. flowable+tomcat部署flowable项目,在线画流程图

    参考: flowable+tomcat部署flowable项目,在线画流程图

  8. 小记---------spark组件与其他组件的比较 spark/mapreduce ;spark sql/hive ; spark streaming/storm

    Spark与Hadoop的对比   Scala是Spark的主要编程语言,但Spark还支持Java.Python.R作为编程语言 Hadoop的编程语言是Java    

  9. Spring是如何使用责任链模式的?

    关于责任链模式,其有两种形式,一种是通过外部调用的方式对链的各个节点调用进行控制,从而进行链的各个节点之间的切换. 另一种是链的每个节点自由控制是否继续往下传递链的进度,这种比较典型的使用方式就是Ne ...

  10. Java第四周总结报告

    本周做了什么? 学习了Java的面向对象知识,包括对类,对象,抽象的理解 下周准备做什么? 学习Java面向对象的有关知识,包括对象与类,继承关系等内容 代码联系时间五个小时,看书四个小时. 本周遇到 ...