CentOS7+keepalived+FTP

CentOS7でFTPkeepalivedで冗長する構成で時間を食ったのでメモ


FTPはパッシブで60001〜60100を使う設定
xxx.xxx.xxx.xxxにグローバルIP(仮想IP)が入ります。
firewallのゾーンはpublicにしています。


ポートを空けます。


firewall-cmd --permanent --add-service=ftp
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT_direct 0 -d xxx.xxx.xxx.xxx -p tcp -m tcp --dport 60001:60100 -j ACCEPT
開けたポートをマーキングします。

firewall-cmd --permanent --direct --add-rule ipv4 mangle PREROUTING 0 -d xxx.xxx.xxx.xxx -p tcp -m tcp --dport 20:21 -j MARK --set-mark 0x21
firewall-cmd --permanent --direct --add-rule ipv4 mangle PREROUTING 1 -d xxx.xxx.xxx.xxx -p tcp -m tcp --dport 60001:60100 -j MARK --set-mark 0x21
keepalived.confを設定します。

vrrp_instance VI_1 {
〜途中省略〜
virtual_ipaddress {
xxx.xxx.xxx.xxx
}
}
virtual_server xxx.xxx.xxx.xxx fwmark 21 {
delay_loop 3
lb_algo lblcr
lb_kind DR
persistence_timeout 600
protocol TCP

real_server 192.168.1.1 {
weight 1
MISC_CHECK {
misc_path "echo -en 'SYST\r\nQUIT\r\n' | nc -w 5 -n 192.168.1.1 21 | egrep '215 Windows_NT'"
misc_timeout 5
}
}
}

確認(必要な部分だけ記載)

# iptables -L -n -t mangle
Chain PREROUTING_direct (1 references)
target prot opt source destination
MARK tcp -- 0.0.0.0/0 xxx.xxx.xxx.xxx tcp dpts:20:21 MARK set 0x21
MARK tcp -- 0.0.0.0/0 xxx.xxx.xxx.xxx tcp dpts:60001:60100 MARK set 0x21

# iptables -L -n -t filter
Chain INPUT_direct (1 references)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 xxx.xxx.xxx.xxx tcp dpts:60001:60100

Chain IN_public_allow (1 references)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 ctstate NEW

※パッシブ用のポートはstate NEWを付けるとFINが落ちてしまう為ファイル転送に失敗します。
 add-serviceではstate NEWを付けない方法が無さそうなのでダイレクト登録しています。