オープンソース

next up previous contents
Next: 3. KeaKeeperのインストール Up: KeaKeeper Previous: 1. KeaKeeperとは


2. KeaKeeperを利用するために

2.1 必要なソフトウェア

KeaKeeperの動作には、以下のソフトウェアが必要です。

  • Kea 1.4
  • Webサーバ
  • MySQL/MariaDB
  • PHP (5.4以上、mbstring, openssl, pdo, mysqlをサポートしている必要があります。)

本書では、以下の環境でKeaを利用することを想定して説明を行ないます。

構築環境
項目 内容
OS CentOS 7
Kea Kea 1.4
WEBサーバ Apache HTTP Server 2.4
PHP php 5.4
DBサーバ MariaDB 5.5

2.2 PHPの設定

2.2.1 PHPのインストール

PHPを以下のコマンドでインストールします。

# yum install php php-cli php-common php-mbstring php-pdo php-mysql

2.2.2 php.iniの設定

/etc/php.iniにタイムゾーンの設定を行ないます。

;date.timezone =
date.timezone = Asia/Tokyo

2.3 WEBサーバのインストール

2.3.1 Apache HTTP Serverのインストール

Apache HTTP Serverを以下のコマンドでインストールします。

# yum install httpd

2.3.2 Apache HTTP Serverの起動

Apache HTTP Serverを以下のコマンドで起動します。

# systemctl start httpd.service

2.4 MariaDBの設定

2.4.1 MariaDBのインストール

MariaDBを以下のコマンドでインストールします。

# yum install mariadb-server

2.4.2 MariaDB Serverの起動

MariaDB Serverを以下のコマンドで起動します。

# systemctl start mariadb.service

2.4.3 Firewalldの設定

Firewalldが有効な環境では、WEBサーバが利用するポートのアクセス許可設定を行う必要があります。 以下はhttpサービスを許可する例です。

# firewall-cmd --add-service=http
# firewall-cmd --permanent --add-service=http

2.4.4 MariaDBの設定

次にMariaDBの設定を行ないます。 mysql_secure_installationコマンドを実行し、初期設定を行ないます。
このコマンドでは以下のことが行われます。環境に合わせて実施してください。

  • 管理者パスワードの設定
  • 匿名ユーザの削除
  • 管理者ユーザのリモートログインの禁止
  • testデータベースの削除
  • 権限テーブルのリロード

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

2.4.5 Kea/KeaKeeper用のDB作成

Kea/KeaKeeperが利用するDBを作成します。 DB名はkeaとします。

# mysql -u root -p
Enter password:
> CREATE DATABASE kea;
> QUIT;

2.4.6 Kea/KeaKeeper用のDBユーザ作成

次にKea/KeaKeeperが利用するDBユーザの作成を行ないます。

# mysql -u root -p
Enter password:
> GRANT ALL ON kea.* TO
keauser@localhost IDENTIFIED BY 'password';
> FLUSH PRIVILEGES;
> QUIT;

2.5 Keaの設定

2.5.1 Keaのインストール

まずKeaのインストールを行ないます。Keaの最新版は以下のサイトからダウンロードできます。

http://ftp.isc.org/isc/kea/

CentOSの場合は、EPELリポジトリからインストールすることもできます。
本書では、EPELリポジトリを利用してインストールを行ないます。

# yum install epel-release
# yum install kea

2.5.2 Keaの設定

次にKeaの設定を行ないます。DHVPv4サービスの場合、設定は/etc/kea/kea-dhcp4.confに行ないます。DHVPv6サービスの場合、設定は/etc/kea/kea-dhcp6.confに行ないます。
設定の詳細については、以下のKeaのドキュメントを参照してください。

http://kea.isc.org/docs/kea-guide.htm

この解説では、DHCPv4サービスを例に挙げて解説します。
実際の設定は、環境に合わせて行ってください。

なお、設定のポイントは以下です。

  • リース情報の保存先をDBに変更する
  • ホスト予約情報の保存先をDBに変更する
  • サブネットの設定にIDを付与する

まず、リース情報の保存先をDBに変更します。
以下のようにlease-databaseのセクションを変更します。

"Dhcp4": {

(snip)

"lease-database": {
"type": "mysql",
"host": "127.0.0.1",
"name": "kea",
"user": "keauser",
"password": "password"
},

(snip)

  • typeにはDBのタイプとしてmysqlを指定します
  • hostにはDBのホストを指定します
  • nameにはDBの名前を指定します
  • userには、上記の手順で追加したユーザIDを指定します
  • passwordには、上記の手順で追加したユーザのパスワードを指定します

次に、ホスト予約情報の保存先をDBに変更します。
以下のようにhosts-databaseのセクションを変更します。

"Dhcp4": {

(snip)

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

(snip)

  • typeにはDBのタイプとしてmysqlを指定します
  • hostにはDBのホストを指定します
  • nameにはDBの名前を指定します
  • userには、上記の手順で追加したユーザIDを指定します
  • passwordには、上記の手順で追加したユーザのパスワードを指定します


最後に、subnet4セクションのサブネット毎にIDを付与します。 このIDはデータベースに格納されたホスト予約情報が、どのサブネットの情報か判断するために利用されます。 IDが無い場合は、データの不整合が発生したり、上手く動作しない恐れがあります。 またKeaの設定全体で(DHCPv6含む)、全てのサブネットにユニークなIDを付与する必要があります。 重複していた場合も、上手く動作しません。

以下は、サブネット「192.168.10.0/24」にid「1」を付与し、 サブネット「192.168.11.0/24」にid「2」を付与している例です。

"Dhcp4": {

(snip)

"subnet4": [
{
"id": 1,
"subnet": "192.168.10.0/24",
"pools": [{"pool": "192.168.10.10 - 192.168.10.100"}]
},
{
"id": 2,
"subnet": "192.168.11.0/24",
"pools": [{"pool": "192.168.11.10 - 192.168.11.100"}]
}
]
},

(snip)

2.5.3 テーブルの作成

データベースにテーブルを作成します。
データベースへのテーブルの作成は、以下のコマンドで行ないます。

# kea-admin lease-init mysql -u keauser -p password -n kea
Checking if there is a database initialized already. Please ignore errors.
Initializing database using script /usr/local/share/kea/scripts/mysql/dhcpdb_create.mysql
mysql returned status code 0
Lease DB version reported after initialization: 5.1

コマンド実行後、データベースには以下のようにテーブルが追加されます。

> use kea;
> show tables;
+----------------------+
| Tables_in_kea |
+----------------------+
| dhcp4_options |
| dhcp6_options |
| dhcp_option_scope |
| host_identifier_type |
| hosts |
| ipv6_reservations |
| lease4 |
| lease4_stat |
| lease6 |
| lease6_stat |
| lease6_types |
| lease_hwaddr_source |
| lease_state |
| schema_version |
+----------------------+
14 rows in set (0.00 sec)

2.5.4 Keaの起動

最後にKeaを起動します。
以下はDHCPv4サービスを起動する場合の例です。

# keactrl start -s dhcp4

next up previous contents
Next: 3. KeaKeeperのインストール Up: KeaKeeper Previous: 1. KeaKeeperとは

2023年11月27日