(Database and High-Availability options)
Created: 2020-10-28 Wed 11:54
postgres
).
kea
access permissions on this database(kea-server)# su - postgres (kea-server)$ psql -U postgres Password for user postgres: psql (12.4) Type "help" for help. postgres=# CREATE USER kea WITH PASSWORD 'secure-password'; CREATE ROLE postgres=# CREATE DATABASE kea_lease_db; CREATE DATABASE # GRANT ALL PRIVILEGES ON DATABASE kea_lease_db TO kea; postgres=# \q
mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.4.14-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE DATABASE kea_lease_db; Query OK, 1 row affected (0.000 sec)
kea
is created and given
access to the lease-database:MariaDB [(none)]> CREATE USER 'kea'@'localhost' IDENTIFIED BY 'secure-password'; Query OK, 0 rows affected (0.006 sec) MariaDB [(none)]> GRANT ALL ON kea_lease_db.* TO 'kea'@'localhost'; Query OK, 0 rows affected (0.005 sec) MariaDB [(none)]> quit Bye
innodb_flush_log_at_trx_commit
from default value 1
to 2
can result with huge gain in Kea
performance
It can be set per session for testing:
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
[mysqld] innodb_flush_log_at_trx_commit=2
db-init
of the kea-admin
tool is used to initialize the database
kea-admin
tool, as it provides extra security checks in the processExample: initializing a PostgreSQL database for lease database
# kea-admin db-init pgsql -u kea -h 127.0.0.1 -p secure-password -n kea_lease_db Checking if there is a database initialized already. Please ignore errors. Initializing database using script /opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:142: NOTICE: function lease4dumpheader() does not exist, skipping psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:150: NOTICE: function lease4dumpdata() does not exist, skipping psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:180: NOTICE: function lease6dumpheader() does not exist, skipping psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:188: NOTICE: function lease6dumpdata() does not exist, skipping psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:892: WARNING: there is already a transaction in progress Database version reported after initialization: 6.1
# kea-admin db-init mysql -u kea -p secure-password -n kea_lease_db Checking if there is a database initialized already. Please ignore errors. Verifying create permissions for kea MySQL Version is: 10.4.14-MariaDB Initializing database using script /opt/kea/share/kea/scripts/mysql/dhcpdb_create.mysql mysql returned status code 0 Database version reported after initialization: 9.3
kea-admin db-upgrade
command can be used to upgrade an
existing database
To check the current version of the database, use the following
command (<db-product>
can be mysql
or pgsql
):
$ kea-admin db-version <db-product> -u <db-user> -p <db-password> -n <db-name>
The kea-admin
command is used to upgrade the database schema of
the database (<db-product>
can be mysql
or pgsql
):
$ kea-admin db-upgrade <db-product> -u database-user -p database-password -n database-name
Example of a lease database configuration in Kea (file
kea-dhcp4.conf
or kea-dhcp6.conf
)
type
to mysql
"lease-database": { "type": "postgresql", "name": "kea_lease_db", "user": "kea", "password": "secure-password", "host": "localhost" },
# kea-dhcp4 -t /opt/kea/etc/kea/kea-dhcp4.conf 2020-10-22 11:43:23.772 INFO [kea-dhcp4.hosts/61595.139911418369920] HOSTS_BACKENDS_REGISTERED the following host backend types are available: mysql 2020-10-22 11:43:23.773 INFO [kea-dhcp4.dhcpsrv/61595.139911418369920] DHCPSRV_CFGMGR_SOCKET_TYPE_DEFAULT "dhcp-socket-type" not specified , using default socket type raw 2020-10-22 11:43:23.774 INFO [kea-dhcp4.dhcpsrv/61595.139911418369920] DHCPSRV_CFGMGR_NEW_SUBNET4 a new subnet has been added to configuration: 192.0.2.0/24 with params: t1=900, t2=1800, valid-lifetime=3600
kea
access permissions on this
database(kea-server)# su - postgres (kea-server)$ psql -U postgres Password for user postgres: psql (12.4) Type "help" for help. postgres=# CREATE DATABASE kea_host_db; CREATE DATABASE postgres=# GRANT ALL PRIVILEGES ON DATABASE kea_host_db TO kea; GRANT postgres=# \q
db-init
of the kea-admin
tool is used to initialized the database
kea-admin
tool, as it provides extra security checks in the processExample: initializing a PostgreSQL database for use as a host reservation database
# kea-admin db-init pgsql -u kea -h 127.0.0.1 -p secure-password -n kea_host_db Checking if there is a database initialized already. Please ignore errors. Initializing database using script /opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:142: NOTICE: function lease4dumpheader() does not exist, skipping psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:150: NOTICE: function lease4dumpdata() does not exist, skipping psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:180: NOTICE: function lease6dumpheader() does not exist, skipping psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:188: NOTICE: function lease6dumpdata() does not exist, skipping psql:/opt/kea/share/kea/scripts/pgsql/dhcpdb_create.pgsql:892: WARNING: there is already a transaction in progress Database version reported after initialization: 6.1
Host database for PostgreSQL configuration in Kea (file
kea-dhcp4.conf
or kea-dhcp6.conf
)
type
to mysql
"hosts-database": { "type": "postgresql", "name": "kea_host_db", "user": "kea", "password": "secure-password", "host": "localhost" },
read-only access for retrieving reservations for clients and/or assigning specific addresses and options, can be configured explicitly in Kea with the read-only mode
"Dhcp4": { "hosts-database": { "readonly": true, ... }, ... }
config-fetch-wait-time
parameter
server-tag
is selecting the individual configuration for
this DHCP serverconfig-fetch-wait-time
parameter defines the poll intervall for
new configuration (default 30) in seconds"Dhcp6": { "server-tag": "office-1", "config-control": { "config-databases": [{ "type": "mysql", "name": "kea_config_db", "user": "kea", "password": "secure-password", "host": "2001:db8:568::568" }], "config-fetch-wait-time": 120 }, [...] }
libdhcp_mysql_cb.so
is the implementation of the
Configuration Backend for MySQL."hooks-libraries": [{ "library": "/usr/lib/kea/hooks/libdhcp_mysql_cb.so" }, { "library": "/usr/lib/kea/hooks/libdhcp_cb_cmds.so" }],
libdhcp_cb_cmds.so
is optional."hooks-libraries": [{ "library": "/usr/lib/kea/hooks/libdhcp_mysql_cb.so" }, { "library": "/usr/lib/kea/hooks/libdhcp_cb_cmds.so" }],
all
tag
max-reconnect-tries
,
the server will issue a fatal error and exitreconnect-wait-time
configures number of
milliseconds the server will wait between attempts to reconnect to
the database after connectivity has been lost
0
, which disables
automatic recovery and causes the server to exit immediately upon
detecting the loss of connectivity to a database
this-server-name
parametermode
parameter"Dhcp4": { "hooks-libraries": [{ "library": "/usr/lib/kea/hooks/libdhcp_lease_cmds.so", "parameters": { } }, { "library": "/usr/lib/kea/hooks/libdhcp_ha.so", "parameters": { "high-availability": [{ "this-server-name": "server1", "mode": "load-balancing", "heartbeat-delay": 10000, "max-response-delay": 40000, "max-ack-delay": 5000, "max-unacked-clients": 5, "peers": [{ "name": "server1", "url": "http://192.0.2.33:8000/", "role": "primary", "auto-failover": true }, { "name": "server2", "url": "http://192.0.2.66:8000/", "role": "secondary", "auto-failover": true }, { "name": "server3", "url": "http://192.0.2.99:8000/", "role": "backup", "basic-auth-user": "foo", "basic-auth-password": "bar", "auto-failover": false }] }] } }], [...]
"Dhcp4": { "hooks-libraries": [{ "library": "/usr/lib/kea/hooks/libdhcp_lease_cmds.so", "parameters": { } }, { "library": "/usr/lib/kea/hooks/libdhcp_ha.so", "parameters": { "high-availability": [{ "this-server-name": "server1", "mode": "hot-standby", "heartbeat-delay": 10000, "max-response-delay": 40000, "max-ack-delay": 5000, "max-unacked-clients": 5, "peers": [{ "name": "server1", "url": "http://192.0.2.33:8000/", "role": "primary", "auto-failover": true }, { "name": "server2", "url": "http://192.0.2.66:8000/", "role": "standby", "auto-failover": true }, { "name": "server3", "url": "http://192.0.2.99:8000/", "basic-auth-user": "foo", "basic-auth-password": "bar", "role": "backup", "auto-failover": false }] }] } }], [...]
ha-sync
command triggers the server to sync the lease
database with the selected peer{ "command": "ha-sync", "service": [ "dhcp4 "], "arguments": { "server-name": "server2", "max-period": 60 } }
The command ha-heartbeat
can be used to check the current state
of a Kea DHCP server HA node
{ "service": [ "dhcp4" ], "command": "ha-heartbeat" }
The returned JSON structure describes the current DHCP server state
{ "result": 0, "text": "HA peer status returned.", "arguments": { "state": "partner-down", "date-time": "Thu, 07 Nov 2019 08:49:37 GMT" } }
status-get
command, the administrator can request the
current HA configuration from a Kea DHCP server node{ "result": 0, "text": "", "arguments": { "pid": 1234, "uptime": 3024, "reload": 1111, "high-availability": [{ "ha-mode": "load-balancing", "ha-servers": { "local": { "role": "primary", "scopes": [ "server1" ], "state": "load-balancing" }, "remote": { "age": 10, "in-touch": true, "role": "secondary", "last-scopes": [ "server2" ], [...] "analyzed-packets": 8 } }}], "multi-threading-enabled": true, "thread-pool-size": 4, "packet-queue-size": 64 } }
ha-maintenance-start
and ha-maintenance-cancel
commands can be use to bring a server in or out of maintenance
mode