1. 程式人生 > >基於lvs的FTP負載均衡部署方案(PASV)

基於lvs的FTP負載均衡部署方案(PASV)

啟動iptables

在redirector的主機上,啟動iptables,把原訪問策略新增進去,同時新增ftp的分發訪問策略(預設的redirector的主機並不需要iptables)

1. 確認iptables模組已經編譯並載入。

# modprobe ip_tables

2. 新增防火牆的規則,並儲存

# iptables -A INPUT -p tcp -m state –state NEW –dport 22 -j ACCEPT

# iptables -A INPUT -p icmp -m icmp –icmp-type any -j ACCEPT

# iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

# iptables -I INPUT 2 -p tcp -m state –state NEW -m tcp –dport 21 -j ACCEPT

# iptables -I INPUT 3 -p tcp -m state –state NEW -m tcp –dport 50001:50501 -j ACCEPT

# iptables -A INPUT -j REJECT –reject-with icmp-host-prohibited

# iptables -t mangle -A PREROUTING -p tcp -d 172.16.129.39/32 –dport 21 -j MARK –set-mark 21

# iptables -t mangle -A PREROUTING -p tcp -d 172.16.129.39/32 –dport 50001:50501 -j MARK –set-mark 21

# service iptables save

3. 啟動防火牆

# service iptables start

配置FTP的虛擬IP和分發策略

1. 在redirector的主機上,新增FTP的虛擬IP(172.16.129.39),重新啟動該VIP

# vi /etc/init.d/lvsstart.sh 新增:

VIP3=172.16.129.39

/sbin/ifconfig eth0:2 $VIP3 broadcast $VIP3 netmask 255.255.255.255 up

/sbin/route add -host $VIP3 dev eth0:3

# lvsstart.sh stop

# lvsstart.sh start

2. 更新ldirectord.cf ,新增FWM=21基於sh的分發策略

# vi /etc/ha.d/ldirectord.cf 新增

virtual=21

real=172.16.129.32 gate

real=172.16.129.31 gate

scheduler=sh

protocol=fwm

checktype=connect

checkport=21

ldirectord將自動更新分發策略。

配置FTP伺服器以支援分發策略

配置伺服器的lo:0地址新增FTP的虛擬IP(172.16.129.39)

# vi /etc/init.d/lvsstart.sh

VIP=172.16. 129.39

/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

/sbin/route add -host $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

# chmod +x /etc/init.d/lvsstart.sh

# ./lvsstart.sh
更新vsftpd的配置使分發生效

# vi /etc/vsftpd/vsftpd.conf

pasv_address=172.16.129.39

pasv_min_port=50001
pasv_max_port=50501
請自己保證2臺ftp伺服器的資料同步