2019-06-06 18:25:46 +02:00
|
|
|
.. _admin:
|
|
|
|
|
|
|
|
***************************
|
|
|
|
Kea Database Administration
|
|
|
|
***************************
|
|
|
|
|
|
|
|
.. _kea-database-version:
|
|
|
|
|
2021-10-19 18:41:26 +03:00
|
|
|
Databases and Schema Versions
|
|
|
|
=============================
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2020-11-14 00:00:37 +00:00
|
|
|
Kea may be configured to use a database as storage for leases or as a
|
2019-06-06 18:25:46 +02:00
|
|
|
source of servers' configurations and host reservations (i.e. static
|
2021-09-10 20:34:45 +00:00
|
|
|
assignments of addresses, prefixes, options, etc.). As Kea is
|
|
|
|
updated, new database schemas are introduced to facilitate new
|
2019-06-06 18:25:46 +02:00
|
|
|
features and correct discovered issues with the existing schemas.
|
|
|
|
|
2021-10-19 18:41:26 +03:00
|
|
|
Each version of Kea expects a particular schema structure and checks for this by
|
|
|
|
examining the version of the database it is using. Separate version numbers are
|
|
|
|
maintained for the schemas, independent of the version of Kea itself. It is
|
|
|
|
possible that the schema version will stay the same through several Kea
|
|
|
|
revisions; similarly, it is possible that the version of the schema may go up
|
|
|
|
several revisions during a single Kea version upgrade. Versions for each backend
|
|
|
|
type are also independent, so an increment in the MySQL backend version does not
|
|
|
|
imply an increment in that of PostgreSQL.
|
|
|
|
|
|
|
|
Schema versions are specified in a major.minor format. For the most recent
|
|
|
|
versions, the minor version is always zero and only the major version is
|
|
|
|
incremented.
|
|
|
|
|
|
|
|
Historically, the minor version used to be incremented when backward-compatible
|
|
|
|
changes were introduced to the schema: for example - when a new index is added.
|
|
|
|
This was opposed to incrementing the major version which implied an incompatible
|
|
|
|
schema change: for example - changing the type of an existing column. If Kea
|
|
|
|
attempts to run on a schema that is too old, as indicated by a mismatched schema
|
|
|
|
version, it will fail; administrative action is required to upgrade the schema.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
.. _kea-admin:
|
|
|
|
|
2021-10-19 18:49:20 +00:00
|
|
|
The ``kea-admin`` Tool
|
|
|
|
======================
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
To manage the databases, Kea provides the ``kea-admin`` tool. It can
|
|
|
|
initialize a new backend, check its version number, perform a backend
|
2019-06-06 18:25:46 +02:00
|
|
|
upgrade, and dump lease data to a text file.
|
|
|
|
|
|
|
|
``kea-admin`` takes two mandatory parameters: ``command`` and
|
|
|
|
``backend``. Additional, non-mandatory options may be specified. The
|
|
|
|
currently supported commands are:
|
|
|
|
|
2021-10-19 18:49:20 +00:00
|
|
|
- ``db-init`` — initializes a new database schema. This is useful
|
2019-06-06 18:25:46 +02:00
|
|
|
during a new Kea installation. The database is initialized to the
|
|
|
|
latest version supported by the version of the software being
|
|
|
|
installed.
|
|
|
|
|
2021-10-19 18:49:20 +00:00
|
|
|
- ``db-version`` — reports the database backend version number. This
|
2021-09-10 20:34:45 +00:00
|
|
|
is not necessarily equal to the Kea version number, as each backend
|
2019-06-06 18:25:46 +02:00
|
|
|
has its own versioning scheme.
|
|
|
|
|
2021-10-19 18:49:20 +00:00
|
|
|
- ``db-upgrade`` — conducts a database schema upgrade. This is
|
2019-06-06 18:25:46 +02:00
|
|
|
useful when upgrading Kea.
|
|
|
|
|
2021-12-20 10:34:57 +02:00
|
|
|
- ``lease-dump`` — dumps the contents of the lease database (for MySQL or
|
2022-03-30 12:46:28 +03:00
|
|
|
PostgreSQL backends) to a CSV (comma-separated values) text file.
|
|
|
|
|
2021-12-20 10:34:57 +02:00
|
|
|
The first line of the file contains the column names. This can be used
|
|
|
|
as a way to switch from a database backend to a memfile backend.
|
|
|
|
Alternatively, it can be used as a diagnostic tool, so it provides a portable
|
|
|
|
form of the lease data.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2021-12-22 14:22:05 +02:00
|
|
|
- ``lease-upload`` — uploads leases from a CSV (comma-separated values) text
|
|
|
|
file to a MySQL or a PostgreSQL lease database. The CSV file needs to be in
|
|
|
|
memfile format.
|
|
|
|
|
2019-06-06 18:25:46 +02:00
|
|
|
``backend`` specifies the type of backend database. The currently
|
|
|
|
supported types are:
|
|
|
|
|
2021-10-19 18:49:20 +00:00
|
|
|
- ``memfile`` — lease information is stored on disk in a text file.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2021-10-19 18:49:20 +00:00
|
|
|
- ``mysql`` — information is stored in a MySQL relational database.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2021-10-19 18:49:20 +00:00
|
|
|
- ``pgsql`` — information is stored in a PostgreSQL relational
|
2019-06-06 18:25:46 +02:00
|
|
|
database.
|
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
Additional parameters may be needed, depending on the setup and
|
2019-06-06 18:25:46 +02:00
|
|
|
specific operation: username, password, and database name or the
|
|
|
|
directory where specific files are located. See the appropriate manual
|
|
|
|
page for details (``man 8 kea-admin``).
|
|
|
|
|
|
|
|
.. _supported-databases:
|
|
|
|
|
|
|
|
Supported Backends
|
|
|
|
==================
|
|
|
|
|
|
|
|
The following table presents the capabilities of available backends.
|
|
|
|
Please refer to the specific sections dedicated to each backend to
|
|
|
|
better understand their capabilities and limitations. Choosing the right
|
2021-09-10 20:34:45 +00:00
|
|
|
backend is essential for the success of the deployment.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
.. table:: List of available backends
|
|
|
|
|
2022-03-30 12:46:28 +03:00
|
|
|
+---------------+----------------+----------------+---------------+
|
|
|
|
| Feature | Memfile | MySQL | PostgreSQL |
|
|
|
|
| | | | |
|
|
|
|
+===============+================+================+===============+
|
|
|
|
| Status | Stable | Stable | Stable |
|
|
|
|
| | | | |
|
|
|
|
+---------------+----------------+----------------+---------------+
|
|
|
|
| Data format | CSV file | SQL RMDB | SQL RMDB |
|
|
|
|
| | | | |
|
|
|
|
| | | | |
|
|
|
|
+---------------+----------------+----------------+---------------+
|
|
|
|
| Leases | yes | yes | yes |
|
|
|
|
+---------------+----------------+----------------+---------------+
|
|
|
|
| Host | no | yes | yes |
|
|
|
|
| reservations | | | |
|
|
|
|
| | | | |
|
|
|
|
+---------------+----------------+----------------+---------------+
|
|
|
|
| Options | no | yes | yes |
|
|
|
|
| defined on | | | |
|
|
|
|
| per host | | | |
|
|
|
|
| basis | | | |
|
|
|
|
+---------------+----------------+----------------+---------------+
|
|
|
|
| Configuration | no | yes | yes |
|
|
|
|
| backend | | | |
|
|
|
|
| | | | |
|
|
|
|
+---------------+----------------+----------------+---------------+
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-06-26 16:03:19 -04:00
|
|
|
Memfile
|
2019-06-06 18:25:46 +02:00
|
|
|
-------
|
|
|
|
|
2019-06-17 17:20:36 -04:00
|
|
|
The memfile backend is able to store lease information, but cannot
|
|
|
|
store host reservation details; these must be stored in the
|
2019-06-06 18:25:46 +02:00
|
|
|
configuration file. (There are no plans to add a host reservations
|
|
|
|
storage capability to this backend.)
|
|
|
|
|
|
|
|
No special initialization steps are necessary for the memfile backend.
|
2021-09-10 20:34:45 +00:00
|
|
|
During the first run, both ``kea-dhcp4`` and ``kea-dhcp6`` create
|
2019-06-06 18:25:46 +02:00
|
|
|
an empty lease file if one is not present. Necessary disk-write
|
|
|
|
permission is required.
|
|
|
|
|
|
|
|
.. _memfile-upgrade:
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Upgrading Memfile Lease Files From an Earlier Version of Kea
|
2019-06-06 18:25:46 +02:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
There are no special steps required to upgrade memfile lease files
|
|
|
|
between versions of Kea. During startup, the
|
|
|
|
servers check the schema version of the lease files against their
|
|
|
|
own. If there is a mismatch, the servers automatically launch the
|
2019-06-06 18:25:46 +02:00
|
|
|
LFC process to convert the files to the server's schema version. While
|
|
|
|
this mechanism is primarily meant to ease the process of upgrading to
|
|
|
|
newer versions of Kea, it can also be used for downgrading should the
|
|
|
|
need arise. When upgrading, any values not present in the original lease
|
2021-09-10 20:34:45 +00:00
|
|
|
files are assigned appropriate default values. When downgrading, any
|
|
|
|
data present in the files but not in the server's schema are
|
2019-06-28 17:57:37 -04:00
|
|
|
dropped. To convert the files manually prior to starting the
|
2021-09-10 20:34:45 +00:00
|
|
|
servers, run the lease file cleanup (LFC) process. See :ref:`kea-lfc` for more information.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
.. _mysql-database:
|
|
|
|
|
|
|
|
MySQL
|
|
|
|
-----
|
|
|
|
|
|
|
|
MySQL is able to store leases, host reservations, options defined on a
|
2019-06-17 17:20:36 -04:00
|
|
|
per-host basis, and a subset of the server configuration parameters
|
2021-09-10 20:34:45 +00:00
|
|
|
(serving as a configuration backend).
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2023-01-10 09:51:28 +00:00
|
|
|
.. _mysql-database-engine:
|
|
|
|
|
|
|
|
MySQL 5.7 vs MySQL 8 vs MariaDB 10 and 11
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2023-04-07 15:12:25 +00:00
|
|
|
In our Kea performance testing, MySQL 8 shows a 60-90% drop in speed
|
|
|
|
in comparison with MySQL 5.7.
|
2023-01-10 09:51:28 +00:00
|
|
|
Due to the upcoming MySQL 5.7 EOL, we recommend using MariaDB instead of MySQL 8.
|
|
|
|
|
2023-04-07 15:12:25 +00:00
|
|
|
MySQL 5.7, MySQL 8, MariaDB 10, and MariaDB 11 are fully compatible,
|
|
|
|
interchangeable, and tested with Kea.
|
2023-01-10 09:51:28 +00:00
|
|
|
|
2019-06-06 18:25:46 +02:00
|
|
|
.. _mysql-database-create:
|
|
|
|
|
|
|
|
First-Time Creation of the MySQL Database
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Before preparing any Kea-specific database and tables, the MySQL database
|
|
|
|
must be configured to use the system timezone. It is recommended to use UTC
|
|
|
|
as the timezone for both the system and the MySQL database.
|
2021-08-05 16:44:06 +03:00
|
|
|
|
|
|
|
To check the system timezone:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
date +%Z
|
|
|
|
|
|
|
|
To check the MySQL timezone:
|
|
|
|
|
|
|
|
.. code-block:: mysql
|
|
|
|
|
|
|
|
mysql> SELECT @@system_time_zone;
|
|
|
|
mysql> SELECT @@global.time_zone;
|
|
|
|
mysql> SELECT @@session.time_zone;
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
To configure the MySQL timezone for a specific server, please refer to the
|
2021-08-05 16:44:06 +03:00
|
|
|
installed version documentation.
|
|
|
|
|
2021-10-19 18:49:20 +00:00
|
|
|
Usually the setting is configured in the [mysqld] section in ``/etc/mysql/my.cnf``,
|
|
|
|
``/etc/mysql/mysql.cnf``, ``/etc/mysql/mysqld.cnf``, or
|
|
|
|
``/etc/mysql/mysql.conf.d/mysqld.cnf``.
|
2021-08-05 16:44:06 +03:00
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
[mysqld]
|
|
|
|
# using default-time-zone
|
|
|
|
default-time-zone='+00:00'
|
|
|
|
|
|
|
|
# or using timezone
|
|
|
|
timezone='UTC'
|
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
When setting up the MySQL database for the first time, the
|
|
|
|
database area must be created within MySQL, and the MySQL user ID under
|
|
|
|
which Kea will access the database must be set up. This needs to be done manually,
|
|
|
|
rather than via ``kea-admin``.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
To create the database:
|
|
|
|
|
|
|
|
1. Log into MySQL as "root":
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
$ mysql -u root -p
|
|
|
|
Enter password:
|
|
|
|
mysql>
|
|
|
|
|
|
|
|
2. Create the MySQL database:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: mysql
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
mysql> CREATE DATABASE database_name;
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2020-11-20 16:54:00 +02:00
|
|
|
(``database_name`` is the name chosen for the database.)
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
3. Create the user under which Kea will access the database (and give it
|
|
|
|
a password), then grant it access to the database tables:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: mysql
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
mysql> CREATE USER 'user-name'@'localhost' IDENTIFIED BY 'password';
|
|
|
|
mysql> GRANT ALL ON database-name.* TO 'user-name'@'localhost';
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
(``user-name`` and ``password`` are the user ID and password used to
|
2019-06-17 17:20:36 -04:00
|
|
|
allow Kea access to the MySQL instance. All apostrophes in the
|
2019-06-06 18:25:46 +02:00
|
|
|
command lines above are required.)
|
|
|
|
|
2019-08-26 08:55:03 -04:00
|
|
|
4. Create the database.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2020-11-14 00:00:37 +00:00
|
|
|
Exit the MySQL client
|
2019-08-26 08:55:03 -04:00
|
|
|
|
|
|
|
.. code-block:: mysql
|
|
|
|
|
|
|
|
mysql> quit
|
|
|
|
Bye
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Then use the ``kea-admin`` tool to create the database.
|
2019-08-26 08:55:03 -04:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ kea-admin db-init mysql -u database-user -p database-password -n database-name
|
|
|
|
|
2020-11-14 00:00:37 +00:00
|
|
|
While it is possible to create the database from within the MySQL client, we recommend
|
2021-09-10 20:34:45 +00:00
|
|
|
using the ``kea-admin`` tool as it performs some necessary validations to ensure Kea can
|
|
|
|
access the database at runtime. Among those checks is verification that the schema does not contain
|
|
|
|
any pre-existing tables; any pre-existing tables must be removed
|
|
|
|
manually. An additional check examines the user's ability to create functions and
|
2020-11-14 00:00:37 +00:00
|
|
|
triggers. The following error indicates that the user does not have the necessary
|
|
|
|
permissions to create functions or triggers:
|
2019-08-26 08:55:03 -04:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
ERROR 1419 (HY000) at line 1: You do not have the SUPER privilege and binary logging is
|
|
|
|
enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
|
|
|
|
ERROR/kea-admin: mysql_can_create cannot trigger, check user permissions, mysql status = 1
|
|
|
|
mysql: [Warning] Using a password on the command line interface can be insecure.
|
|
|
|
ERROR/kea-admin: Create failed, the user, keatest, has insufficient privileges.
|
|
|
|
|
2020-11-20 16:54:00 +02:00
|
|
|
The simplest way around this is to set the global MySQL variable,
|
|
|
|
``log_bin_trust_function_creators``, to 1 via the MySQL client.
|
|
|
|
Note this must be done as a user with SUPER privileges:
|
2019-08-26 08:55:03 -04:00
|
|
|
|
|
|
|
.. code-block:: mysql
|
|
|
|
|
|
|
|
mysql> set @@global.log_bin_trust_function_creators = 1;
|
|
|
|
Query OK, 0 rows affected (0.00 sec)
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
To create the database with MySQL directly, follow these steps:
|
2019-08-26 08:55:03 -04:00
|
|
|
|
|
|
|
.. code-block:: mysql
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
mysql> CONNECT database-name;
|
|
|
|
mysql> SOURCE path-to-kea/share/kea/scripts/mysql/dhcpdb_create.mysql
|
|
|
|
|
2021-10-19 18:41:26 +03:00
|
|
|
(where ``path-to-kea`` is the location where Kea is installed.)
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-08-26 09:26:56 -04:00
|
|
|
The database may also be dropped manually as follows:
|
2019-08-26 08:55:03 -04:00
|
|
|
|
|
|
|
.. code-block:: mysql
|
|
|
|
|
|
|
|
mysql> CONNECT database-name;
|
|
|
|
mysql> SOURCE path-to-kea/share/kea/scripts/mysql/dhcpdb_drop.mysql
|
|
|
|
|
2021-10-19 18:41:26 +03:00
|
|
|
(where ``path-to-kea`` is the location where Kea is installed.)
|
2019-08-26 08:55:03 -04:00
|
|
|
|
|
|
|
.. warning::
|
2021-10-19 18:49:20 +00:00
|
|
|
|
2020-11-14 00:00:37 +00:00
|
|
|
Dropping the database results in the unrecoverable loss of any data it contains.
|
2019-08-26 08:55:03 -04:00
|
|
|
|
|
|
|
|
2019-06-06 18:25:46 +02:00
|
|
|
5. Exit MySQL:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: mysql
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
mysql> quit
|
|
|
|
Bye
|
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
If the tables were not created in Step 4, run the ``kea-admin`` tool
|
|
|
|
to create them now:
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-19 10:04:38 +02:00
|
|
|
$ kea-admin db-init mysql -u database-user -p database-password -n database-name
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
Do not do this if the tables were created in Step 4. ``kea-admin``
|
2019-06-06 18:25:46 +02:00
|
|
|
implements rudimentary checks; it will refuse to initialize a database
|
2019-06-28 17:57:37 -04:00
|
|
|
that contains any existing tables. To start from scratch,
|
2020-11-12 12:08:17 +00:00
|
|
|
all data must be removed manually. (This process is a manual operation
|
2021-09-10 20:34:45 +00:00
|
|
|
on purpose, to avoid accidentally irretrievable mistakes by ``kea-admin``.)
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
.. _mysql-upgrade:
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Upgrading a MySQL Database From an Earlier Version of Kea
|
2019-06-06 18:25:46 +02:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Sometimes a new Kea version uses a newer database schema, so the
|
|
|
|
existing database needs to be upgraded. This can be done using the
|
2019-07-19 10:04:38 +02:00
|
|
|
``kea-admin db-upgrade`` command.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
To check the current version of the database, use the following command:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-19 10:04:38 +02:00
|
|
|
$ kea-admin db-version mysql -u database-user -p database-password -n database-name
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-06-20 08:37:00 -04:00
|
|
|
(See :ref:`kea-database-version`
|
2019-06-06 18:25:46 +02:00
|
|
|
for a discussion about versioning.) If the version does not match the
|
|
|
|
minimum required for the new version of Kea (as described in the release
|
|
|
|
notes), the database needs to be upgraded.
|
|
|
|
|
|
|
|
Before upgrading, please make sure that the database is backed up. The
|
|
|
|
upgrade process does not discard any data, but depending on the nature
|
|
|
|
of the changes, it may be impossible to subsequently downgrade to an
|
2021-09-10 20:34:45 +00:00
|
|
|
earlier version.
|
|
|
|
|
|
|
|
To perform an upgrade, issue the following command:
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-19 10:04:38 +02:00
|
|
|
$ kea-admin db-upgrade mysql -u database-user -p database-password -n database-name
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-10-14 16:30:18 +02:00
|
|
|
.. note::
|
|
|
|
|
2020-11-17 15:42:21 +00:00
|
|
|
To search host reservations by hostname, it is critical that the collation of
|
2020-11-14 00:00:37 +00:00
|
|
|
the hostname column in the host table be case-insensitive. Fortunately, that
|
|
|
|
is the default in MySQL, but it can be verified via this command:
|
2019-10-14 16:30:18 +02:00
|
|
|
|
|
|
|
.. code-block:: mysql
|
|
|
|
|
|
|
|
mysql> SELECT COLLATION('');
|
|
|
|
+-----------------+
|
|
|
|
| COLLATION('') |
|
|
|
|
+-----------------+
|
|
|
|
| utf8_general_ci |
|
|
|
|
+-----------------+
|
|
|
|
|
2021-06-08 09:47:22 +00:00
|
|
|
According to mysql's naming convention, when the name ends in ``_ci``,
|
2019-10-14 16:30:18 +02:00
|
|
|
the collation is case-insensitive.
|
|
|
|
|
2020-01-24 11:26:11 +01:00
|
|
|
.. _mysql-performance:
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Improved Performance With MySQL
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-01-24 11:26:11 +01:00
|
|
|
|
2020-11-14 00:00:37 +00:00
|
|
|
Changing the MySQL internal value ``innodb_flush_log_at_trx_commit`` from the default value
|
2021-10-19 18:49:20 +00:00
|
|
|
of 1 to 2 can result in a huge gain in Kea performance. In some deployments, the
|
2021-08-19 11:43:10 +02:00
|
|
|
gain was over 1000% (10 times faster when set to 2, compared to the default value of 1).
|
|
|
|
It can be set per-session for testing:
|
2020-01-24 11:26:11 +01:00
|
|
|
|
|
|
|
.. code-block:: mysql
|
2020-01-24 11:54:42 +01:00
|
|
|
|
2020-01-24 11:26:11 +01:00
|
|
|
mysql> SET GLOBAL innodb_flush_log_at_trx_commit=2;
|
|
|
|
mysql> SHOW SESSION VARIABLES LIKE 'innodb_flush_log%';
|
|
|
|
|
|
|
|
or permanently in ``/etc/mysql/my.cnf``:
|
|
|
|
|
2020-10-02 19:31:37 +03:00
|
|
|
.. code-block:: ini
|
2020-01-24 11:54:42 +01:00
|
|
|
|
2020-01-24 11:26:11 +01:00
|
|
|
[mysqld]
|
|
|
|
innodb_flush_log_at_trx_commit=2
|
|
|
|
|
2020-11-17 15:42:21 +00:00
|
|
|
Be aware that changing this value can cause problems during data recovery
|
2021-08-19 11:43:10 +02:00
|
|
|
after a crash, so we recommend checking the `MySQL documentation
|
|
|
|
<https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_flush_log_at_trx_commit>`__.
|
|
|
|
With the default value of 1, MySQL writes changes to disk after every INSERT or UPDATE query
|
2021-09-10 20:34:45 +00:00
|
|
|
(in Kea terms, every time a client gets a new lease or renews an existing lease). When
|
2021-08-19 15:01:26 +02:00
|
|
|
``innodb_flush_log_at_trx_commit`` is set to 2, MySQL writes the changes at intervals
|
|
|
|
no longer than 1 second. Batching writes gives a substantial performance boost. The trade-off,
|
2021-09-10 20:34:45 +00:00
|
|
|
however, is that in the worst-case scenario, all changes in the last second before crash
|
2021-08-19 15:01:26 +02:00
|
|
|
could be lost. Given the fact that Kea is stable software and crashes very rarely,
|
2021-08-19 11:43:10 +02:00
|
|
|
most deployments find it a beneficial trade-off.
|
2020-01-24 11:26:11 +01:00
|
|
|
|
2019-06-06 18:25:46 +02:00
|
|
|
.. _pgsql-database:
|
|
|
|
|
|
|
|
PostgreSQL
|
|
|
|
----------
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
PostgreSQL can store leases, host reservations, and options
|
|
|
|
defined on a per-host basis.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
.. _pgsql-database-create:
|
|
|
|
|
|
|
|
First-Time Creation of the PostgreSQL Database
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Before preparing any Kea-specific database and tables, the PostgreSQL database
|
|
|
|
must be configured to use the system timezone. It is recommended to use UTC
|
|
|
|
as the timezone for both the system and the PostgreSQL database.
|
2021-08-05 16:44:06 +03:00
|
|
|
|
|
|
|
To check the system timezone:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
date +%Z
|
|
|
|
|
|
|
|
To check the PostgreSQL timezone:
|
|
|
|
|
|
|
|
.. code-block:: psql
|
|
|
|
|
|
|
|
postgres=# show timezone;
|
|
|
|
postgres=# SELECT * FROM pg_timezone_names WHERE name = current_setting('TIMEZONE');
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
To configure the PostgreSQL timezone for a specific server, please refer to the
|
2021-08-05 16:44:06 +03:00
|
|
|
installed version documentation.
|
|
|
|
|
2021-08-13 11:55:36 +02:00
|
|
|
Usually the setting is configured in the ``postgresql.conf`` with the varying
|
|
|
|
version path ``/etc/postgresql/<version>/main/postgresql.conf``, but on some systems
|
|
|
|
the files may be located in ``/var/lib/pgsql/data``.
|
2021-08-05 16:44:06 +03:00
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
timezone = 'UTC'
|
|
|
|
|
2019-07-19 10:04:38 +02:00
|
|
|
The first task is to create both the database and the user under
|
2019-06-06 18:25:46 +02:00
|
|
|
which the servers will access it. A number of steps are required:
|
|
|
|
|
|
|
|
1. Log into PostgreSQL as "root":
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
$ sudo -u postgres psql postgres
|
|
|
|
Enter password:
|
|
|
|
postgres=#
|
|
|
|
|
|
|
|
2. Create the database:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: psql
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
postgres=# CREATE DATABASE database-name;
|
|
|
|
CREATE DATABASE
|
|
|
|
postgres=#
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
(``database-name`` is the name chosen for the database.)
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
3. Create the user under which Kea will access the database (and give it
|
|
|
|
a password), then grant it access to the database:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: psql
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
postgres=# CREATE USER user-name WITH PASSWORD 'password';
|
|
|
|
CREATE ROLE
|
|
|
|
postgres=# GRANT ALL PRIVILEGES ON DATABASE database-name TO user-name;
|
|
|
|
GRANT
|
|
|
|
postgres=#
|
|
|
|
|
|
|
|
4. Exit PostgreSQL:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: psql
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
postgres=# \q
|
|
|
|
Bye
|
|
|
|
$
|
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
5. At this point, create the database tables either
|
|
|
|
using the ``kea-admin`` tool, as explained in the next section
|
2019-06-06 18:25:46 +02:00
|
|
|
(recommended), or manually. To create the tables manually, enter the
|
2021-09-10 20:34:45 +00:00
|
|
|
following command. PostgreSQL will prompt the administrator to enter the
|
2019-06-28 17:57:37 -04:00
|
|
|
new user's password that was specified in Step 3. When the command
|
|
|
|
completes, Kea will return to the shell prompt. The
|
|
|
|
output should be similar to the following:
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
$ psql -d database-name -U user-name -f path-to-kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql
|
|
|
|
Password for user user-name:
|
|
|
|
CREATE TABLE
|
|
|
|
CREATE INDEX
|
|
|
|
CREATE INDEX
|
|
|
|
CREATE TABLE
|
|
|
|
CREATE INDEX
|
|
|
|
CREATE TABLE
|
|
|
|
START TRANSACTION
|
|
|
|
INSERT 0 1
|
|
|
|
INSERT 0 1
|
|
|
|
INSERT 0 1
|
|
|
|
COMMIT
|
|
|
|
CREATE TABLE
|
|
|
|
START TRANSACTION
|
|
|
|
INSERT 0 1
|
|
|
|
COMMIT
|
|
|
|
$
|
|
|
|
|
2021-10-19 18:41:26 +03:00
|
|
|
(``path-to-kea`` is the location where Kea is installed.)
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
If instead an error is encountered, such as:
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
psql: FATAL: no pg_hba.conf entry for host "[local]", user "user-name", database "database-name", SSL off
|
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
... the PostgreSQL configuration will need to be altered. Kea uses
|
2019-06-06 18:25:46 +02:00
|
|
|
password authentication when connecting to the database and must have
|
|
|
|
the appropriate entries added to PostgreSQL's pg_hba.conf file. This
|
2019-06-28 17:57:37 -04:00
|
|
|
file is normally located in the primary data directory for the
|
|
|
|
PostgreSQL server. The precise path may vary depending on the
|
2021-08-05 16:44:06 +03:00
|
|
|
operating system and version, but the default location for PostgreSQL is
|
2021-08-13 11:55:36 +02:00
|
|
|
``/etc/postgresql/*/main/postgresql.conf``. However, on some systems
|
2021-09-10 20:34:45 +00:00
|
|
|
(notably CentOS 8), the file may reside in ``/var/lib/pgsql/data``.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
Assuming Kea is running on the same host as PostgreSQL, adding lines
|
|
|
|
similar to the following should be sufficient to provide
|
|
|
|
password-authenticated access to Kea's database:
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
local database-name user-name password
|
|
|
|
host database-name user-name 127.0.0.1/32 password
|
|
|
|
host database-name user-name ::1/128 password
|
|
|
|
|
|
|
|
These edits are primarily intended as a starting point, and are not a
|
|
|
|
definitive reference on PostgreSQL administration or database
|
2019-06-28 17:57:37 -04:00
|
|
|
security. Please consult the PostgreSQL user manual before making
|
|
|
|
these changes, as they may expose other databases that are running. It
|
2021-09-10 20:34:45 +00:00
|
|
|
may be necessary to restart PostgreSQL for the changes to
|
2019-06-06 18:25:46 +02:00
|
|
|
take effect.
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Initialize the PostgreSQL Database Using ``kea-admin``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
If the tables were not created manually, do so now by
|
2019-06-06 18:25:46 +02:00
|
|
|
running the ``kea-admin`` tool:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-19 10:04:38 +02:00
|
|
|
$ kea-admin db-init pgsql -u database-user -p database-password -n database-name
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-06-28 17:57:37 -04:00
|
|
|
Do not do this if the tables were already created manually. ``kea-admin``
|
2019-06-06 18:25:46 +02:00
|
|
|
implements rudimentary checks; it will refuse to initialize a database
|
2019-06-28 17:57:37 -04:00
|
|
|
that contains any existing tables. To start from scratch,
|
|
|
|
all data must be removed manually. (This process is a manual operation
|
2021-09-10 20:34:45 +00:00
|
|
|
on purpose, to avoid accidentally irretrievable mistakes by ``kea-admin``.)
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
.. _pgsql-upgrade:
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Upgrading a PostgreSQL Database From an Earlier Version of Kea
|
2019-06-06 18:25:46 +02:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The PostgreSQL database schema can be upgraded using the same tool and
|
2019-06-20 08:37:00 -04:00
|
|
|
commands as described in :ref:`mysql-upgrade`, with the exception that the "pgsql"
|
2019-06-06 18:25:46 +02:00
|
|
|
database backend type must be used in the commands.
|
|
|
|
|
|
|
|
Use the following command to check the current schema version:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-19 10:04:38 +02:00
|
|
|
$ kea-admin db-version pgsql -u database-user -p database-password -n database-name
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
Use the following command to perform an upgrade:
|
|
|
|
|
2019-07-15 08:32:02 +02:00
|
|
|
.. code-block:: console
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2019-07-19 10:04:38 +02:00
|
|
|
$ kea-admin db-upgrade pgsql -u database-user -p database-password -n database-name
|
2019-06-06 18:25:46 +02:00
|
|
|
|
2021-11-29 16:29:22 +01:00
|
|
|
.. _pgsl-ssl:
|
|
|
|
|
|
|
|
PostgreSQL without OpenSSL support
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Usually the PostgreSQL database client library is built with the OpenSSL
|
2021-12-20 16:30:39 +01:00
|
|
|
support but Kea can be configured to handle the case where it is not
|
|
|
|
supported:
|
2021-11-29 16:29:22 +01:00
|
|
|
|
2023-02-02 14:36:26 +00:00
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ ./configure [other-options] --disable-pgsql-ssl
|
|
|
|
|
2023-01-10 09:51:28 +00:00
|
|
|
.. _pgsql-performance:
|
|
|
|
|
|
|
|
Improved Performance With PostgreSQL
|
2023-01-10 10:48:01 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2023-01-10 09:51:28 +00:00
|
|
|
|
|
|
|
Changing the PostgreSQL internal value ``synchronous_commit`` from the default value
|
2023-04-07 15:12:25 +00:00
|
|
|
of ON to OFF can result in significant gains in Kea performance; on slow systems, the gain
|
|
|
|
can be over 1000%. It can be set per-session for testing:
|
2023-01-10 09:51:28 +00:00
|
|
|
|
|
|
|
.. code-block:: psql
|
|
|
|
|
|
|
|
postgres=# SET synchronous_commit = OFF;
|
|
|
|
|
2023-04-07 15:12:25 +00:00
|
|
|
or permanently via command (preferred method):
|
2023-01-10 09:51:28 +00:00
|
|
|
|
|
|
|
.. code-block:: psql
|
|
|
|
|
|
|
|
postgres=# ALTER SYSTEM SET synchronous_commit=OFF;
|
|
|
|
|
|
|
|
or permanently in ``/etc/postgresql/[version]/main/postgresql.conf``:
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
synchronous_commit = off
|
|
|
|
|
2023-04-07 15:12:25 +00:00
|
|
|
Changing this value can cause problems during data recovery
|
|
|
|
after a crash, so we recommend a careful read of the `PostgreSQL documentation
|
2023-01-10 09:51:28 +00:00
|
|
|
<https://www.postgresql.org/docs/current/wal-async-commit.html>`__.
|
|
|
|
With the default value of ON, PostgreSQL writes changes to disk after every INSERT or UPDATE query
|
|
|
|
(in Kea terms, every time a client gets a new lease or renews an existing lease). When
|
2023-04-07 15:12:25 +00:00
|
|
|
``synchronous_commit`` is set to OFF, PostgreSQL adds some delay before writing the changes.
|
|
|
|
Batching writes gives a substantial performance boost,
|
|
|
|
but in the worst-case scenario, all changes in the last moment before a crash
|
|
|
|
could be lost. Since Kea is stable software and crashes very rarely,
|
|
|
|
most deployments find the performance benefits outweigh the potential risks.
|
2023-01-10 09:51:28 +00:00
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
Using Read-Only Databases With Host Reservations
|
2019-06-06 18:25:46 +02:00
|
|
|
------------------------------------------------
|
|
|
|
|
|
|
|
If a read-only database is used for storing host reservations, Kea must
|
|
|
|
be explicitly configured to operate on the database in read-only mode.
|
2019-06-20 08:37:00 -04:00
|
|
|
Sections :ref:`read-only-database-configuration4` and
|
|
|
|
:ref:`read-only-database-configuration6` describe when such
|
2019-06-17 17:20:36 -04:00
|
|
|
a configuration may be required, and how to configure Kea to operate in
|
2019-06-20 08:37:00 -04:00
|
|
|
this way for both DHCPv4 and DHCPv6.
|
2019-06-06 18:25:46 +02:00
|
|
|
|
|
|
|
Limitations Related to the Use of SQL Databases
|
|
|
|
-----------------------------------------------
|
|
|
|
|
|
|
|
Year 2038 Issue
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
2021-09-10 20:34:45 +00:00
|
|
|
The lease expiration time in Kea is stored in the SQL database for each lease
|
|
|
|
as a timestamp value. Kea developers have observed that the MySQL database
|
|
|
|
does not accept timestamps beyond 2147483647 seconds (the maximum signed
|
2019-06-26 16:03:19 -04:00
|
|
|
32-bit number) from the beginning of the UNIX epoch (00:00:00 on 1
|
2019-06-06 18:25:46 +02:00
|
|
|
January 1970). Some versions of PostgreSQL do accept greater values, but
|
|
|
|
the value is altered when it is read back. For this reason, the lease
|
|
|
|
database backends put a restriction on the maximum timestamp to be
|
|
|
|
stored in the database, which is equal to the maximum signed 32-bit
|
|
|
|
number. This effectively means that the current Kea version cannot store
|
|
|
|
leases whose expiration time is later than 2147483647 seconds since the
|
2021-09-10 20:34:45 +00:00
|
|
|
beginning of the epoch (around the year 2038). This will be fixed when
|
2019-06-06 18:25:46 +02:00
|
|
|
database support for longer timestamps is available.
|