Use lvs to achieve ftp load balancing and lvsftp Load Balancing

Source: Internet
Author: User
Tags ftp file

Use lvs to achieve ftp load balancing and lvsftp Load Balancing

Operating System: CentOS6.5 _ x64

Problem description

Use lvs to achieve ftp Load Balancing

To make the model simple enough, only loadblance is implemented here, and HA is not implemented. You can implement it using keepalived.

Implementation

HostA: 192.168.1.21

HostB: 192.168.1.22

HostC: 192.168.1.23

Virtual IP Address: 192.168.1.20

HostA is the Server Load balancer

HostB and hostC are ftp servers

Forwarding mode: DR

Scheduling Algorithm: rr

HostA Configuration

Install ipvsadm:

yum install ipvsadm -y

Install from source code:

yum install -y gcc gcc-c++ make pcre pcre-devel kernel-devel openssl-develyum install libnl* popt*wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gztar zxvf ipvsadm-1.26.tar.gzcd ipvsadm-1.26make && make install

Enable ip forwarding:

vim /etc/sysctl.confnet.ipv4.ip_forward = 1sysctl -p

Disable Firewall:

/etc/init.d/iptables stop

Configure ipvs (start. sh ):

#! /bin/sh# DR Modeipvsadm -Cipvsadm -A -t 192.168.1.20:21 -s rr -pipvsadm -a -t 192.168.1.20:21 -r 192.168.1.22:21 -gipvsadm -a -t 192.168.1.20:21 -r 192.168.1.23:21 -gipvsadm saveipvsadm -lnifconfig eth0:0 192.168.1.20 netmask 255.255.255.0
HostB Configuration

Configure the virtual ip Address:
[root@host22 test]# cat /etc/init.d/realserver.sh#!/bin/bashSNS_VIP=192.168.1.20. /etc/rc.d/init.d/functionscase "$1" instart) 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 1esacexit 0[root@host22 test]# sh /etc/init.d/realserver.sh startSIOCADDRT: File existsRealServer Start OK
Enable ftp service

Install vsftpd:

yum install vsftpd

Modify Configuration:

To enable Anonymous users to perform ftp operations conveniently.

Chmod a + w/var/ftp/pub/# enable the folder write permission vim/etc/vsftpd. confanon_upload_enable = Enabled = YESanon_other_write_enable = YES # enable the anonymous user deletion function

Configure selinux:

getsebool -a | grep ftpsetsebool -P allow_ftpd_anon_write 1setsebool -P allow_ftpd_full_access 1

Start ftp:

/etc/init.d/vsftpd start

Configure boot start:

chkconfig vsftpd on

Disable Firewall:

/etc/init.d/iptables stopchkconfig iptables off
HostC Configuration
Configure the same as hostB

Discussion

Here we only use lvs to implement the ftp Server Load balancer model. For more information, see lvs documentation.

The test script and ftp file writing script are attached here:

#! /usr/bin/env python#-*- coding:utf-8 -*-import ftplib,os,timeftp = ftplib.FTP("192.168.1.20")ftp.login()ftp.cwd("/pub")i = 0while 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)

Okay, that's all. I hope it will help you.

Github address:

Bytes

Please add

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.