一、 环境要求
需要2台LVS和n(n>=2)台RS
操作系统 负载均衡模式 VIP NVIP
RHEL7.4 NAT 193.168.141.30 192.168.102.165

LVS1 LVS2 RS1 RS2
ens3:192.168.102.161 ens3:192.168.102.162 ens3:192.168.102.163 ens3:192.168.102.164
ens4:193.168.141.20 ens4:193.168.141.27 网关:192.168.102.165 网关:192.168.102.165
LVS:
安装ipvsadm(LVS管理工具)和keepalived;
RS:
安装httpd和vsftpd
二、 LVS上配置
开启路由转发功能:
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
检查:
sysctl -p
net.ipv4.ip_forward = 1
修改配置:vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {
qingean@163.com
}
notification_email_from admin@test.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_MASTER
}

vrrp_instance VI_1 {
state MASTER
interface ens4
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
193.168.141.30 #VIP
}
}

vrrp_instance LAN_GATEWAY {
state MASTER
interface ens3
virtual_router_id 62
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.102.165 #NVIP
}
}

virtual_server 193.168.141.30 80{
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 30#一个用户多少时间内只访问一个RS
protocol TCP
real_server 192.168.102.163 80 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.102.164 80 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}

virtual_server 193.168.141.30 21{
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 30
protocol TCP
real_server 192.168.102.163 21 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 21
}
}
real_server 192.168.102.164 21 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 21
}
}
}
Firewall配置:
firewall-cmd --permanent --zone=internal --add-interface=ens3
firewall-cmd --permanent --zone=public --add-interface=ens4
查看网卡:firewall-cmd --get-active-zones
internal
interfaces: ens3
public
interfaces: ens4
firewall-cmd --permanent --zone=public --add-masquerade
查看:firewall-cmd --zone=public --query-masquerade
yes
firewall-cmd --zone=internal --query-masquerade
no
firewall-cmd --direct --permanent --add-rule ipv4 filter FORWARD 0 \
-i ens3 -o ens4 -j ACCEPT
firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept' --permanent
firewall-cmd --reload
Firewall开启端口:
firewall-cmd --zone=public --add-port=65400-65420/tcp
firewall-cmd --zone=public --add-port=21/tcp
firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --reload
开启keepalived服务:
systemctl start keepalived
三、 RS上配置
为所有RS添加网关为192.168.102.165:
vim /etc/sysconfig/network-scripts/ifcfg-ens3
GATEWAY=192.168.102.165
重启:systemctl restart network
http写入测试页:
RS1:echo “RS1″ > /var/www/html/index.html
RS2:echo “RS2″ > /var/www/html/index.html
ftp配置:vim /etc/vsftpd/vsftpd.conf
pasv_enable=YES
pasv_address=193.168.141.30
pasv_min_port=65400
pasv_max_port=65420
listen_port=21
listen=YES
listen_ipv6=NO
Firewall开启端口:
firewall-cmd --zone=public --add-port=65400-65420/tcp
firewall-cmd --zone=public --add-port=21/tcp
firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --reload
开启vsftpd和httpd服务:
systemctl start httpd
systemctl start vsftpd
四、 测试
客户端防火墙配置:(不配不能用ftp主动模式)
firewall-cmd --add-source=193.168.141.30/32 –permanent
firewall-cmd --add-port=1024-65535/tcp --permanent
http测试:(keepalived配置去除http的persistence_timeout项,则无间隔轮番显示)
浏览器访问http://193.168.141.30#刷新会轮番显示RS1或RS2,轮番显示的时间间隔由persistence_timeout和LVS的超时共同决定。
ftp测试:
ftp 193.168.141.30
Connected to 193.168.141.30.
220 (vsFTPd 3.0.2)
Name (193.168.141.30:gean): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> passive
Passive mode on.
ftp> ls
227 Entering Passive Mode (193,168,141,30,255,140).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 Mar 23 2017 pub
226 Directory send OK.
ipvsadm –Lcn查看LVS收到请求的情况。
注:搭建共享存储nfs勿忘:setsebool -P httpd_use_nfs=1 ftpd_use_nfs=1

