金曜日, 4月 24, 2009

DHCP サーバのクラスタ化

[概要]
LinuxのDHCPサーバをクラスタリングする方法を説明しています。
[詳細]
DHCPで運用しているネットワークにおいて、サーバが停止すると新たに接続されたコンピュータに
IPアドレスが払い出しされなくなるなど、ネットワーク運用に大きな影響を及ぼします。
Linuxの各ディストリビューションで提供されているDHCPDには、
2台のDHCPサーバを二重化する機能が備わっており、これを利用してDHCPサーバの障害対策を行います。
二重化に対応した"/etc/dhcpd.conf"の設定方法を説明します。
  1. DHCPDのインストール
    RHEL系の場合には、dhcpをインストールします。
    Debian系の場合には、dhcpd3-serverをインストールします。

  2. 共通項目用設定ファイルの準備
    二重化するサーバで共通する設定項目を記述したファイルをプライマリ・セカンダリ双方に作成します。
    ここではファイル名を"/etc/dhcpd.master"とします。
    option domain-name "foo.bar.com";
    option domain-name-servers 192.168.1.3, 192.168.1.5, 192.168.1.2;
    default-lease-time 21600;
    max-lease-time 43200;
    subnet 192.168.1.0 netmask 255.255.255.0 {
    pool {
    failover peer "dhcp";
    range 192.168.1.200 192.168.1.230;
    deny dynamic bootp clients;
    }
    option routers 192.168.1.1;
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.1.255;
    option ntp-servers 192.168.1.3,192.168.1.5;
    }
  3. プライマリサイト用設定ファイルの作成
    プライマリ・サーバのdhcpdの設定ファイルを作成します。
    (RHEL系:/etc/dhcpd.conf, debian系:/etc/dhcp3/dhcpd.conf)
    ddns-update-style none;
    one-lease-per-client true;
    authoritative;
    failover peer "dhcp" {
    primary;
    address 192.168.1.3; # プライマリ・サーバ自身のIPアドレス
    port 519;
    peer address 192.168.1.5; # セカンダリ・サーバ自身のIPアドレス
    peer port 520;
    max-response-delay 60;
    max-unacked-updates 10;
    mclt 600;
    split 128;
    load balance max seconds 3;
    }
    include "/etc/dhcpd.master";
  4. セカンダリ用設定ファイルの作成
    同様に、セカンダリ・サーバのdhcpdの設定ファイルを作成します。
    ddns-update-style none;
    one-lease-per-client true;
    authoritative;
    failover peer "dhcp" {
    secondary;
    address 192.168.1.5; # セカンダリ・サーバ自身のIPアドレス
    port 520;
    peer address 192.168.1.3; # プライマリ・サーバのIPアドレス
    peer port 519;
    max-response-delay 60;
    max-unacked-updates 10;
    }
  5. 動作確認
    dhcpdをデバッグモードで起動します。
    [起動確認]
    <プライマリ・サーバの起動(RHEL系の例)>
    [root@linux01 ~]# /usr/sbin/dhcpd -d
    Internet Systems Consortium DHCP Server V3.0.5-RedHat
    Copyright 2004-2006 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/
    Wrote 31 leases to leases file.
    Listening on LPF/eth0/00:21:85:9c:5c:3b/192.168.1/24
    Sending on LPF/eth0/00:21:85:9c:5c:3b/192.168.1/24
    Sending on Socket/fallback/fallback-net
    failover peer dhcp: I move from communications-interrupted to startup
    failover peer dhcp: I move from startup to communications-interrupted
    ↑1台ずつ起動なので、縮退状態で起動。
    failover peer dhcp: peer moves from normal to normal
    failover peer dhcp: I move from communications-interrupted to normal
    ↑セカンダリが起動。クラスタ化。
    pool 9ba8320 192.168.1/24 total 31 free 17 backup 13 lts -2
    <セカンダリ・サーバの起動>
    linux02:~# /usr/sbin/dhcpd3 -d
    Internet Systems Consortium DHCP Server V3.0.4
    Copyright 2004-2006 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/
    Wrote 31 leases to leases file.
    Listening on LPF/eth0/00:a0:b0:75:e2:6e/192.168.1/24
    Sending on LPF/eth0/00:a0:b0:75:e2:6e/192.168.1/24
    Sending on Socket/fallback/fallback-net
    failover peer dhcp: I move from normal to startup
    failover peer dhcp: peer moves from normal to communications-interrupted
    failover peer dhcp: I move from startup to normal
    failover peer dhcp: peer moves from communications-interrupted to normal
    ↑クラスタ化
    pool 1141e0 192.168.1/24 total 31 free 17 backup 13 lts 2
    プライマリとセカンダリで、赤い部分の"total", "free", "backup"が同じであることを確認してください。
    [縮退(フェイルオーバー)テスト]
    まず、セカンダリのdhcpdを停止してください。
    <プライマリ・サーバの出力>
    peer dhcp: disconnected
    ↑セカンダリを停止。
    failover peer dhcp: I move from normal to communications-interrupted
    ↑縮退
    [復帰(フェイルバック)テスト]
    <セカンダリ・サーバの起動>
    linux02:~# /usr/sbin/dhcpd3 -d
    Internet Systems Consortium DHCP Server V3.0.4
    Copyright 2004-2006 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/
    Wrote 31 leases to leases file.
    Listening on LPF/eth0/00:a0:b0:75:e2:6e/192.168.1/24
    Sending on LPF/eth0/00:a0:b0:75:e2:6e/192.168.1/24
    Sending on Socket/fallback/fallback-net
    failover peer dhcp: I move from normal to startup
    failover peer dhcp: peer moves from normal to communications-interrupted
    failover peer dhcp: I move from startup to normal
    failover peer dhcp: peer moves from communications-interrupted to normal
    ↑クラスタ化完了
    pool 1141e0 192.168.1/24 total 31 free 17 backup 13 lts 2
    <プライマリ・サーバの出力>
    failover peer dhcp: peer moves from normal to normal
    failover peer dhcp: I move from communications-interrupted to normal
    ↑クラスタ化
    pool 9ba8320 192.168.1/24 total 31 free 17 backup 13 lts -2
    起動のときと同様に、プライマリとセカンダリで、赤い部分の"total", "free", "backup"が同じであることを確認してください。
  6. DHCPDのリスタート
    デバックモードを終了して、プライマリ、セカンダリ両方のサーバのdhcpdのスタートを行います。
    [RHEL系の場合]
    [root@linux01 ~]# /etc/init.d/dhcpd start
    [Debian系の場合]
    linux02:~# /etc/init.d/dhcp3-server start