CentOS下使用lvs实现ftp的负载均衡
操作系统:CentOS6.5_x64
问题描述
使用lvs实现ftp的负载均衡
为了使模型足够简单,这里只实现了loadblance,HA并未实现,可以借助keepalived实现。
具体实现
hostA : 192.168.1.21
hostB : 192.168.1.22
hostC : 192.168.1.23
虚拟ip地址: 192.168.1.20
hostA为负载均衡器
hostB和hostC为ftp服务器
转发模式:DR
调度算法:rr
hostA配置
安装ipvsadm:
yum install ipvsadm -y
从源码安装:
yum install -y gcc gcc-c++ make pcre pcre-devel kernel-devel openssl-devel yum install libnl* popt* wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz tar zxvf ipvsadm-1.26.tar.gz cd ipvsadm-1.26 make && make install
开启ip转发功能:
vim /etc/sysctl.conf net.ipv4.ip_forward = 1 sysctl -p
关闭防火墙:
/etc/init.d/iptables stop
配置ipvs(start.sh) :
#! /bin/sh # DR Mode ipvsadm -C ipvsadm -A -t 192.168.1.20:21 -s rr -p ipvsadm -a -t 192.168.1.20:21 -r 192.168.1.22:21 -g ipvsadm -a -t 192.168.1.20:21 -r 192.168.1.23:21 -g ipvsadm save ipvsadm -ln ifconfig eth0:0 192.168.1.20 netmask 255.255.255.0
hostB配置
配置虚拟ip:
[root@host22 test]# cat /etc/init.d/realserver.sh #!/bin/bash SNS_VIP=192.168.1.20 . /etc/rc.d/init.d/functions case "$1" in start) ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP /sbin/route add -host $SNS_VIP dev lo:0 echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce sysctl -p >/dev/null 2>&1 echo "RealServer Start OK" ;; stop) ifconfig lo:0 down route del $SNS_VIP >/dev/null 2>&1 echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce echo "RealServer Stoped" ;; *) echo "Usage: $0 {start|stop}" exit 1 esac exit 0 [root@host22 test]# sh /etc/init.d/realserver.sh start SIOCADDRT: File exists RealServer Start OK
开启ftp服务
安装vsftpd :
yum install vsftpd
修改配置:
为了方便开启匿名用户操作ftp的各种权限。
chmod a+w /var/ftp/pub/ # 开启文件夹写权限 vim /etc/vsftpd/vsftpd.conf anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES # 开启匿名用户删除功能
配置selinux:
getsebool -a | grep ftp setsebool -P allow_ftpd_anon_write 1 setsebool -P allow_ftpd_full_access 1
启动ftp:
/etc/init.d/vsftpd start
配置开机启动:
chkconfig vsftpd on
关闭防火墙:
/etc/init.d/iptables stop chkconfig iptables off
hostC配置
配置同hostB
讨论
这里只是用lvs实现了ftp负载均衡的模型,其它具体问题请参考lvs相关文档。
这里附上测试脚本,ftp写文件脚本:
#! /usr/bin/env python #-*- coding:utf-8 -*- import ftplib,os,time ftp = ftplib.FTP("192.168.1.20") ftp.login() ftp.cwd("/pub") i = 0 while True : filename = "ftptest1_%d.txt" % i print filename i += 1 with open(filename,"w") as fout : fout.write(str(time.time())) myfile = open(filename, 'r') try : ftp.storlines('STOR ' + filename, myfile) except : ftp.login() ftp.cwd("/pub") myfile.close() os.remove(filename) time.sleep(10)
好,就这些了,希望对你有帮助。
本文github地址:
https://github.com/mike-zhang/mikeBlogEssays/blob/master/2017/20170623_使用lvs实现ftp的负载均衡.rst
欢迎补充
- E-Mail : Mike_Zhang@live.com
- github :https://github.com/mike-zhang

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
centos下修改yum源的优先级
ps:当既有本地yum源又有163源的时候,我们在装软件包的时候当然希望先用本地的yum源去安装,本地找不到可用的包时再使用163源去安装软件,这里就涉及到了优先级的问题,yum提供的插件yum-plugin-priorities.noarch可以解决这个问题 1.查看系统是否安装了优先级的插件 [root@kangvcar ~]# rpm -qa | grep yum-plugin- yum-plugin-fastestmirror-1.1.31-34.el7.noarch //这里看到没有安装yum-plugin-priorities.noarch这个插件 [root@kangvcar ~]# yum search yum-plugin-priorities //用search查看是否有此插件可用 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * ...
- 下一篇
CentOS6.5配置网络说明
1 网卡说明 1)两块网卡的说明: 第一块网卡为配置外网: eth0 第二块网卡为配置内网: eth1(没有外网的机器也要将内网配置在第二块网卡上) 2 网卡默认配置 1)安装完成后默认配置: CentOS 6.5默认安装好之后是没有自动开启网络连接的! 2) 默认IP图: 3) 默认网卡1配置文件。 文件路径: /etc/sysconfig/network-scripts/ifcfg-eth0 # vi/etc/sysconfig/network-scripts/ifcfg-eth0 使用vi打开之后如下图。 3 网卡自动获取IP配置 操作步骤: 1) # vi /etc/sysconfig/network-scripts/ifcfg-eth0 2)修改ONBOOT=yes即可。 3)# service network restart #重启网卡。 4 网卡配置静态IP 1)编辑配置文件,添加修改以下内容 # vi /etc/sysconfig/network-scripts/ifcfg-eth0 BOOTPROTO=static #启用静态IP地址 ONBOO...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- CentOS8安装Docker,最新的服务器搭配容器使用
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- Windows10,CentOS7,CentOS8安装Nodejs环境
- CentOS7设置SWAP分区,小内存服务器的救世主
- MySQL8.0.19开启GTID主从同步CentOS8
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装