keepalived(nat)+ftp+http的更多相关文章

  1. linux 做gw(nat)详细配置

                          linux 做企业网关gw(nat)详细配置   最近因为公司的路由器老化导致上网时断时续,上半小时网就断一次网,为此我头疼不已,本着为公司节约成本的宗旨, ...

  2. RHEL6.5----LVS(NAT)

    主机名 IP  所需软件  master 192.168.30.130(Nat) 192.168.17.130(VMnet4) ipvsadm  node-1 192.168.17.131  http ...

  3. 【记】VM VirtualBox 网络地址转换(NAT)使用详解

    1. 查看虚拟机Centos6的ip 但是这个IP地址并不能直接连接,因为本地VBox网络连接方式采用的是“网络地址转换(NAT)”(如上上图所示),也就是说 10.0.2.15 这地址是转换的. 2 ...

  4. 计算机网络-应用层(2)FTP协议

    文件传输协议(FTP,File Transfer Protocol)是Internet上使用最广泛的文件传送协议.FTP提供交互式的访问,允许客户指明文件的类型与格式,并允许文件具有存取权限.它屏蔽了 ...

  5. virtualbox 网络地址转换(NAT)

    网络地址转换 虚拟机可以访问主机 通过主机请求外网 但是主机不能请求虚拟机 所以要配置端口转发才行 host-only模式下 不同网段的不同虚拟机也可以互相ping通  比如 192.168.33.1 ...

  6. 网络地址转换(NAT)和默认路由

    我们要连接外网时,外网的网段很多很多,我们该如何愉快地连接外网?下面我们通过Cisco packet模拟环境,并了解NAT和默认路由的使用: NAT(Network Address Translati ...

  7. 初入网络系列笔记(5)FTP协议

    一.借鉴说明,本博文借鉴以下博文 1.锤子,FTP协议,http://www.cnblogs.com/loadrunner/archive/2008/01/09/1032264.html 2.suna ...

  8. 学习Keepalived(三)

    1.1Keepalived高可用软件 Keepalived起初是专为LVS设计的,专门用来监控LVS集群系统中各个服务节点的状态,后来又加入了VRRP的功能,因此除了配合LVS服务外,也可以作为其他服 ...

  9. 学习Keepalived(二)

    一.keepalived简介 keepalived是集群管理中保证集群高可用的一个服务软件,其功能类似于,用来防止单点故障. 二.vrrp协议2.1 vrrp协议简介 在现实的网络环境中,两台需要通信 ...

随机推荐

  1. C#中的Explicit和Implicit

    今天在Review一个老项目的时候,看到一段奇怪的代码. if (dto.Payment == null) continue; var entity = entries.FirstOrDefault( ...

  2. String内存溢出异常(错误)可能的原因及解决方式

    摘要:本Blog主要为了阐述java.lang.OutOfMemoryError:PermGenspace可能产生的原因及解决方式. 当中PermGen space是Permanent Generat ...

  3. java.lang.IllegalStateException: attempt to re-open an already-closed object

    attempt to re-open an already-closed object 字面理解,试图再次打开已经关闭的对象.这是我在操作sqlited的时候出现的错误, 我在一个activity里面 ...

  4. mvc 中Range中max和min值晚绑定

    对于Attribute : Range(min,max)的min和max必须在用的时候给,但是需求有时须要把这两个值存db.动态取出的.这时就须要razor帮忙了: @Html.TextBoxFor( ...

  5. JAVA随笔篇一(Timer源代码分析和scheduleAtFixedRate的使用)

    写完了基础篇,想了非常久要不要去写进阶篇.去写JSP等等的用法.最后决定先不去写.由于自己并非JAVA方面的大牛.眼下也在边做边学,所以决定先将自己不懂的拿出来学并记下来. Timer是Java自带的 ...

  6. ASP.MVC当URL跳转时候参数的安全性

    一个页面跳转到另外一个页面直接将参数写在URL上面并不安全比如 http://XXXXXXXXXXX/meeting/shakeGroup?id=5381&uid=o0En_sj1J0bFgI ...

  7. Spring Boot-------热部署

    热部署 热部署重要的是:添加一个jar包 第一步:在我们项目中的pom.xml文件中添加spring-boot-devtools这个jar包,Maven会帮我们自动下载的 <dependency ...

  8. Elasticsearch过滤器——filter

    Elasticsearch中的所有的查询都会触发相关度得分的计算.对于那些我们不需要相关度得分的场景下,Elasticsearch以过滤器的形式提供了另一种查询功能.过滤器在概念上类似于查询,但是它们 ...

  9. HTML: width,height

    在进行前端页面开发时,width(width,offsetWidth,scrollWidth,clientWidth)height(height,offsetHeight,scrollHeight,c ...

  10. Mac shell笔记

    用来自动执行一些前端发布的操作. 脚本: # webReleasePath用来发布的目录,webRevisionPath是开发的目录 webReleasePath='/Users/lufeng/Doc ...