Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

3.4. 複数ポートサービスと LVS

LVS routers under any topology require extra configuration when creating multi-port LVS services. Multi-port services can be created artificially by using firewall marks to bundle together different, but related protocols, such as HTTP (port 80) and HTTPS (port 443), or when LVS is used with true multi-port protocols, such as FTP. In either case, the LVS router uses firewall marks to recognize that packets destined for different ports, but bearing the same firewall mark, should be handled identically. Also, when combined with persistence, firewall marks ensure connections from the client machine are routed to the same host, as long as the connections occur within the length of time specified by the persistence parameter. For more on assigning persistence to a virtual server, see 仮想サーバー サブセクション」.
残念なことに、実サーバー上でロードのバランスを取るために使用するメカニズム — IPVS — は、パケットに割り当てたファイアウォールマークは認識できますが、自身でファイアウォールマークを割り当てる ことが出来ません。ファイアウォールマークを割り当てる 作業はネットワーク パケットフィルタ、iptables によって Piranha Configuration Tool の外部で実行される必要があります。

3.4.1. ファイアウォールマークの割り当て

ファイアウォールマークを、特定ポートに向けたパケットに割り当てるには、管理者は iptables を使用する必要があります。
This section illustrates how to bundle HTTP and HTTPS as an example; however, FTP is another commonly clustered multi-port protocol. If an LVS is used for FTP services, refer to 「FTP の設定」 for configuration details.
ファイアウォールマークの使用で記憶すべき基本ルールは、Piranha Configuration Tool で ファイアウォールを使用している全てのプロトコルに、ネットワークパケットにマークを割り当てる為の 同量の iptables ルールが存在すべきだと言うことです。
ネットワークパケットフィルタルールを作成する前に、既に他のルールが存在しないことを 確認してください。これを行うには、シェルプロンプトを開いて、root でログインして 以下を入力します:
/sbin/service iptables status
iptables が稼働していない場合、すぐにプロンプトが 再出現します。
iptables がアクティブな場合、ルールセットを表示します。 ルールが存在するならば、以下のコマンドを入力します:
/sbin/service iptables stop
既存のルールが重要な場合、/etc/sysconfig/iptables の内容を確認して、 保存する価値のあるルールを安全な場所にコピーしてから継続します。
同じファイアウォールマーク 80 を、 ポート80 と 443 上の浮動 IP アドレス n.n.n.n へ向けられたトラフィックへ割り当てるルールを以下に示します。
/sbin/modprobe ip_tables
/sbin/iptables -t mangle -A PREROUTING -p tcp -d n.n.n.n/32 --dport 80 -j MARK --set-mark 80
/sbin/iptables -t mangle-A PREROUTING -p tcp -d n.n.n.n/32 --dport 443 -j MARK --set-mark 80
For instructions on assigning the VIP to the public network interface, see 仮想サーバー サブセクション」. Also note that you must log in as root and load the module for iptables before issuing rules for the first time.
上述の iptables コマンドでは、n.n.n.n の部分は使用中の HTTP と HTTPS 仮想サーバーの浮動 IP で入れ替える必要が あります。これらのコマンドは、該当するポート上の VIP に向けられた全てのトラフィックを ファイアウォールマーク 80 に割り当てることと同様の効果を持ちます。これが結果として、 IPVS で認識され、適切に転送されます。

警告

The commands above will take effect immediately, but do not persist through a reboot of the system. To ensure network packet filter settings are restored upon reboot, refer to 「ネットワークパケットフィルター設定の保存」