Centos7下lvs负载均衡lvs-tun模式配置
一、架构
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 home]# ipvsadm -a -t 172.28.18.70: -r 172.28.18.71: -i -w
[root@director home]# ipvsadm -a -t 172.28.18.70: -r 172.28.18.78: -i -w
-a :增加后端服务器 -t:对应的虚拟服务器IP -r :对应的后端服务器IP -i: lvs-tun模式 -w:权重
六、查看配置规则
[root@director home]# ipvsadm -Ln
IP Virtual Server version 1.2. (size=)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.28.18.70: rr
-> 172.28.18.71: Tunnel
-> 172.28.18.78: Tunnel
七、设置director分发器的虚拟IP到设备em1:0
[root@director home]# ip addr add 172.28.18.70 dev em1:
八、在后端服务器上加载ipip模块
加载ipip模块后,就会有默认的tunl0隧道
1、查看是否有tunl0隧道
[root@localhost conf]# lsmod|grep ipip
[root@localhost conf]#
没有ipip模块,加载ipip模块
[root@localhost conf]# modprobe ipip
再查看,有了
[root@localhost conf]# lsmod|grep ipip
ipip
tunnel4 ipip
ip_tunnel ipip
ip a ,查看tunl0也有了
[root@server- html]# 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 :b1:1c::be: brd ff:ff:ff:ff:ff:ff
inet 172.28.18.78/ brd 172.28.18.79 scope global noprefixroute em1
valid_lft forever preferred_lft forever
inet6 fe80::e6fb:2cb7::/ 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 :b1:1c::be:0a brd ff:ff:ff:ff:ff:ff
inet 192.168.18.103/ brd 192.168.18.255 scope global noprefixroute em2
valid_lft forever preferred_lft forever
inet6 fe80:::91de::a505/ scope link tentative
valid_lft forever preferred_lft forever
: tunl0@NONE: <NOARP> mtu qdisc noop state DOWN group default qlen
link/ipip 0.0.0.0 brd 0.0.0.0
九、在后端服务器上配置虚拟IP绑定tunl0
[root@localhost conf]# ip addr add 172.28.18.70 dev tunl0
十、在后端服务器上配置关闭ARP转发
net.ipv4.conf.tunl0.arp_ignore =
net.ipv4.conf.tunl0.arp_announce =
net.ipv4.conf.all.arp_ignore =
net.ipv4.conf.all.arp_announce =
net.ipv4.conf.tunl0.rp_filter =
net.ipv4.conf.all.rp_filter =
[root@localhost conf]# sysctl -p
Centos7下lvs负载均衡lvs-tun模式配置的更多相关文章
- 20.LVS负载均衡群集—NAT模式实例
LVS负载均衡群集-NAT模式实例 目录 LVS负载均衡群集-NAT模式实例 群集引用概述 群集的含义 问题 解决方法 企业群集分类 群集的三种类型 负载均衡群集(Load Balance Clust ...
- LVS负载均衡之DR模式原理介绍
LVS基本原理 流程解释: 当用户向负载均衡调度器(Director Server)发起请求,调度器将请求发往至内核空间 PREROUTING 链首先会接收到用户请求,判断目标 IP 确定是本机 IP ...
- LVS负载均衡之DR模式部署
1.LVS的DR模式介绍 参考自官网:http://www.linuxvirtualserver.org/zh/lvs3.html VS/DR利用大多数Internet服务的非对称特点,负 ...
- LVS负载均衡之NAT模式部署
1.LVS的NAT模式介绍 参考自官网:http://www.linuxvirtualserver.org/zh/lvs3.html 由于IPv4中IP地址空间的日益紧张和安全方面的原因,很多网络使用 ...
- LVS负载均衡三种模式的实现
何为lvs负载均衡? lvs负载均衡(linux virtual server)又名linux虚拟服务器.由章文嵩博士主导的负载均衡项目,目前LVS已经被集成到Linux内核模块中.该项目在Linux ...
- LVS负载均衡IP隧道模式原理介绍以及配置实战
LVS 基本工作原理 当用户向负载均衡调度器(Director Server)发起请求,调度器将请求发往至内核空间 PREROUTING 链首先会接收到用户请求,判断目标 IP 确定是本机 IP,将数 ...
- 11.4.5 LVS负载均衡常见工作模式总结以及ipvsadm
NAT TUN DR RS any Tunneling Non-arp device RS network private LAN/WAN LAN RS number low(10-20) Hig ...
- LVS 负载均衡——直接路由模式DR
一.配置的网络拓扑结构图 二.配置lvs服务器 配置虚拟网卡地址(VIP地址) [root@localhost ~]# ifconfig eno16777728: 192.168.200.253 ne ...
- LVS负载均衡DR模式实现
LVS负载均衡之DR模式配置 DR 模式架构图: 操作步骤 实验环境准备:(centos7平台) 所有服务器上配置 # systemctl stop firewalld //关闭防火墙 # sed - ...
- LVS负载均衡NAT模式实现
LVS负载均衡之NAT模式配置 NAT 模式架构图: 操作步骤 实验环境准备:(centos7平台) 所有服务器上配置 # systemctl stop firewalld //关闭防火墙 # sed ...
随机推荐
- leetcode 139 单词拆分(word break)
一开始的错误答案与错误思路,幻想直接遍历得出答案: class Solution { public: bool wordBreak(string s, vector<string>& ...
- Git检出和提交至远程仓库
步骤一:首先需要一个Github账号,还没有的话先去注册:https://github.com/,我们使用Git需要先安装Git工具,这里给出下载地址:https://git-for-windows. ...
- 解决ssh链接慢问题
1,ssh -v root@ip 2,查看哪里卡住了 一般情况就是卡在debug1: SSH2_MSG_SERVICE_ACCEPT received 3,如果是上面卡住了 修改/etc/ssh/ss ...
- flutter stack嵌套,appbar透明,Container设置背景图片并且图片在appbar之下
stack嵌套 一般情况下 stack是无法嵌套,出现stack嵌套,布局就会出乱 解决方式:就是第二个stack需要确定宽高 appbar透明 AppBar( backgroundColor: Co ...
- zabbix服务端安装
1.安装zabbix服务(1)先rpm安装lamp环境 yum install -y httpd mysql mysql-libs php php-mysql mysql-server php-bcm ...
- vue中html、css、js 分离
在正常的创建和引用vue文件都是html.css.js三者在一起的,这样写起来虽然方便了,但是页面比较大或者代码比较多的情况下,即使使用组件有时代码也比较多,简单来说查找不变不利于编程,大的来说影像优 ...
- 企业应用学习-git学习
1.git的基本使用 git与svn的区别 GIT 是分布式的,SVN 不是:这是 GIT 和其它非分布式的版本控制系统,例如 SVN,CVS 等,最核心的区别. GIT 把内容按元数据方式存储,而 ...
- centos没有ifcfg-eth0或者ifcfg-eth0文件内容为空
虚拟机安装好CentOS 6系统后,发现ip在每次重启后都会还原,用ifconfig查看是有eth0网卡的(也有可能只有回环网卡lo),于是查看eth0网卡配置文件,发现在 /etc/sysconfi ...
- mysql——单表查询——聚合函数——概念
使用聚合函数查询 group by关键字通常和聚合函数一起使用 .count()函数 count()函数用来统计记录的条数 举例:使用count()函数统计employee表的记录数 select c ...
- 【五一qbxt】test1
(不知道为什么居然爆零了qwq) (全员爆零诶,最高分10分???还是rand出来的???) 我freopen写错了????自闭了 不行不行再写一遍freopen加深印象,不能再写错了 freopen ...