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?

KEA-DHCP+MariadbのHA構築方法

Posted at

はじめに

本記事では、UbuntuにKeaインストール、ファイル構成を説明します。Keaについてはこの記事では説明しません。

手順

Keaインストール

apt-get install -y isc-kea-*
apt-get update

Keaコンフィグ設定(/etc/kea/kea-dhcp4.conf)

{
"Dhcp4": {
    "interfaces-config": {
        // interface name (e.g. "eth0" or specific IPv4 address on that
        // interface name (e.g. "eth0/192.0.2.1").
        "interfaces": [ "eth0" ] //インターフェイスで変更

    },

    "control-socket": {
        "socket-type": "unix",
        "socket-name": "/tmp/kea4-ctrl-socket"
    },

    "lease-database": {
        "type": "memfile",
        "lfc-interval": 3600
    },
    
    //リースをデータベースで管理する用
    //  "lease-database": {
    //  "type": "mysql",
    //  "name": "kea",
    //  "user": "kea",
    //  "password": "database_password",
    //  "host": "192.168.0.0",
    //  "port": 3306
    //  },

    //  "hosts-database": {
    //  "type": "mysql",
    //  "host": "localhost",
    //  "name": "kea",
    //  "user": "kea",
    //  "password": "password"
    //  },
    
    "expired-leases-processing": {
        "reclaim-timer-wait-time": 10,
        "flush-reclaimed-timer-wait-time": 25,
        "hold-reclaimed-time": 3600,
        "max-reclaim-leases": 100,
        "max-reclaim-time": 250,
        "unwarned-reclaim-cycles": 5
    },

    "renew-timer": 900,
    "rebind-timer": 1800,
    "valid-lifetime": 3600,

    "option-data": [
        {
            "name": "domain-name-servers",
            "data": "8.8.8.8" //DSNアドレスに変更
        },

    ],

    //ホットスタンバイのフック
    "hooks-libraries": [
        {    //hookが入っているLinkに変更
           "library": "/usr/lib/x86_64-linux-gnu/kea/hooks/libdhcp_lease_cmds.so", 
           "parameters": {}
       },
       {
           "library": "/usr/lib/x86_64-linux-gnu/kea/hooks/libdhcp_ha.so",
           "parameters":  {
                "high-availability": [ { //サブのサーバー情報など
                        "this-server-name": "kea_1", //このサーバーの名前
                        "mode": "hot-standby", //HAやL
                        "hearbeat-delay": 10000,
                        "max-response-delay": 10000,
                        "max-ack-delay": 5000,
                        "max-unacked-clients": 5,
                        "peers": [
                        {
                                "name": "kea_1",
                                "url": "http://192.168.0.0:8080/", //primary用のアドレス
                                "role": "primary",
                                "auto-failover": true
                        },
                        {
                                "name": "kea_2",
                                "url": "http://192.168.0.0:8080/", //secondar用のアドレス
                                "role": "standby",
                                "auto-failover": true
                        }
                ]
                }]
          }
       }
    ],

    "subnet4": [
        {
            "id": 1,
            "subnet": "192.168.0.0/0",  //サブネット変更
            "pools": [ { "pool": "192.168.0.50 - 192.168.0.100" } ], //DHCPプールに変更
        "option-data": [
        {
                "name": "routers",
                "data": "192.168.0.1" //ゲートウェイに変更
        }
        ]
        },
        //DHCPプールを複数にする用
        //{
        //    "id": 2,
        //    "subnet": "192.168.200.0/0",
        //    "pools": [ { "pool": "192.168.200.100 - 192.168.200.150" } ],
        //"option-data": [ {
        //        "name": "routers",
        //        "data": "192.168.200.1"
        //                } ]
        //},

    ],

    "loggers": [
    {
        "name": "kea-dhcp4",
        "output-options": [
            {
                "output": "/var/log/kea/kea-dhcp4.log", //ログファイルの場所に変更
                "maxver": 8,
                "maxsize": 204800,
                "flush": true
            }
        ],
        "severity": "INFO", //デバッグの場合"DEBUG"に変更

        // If DEBUG level is specified, this value is used. 0 is least verbose,
        // 99 is most verbose. Be cautious, Kea can generate lots and lots
        // of logs if told to do so.
        "debuglevel": 0 //デバッグは"99"にしてください
    }
  ]
}
}

DHCP4再起動

sudo systemctl enable isc-kea-dhcp4-server
sudo systemctl restart isc-kea-dhcp4-server

mariadbインストール

sudo apt-get install -y mariadb-server
sudo systemctl enable mariadb-server

mariadbの初期設定

mysql_secure_installation

DHCP4用のデータベース作成

mysql -u root -p

CREATE DATABASE kea;
GRANT ALL ON kea.* TO keauser@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
QUIT;

kea-admin lease-init mysql -u kea -p password -n kea

Keaのコンフィグに書き込む

"lease-database": {
    "type": "mysql",
    "name": "kea",
    "user": "kea",
    "password": "password",
    "host": "192.168.0.0",
    "port": 3306
},

"hosts-database": {
"type": "mysql",
"host": "localhost",
"name": "kea",
"user": "kea",
"password": "password"
},

kea-dhcp4再起動

sudo systemctl restart isc-kea-dhcp4-server

エラーが発生した場合

エラー文があるか確認

sudo systemctl status mariadb

プライマリーセカンダリーが通信出来てるか確認

sudo journalctl -xe

データベースのリース確認用

公式ページ参照:https://ftp.iij.ad.jp/pub/network/isc/kea/1.6.0/doc/html/man/kea-admin.8.html

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?