1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

keepaliveでセグメントを超える時の設定ハマりどころ

Last updated at Posted at 2017-08-02

初心者がkeepaliveを設定していたらドハマりしたのでメモ。

環境

  • CentOS6.9
  • keepalived.x86_64 1.2.13-5.el6_6

iptables

iptables -A FORWARD -j REJECT を打ち消す
セグメントを超えた負荷分散の場合、パケットをフォワードする必要がある。
その際、CentOS6のデフォルト設定のiptablesではWebサーバからの帰りパケットがリジェクトされてしまう。

iptables -A FORWARD -j ACCEPTはスマートじゃないので、必要な分だけ許可。
以下は_eth1(外)側のネットワークからeth2(内)側へ_http通信する場合の記述

-A FORWARD -i eth1 -o eth2 -p tcp --sport 80 -j ACCEPT  # <- 追記
-A FORWARD -j REJECT --reject-with icmp-host-prohibited # <- 元からある

net.ipv4.ip_forward=1を設定するのは様々なサイトで情報があったが、この設定は無くてハマった。
そんなこと記載する価値もない常識だという可能性もあるが…

設定ファイル

括弧の前には空白必須
本当は必須じゃないかもしれないけれど、空白置いといて損はない。
なおセグメントには一切関係ない。

NG

urlの後ろに空白を入れず括弧をした場合、何故か一番目のreal_serverだけ反映される。 何故だ…

virtual_server 172.16.0.5 80 {
    lb_algo wlc
    lb_kind NAT

    real_server 192.168.254.132 80 {
        HTTP_GET {
            url{
                path /
                status_code 200
            }
        }
    }
    real_server 192.168.254.133 80 {
        HTTP_GET {
            url{
                path /
                status_code 200
            }
        }
    }
    real_server 192.168.254.134 80 {
        HTTP_GET {
            url{
                path /
                status_code 200
            }
        }
    }
}
---------------------------------------------------------------------
[vagrant@LVS1 ~]$ sudo ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  172.16.0.5:80 wlc
  -> 192.168.254.132:80           Masq    1      0          0

OK

virtual_server 172.16.0.5 80 {
    lb_algo wlc
    lb_kind NAT

    real_server 192.168.254.132 80 {
        HTTP_GET {
            url {
                path /
                status_code 200
            }
        }
    }
    real_server 192.168.254.133 80 {
        HTTP_GET {
            url {
                path /
                status_code 200
            }
        }
    }
    real_server 192.168.254.134 80 {
        HTTP_GET {
            url {
                path /
                status_code 200
            }
        }
    }
}
---------------------------------------------------------------------
[vagrant@LVS1 ~]$ sudo ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
UDP  172.16.0.5:80 wlc
  -> 192.168.254.132:80           Masq    1      0          0
  -> 192.168.254.133:80           Masq    1      0          0
  -> 192.168.254.134:80           Masq    1      0          0
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?