实现功能:kea-DHCP实现自动分配IP、stork-server实现监控kea服务器状态及IP地址使用状态
安装环境:Ubuntu 18.04
kea-dhcp Kea-1.9.10.tar
stork 1.9.0
参考资料:https://kea.readthedocs.io/en/latest/index.html
https://stork.readthedocs.io/en/v1.9.0/
下载连接:https://www.isc.org/download/#Kea
环境准备
为了方便操作以下命令均使用root操作
登录root用户,首先使用当前用户设置root用户密码
zhou@zhou-virtual-machine:~$ sudo passwd root
[sudo] zhou 的密码:
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
passwd:已成功更新密码
zhou@zhou-virtual-machine:~$ su - root
密码:
root@zhou-virtual-machine:~#
Ubuntu 基本配置
apt安装源(自行搜索解决)
更新系统软件
root@zhou-virtual-machine:~# apt-get upgrade
安装远程服务及便于操作工具
root@zhou-virtual-machine:~# apt-get install ssh net-tools vim lrzsz
kea安装
一、准备kea环境
kea依赖安装
root@zhou-virtual-machine:~# apt install gcc g++ curl make libtool autoconf libmysql++-dev libboost-system-dev
安装log4cplus
log4plus仓库缺少ThreadPool,需要手动下载。
下载链接:https://github.com/log4cplus/ThreadPool
下载ThreadPool-master.zip包
创建log4cplus文件夹,存放文件进行编译安装
root@zhou-virtual-machine:~# mkdir log4cplus
root@zhou-virtual-machine:~# cd log4cplus
root@zhou-virtual-machine:~/log4cplus# wget https://github.com/log4cplus/log4cplus/archive/refs/tags/REL_2_0_7.tar.gz #下载log4cplus资源包
#ps:如果使用wget无法下载原因可能是因为虚拟机无法连接github导致,需要使用开启代理下载,也可以在浏览器出入此网址进行下载资源包(不稳定)
下载好log4cplus后进行解压,然后下载ThreadPool,将ThreadPool-master.zip解压出来的ThreadPool.h头文件放到REL_2_0_7/threadpool目录
root@zhou-virtual-machine:~/log4cplus# tar -zxvf REL_2_0_7.tar.gz
root@zhou-virtual-machine:~/log4cplus# ls
log4cplus-REL_2_0_7 REL_2_0_7.tar.gz
#ps:使用真机浏览器下载ThreadPool包后,放入服务器内
root@zhou-virtual-machine:~/log4cplus# ls
log4cplus-REL_2_0_7 REL_2_0_7.tar.gz ThreadPool-master.zip
root@zhou-virtual-machine:~/log4cplus# unzip ThreadPool-master.zip
root@zhou-virtual-machine:~/log4cplus# ls
log4cplus-REL_2_0_7 REL_2_0_7.tar.gz ThreadPool-master ThreadPool-master.zip
root@zhou-virtual-machine:~/log4cplus# ls ThreadPool-master
COPYING example.cpp README.md ThreadPool.h
root@zhou-virtual-machine:~/log4cplus# mv ThreadPool-master/ThreadPool.h log4cplus-REL_2_0_7/threadpool/
进入log4cplus目录,进行编译安装
oot@zhou-virtual-machine:~/log4cplus/log4cplus-REL_2_0_7# ./configure
root@zhou-virtual-machine:~/log4cplus/log4cplus-REL_2_0_7# make && make install
#防止共享库加载出现问题,使用ldconfig进行加载共享库
root@zhou-virtual-machine:~/log4cplus/log4cplus-REL_2_0_7# ldconfig
root@zhou-virtual-machine:~/log4cplus/log4cplus-REL_2_0_7# cd
二、安装MySQL服务
root@zhou-virtual-machine:~# apt-get install mariadb-server
root@zhou-virtual-machine:~# systemctl status mariadb
root@zhou-virtual-machine:~# mysql_secure_installation
#使用命令初始化MySQL,除去输入密码选项其余全部回车
登录MySQL,进行kea数据库创建、kea用户授权
root@zhou-virtual-machine:~# mysql -uroot -p
Enter password:
MariaDB [(none)]> CREATE DATABASE keadhcp;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> CREATE USER 'keadhcp'@'localhost' IDENTIFIED BY 'keadhcp';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> GRANT ALL ON keadhcp.* to 'keadhcp'@'localhost' IDENTIFIED BY 'keadhcp';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
安装kea
一、编译安装kea
将下载好的Kea-1.9.10.tar包放入服务器
root@zhou-virtual-machine:~# ls
Kea-1.9.10.tar.gz log4cplus snap
root@zhou-virtual-machine:~# tar -zxvf Kea-1.9.10.tar.gz
root@zhou-virtual-machine:~# ls
Kea-1.9.10.tar.gz kea-Kea-1.9.10 log4cplus snap
root@zhou-virtual-machine:~# cd kea-Kea-1.9.10/
root@zhou-virtual-machine:~/kea-Kea-1.9.10# autoreconf --install #生成可运行的./configure文件
root@zhou-virtual-machine:~/kea-Kea-1.9.10# ./configure --with-mysql #配置加载mysql模块
# 默认不需要添加 “--prefix=”选项 (默认安装位置为/usr/local)
# kea可执行程序安装位置在/usr/local/sbin位置,属于环境变量$path,可以直接使用
root@zhou-virtual-machine:~/kea-Kea-1.9.10# make #编译——编译时间会很长,需要耐心等待
root@zhou-virtual-machine:~/kea-Kea-1.9.10# make install #安装
二、测试开启kea服务
root@zhou-virtual-machine:~/kea-Kea-1.9.10# keactrl start
INFO/keactrl: Starting /usr/local/sbin/kea-dhcp4 -c /usr/local/etc/kea/kea-dhcp4.conf
/usr/local/sbin/kea-dhcp4: error while loading shared libraries: libkea-dhcpsrv.so.48: cannot open shared object file: No such file or directory
INFO/keactrl: Starting /usr/local/sbin/kea-dhcp6 -c /usr/local/etc/kea/kea-dhcp6.conf
/usr/local/sbin/kea-dhcp6: error while loading shared libraries: libkea-dhcpsrv.so.48: cannot open shared object file: No such file or directory
INFO/keactrl: Starting /usr/local/sbin/kea-ctrl-agent -c /usr/local/etc/kea/kea-ctrl-agent.conf
/usr/local/sbin/kea-ctrl-agent: error while loading shared libraries: libkea-process.so.28: cannot open shared object file: No such file or directory
测试开启服务失败,找不到libkea-dhcpsrv.so.48,需要使用ldconfig,加载共享库
root@zhou-virtual-machine:~/kea-Kea-1.9.10# ldconfig
root@zhou-virtual-machine:~/kea-Kea-1.9.10# keactrl start
INFO/keactrl: Starting /usr/local/sbin/kea-dhcp4 -c /usr/local/etc/kea/kea-dhcp4.conf
INFO/keactrl: Starting /usr/local/sbin/kea-dhcp6 -c /usr/local/etc/kea/kea-dhcp6.conf
INFO/keactrl: Starting /usr/local/sbin/kea-ctrl-agent -c /usr/local/etc/kea/kea-ctrl-agent.conf
root@zhou-virtual-machine:~/kea-Kea-1.9.10#
测试开启成功
root@zhou-virtual-machine:~/kea-Kea-1.9.10# keactrl status
DHCPv4 server: active
DHCPv6 server: active
DHCP DDNS: inactive
Control Agent: active
Kea DHCPv4 configuration file: /usr/local/etc/kea/kea-dhcp4.conf
Kea DHCPv6 configuration file: /usr/local/etc/kea/kea-dhcp6.conf
Kea DHCP DDNS configuration file: /usr/local/etc/kea/kea-dhcp-ddns.conf
Kea Control Agent configuration file: /usr/local/etc/kea/kea-ctrl-agent.conf
keactrl configuration file: /usr/local/etc/kea/keactrl.conf
三、初始化kea数据库
此处提供两种初始化方法
● 方法1:通过kea-admin自动初始化
# kea-admin db-init mysql -u <user> -p <password> -n <database>
kea-admin db-init mysql -u keadhcp -p keadhcp -n keadhcp
● 方法2:手动导入Mysql数据表
# mysql -uroot -p
> use keadhcp;
> source /root/kea-Kea-1.9.10/src/share/database/scripts/mysql/dhcpdb_create.mysql
个人只测试了第二种方法
root@zhou-virtual-machine:~/kea-Kea-1.9.10# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 50
Server version: 10.1.48-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04
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)]> use keadhcp;
Database changed
MariaDB [keadhcp]> show tables;
Empty set (0.00 sec)
MariaDB [keadhcp]> source /root/kea-Kea-1.9.10/src/share/database/scripts/mysql/dhcpdb_create.mysql
保存虚拟机快照进行下一阶段
修改kea配置文件,测试DHCP功能
kea安装路径为/usr/local
默认可执行程序路径为/usr/local/sbin 默认配置文件路径为/usr/local/etc/kea/
一、修改kea-dhcp4配置文件
root@zhou-virtual-machine:~/kea-Kea-1.9.10# cp /usr/local/etc/kea/kea-dhcp4.conf /usr/local/etc/kea/kea-dhcp4.conf.bak
root@zhou-virtual-machine:~# vim /usr/local/etc/kea/kea-dhcp4.conf
{
"Dhcp4": {
"interfaces-config": {
"interfaces": [
"ens33/192.168.4.10" //启用DHCP服务网卡地址
]
},
"control-socket": {
"socket-type": "unix",
"socket-name": "/tmp/kea4-ctrl-socket"
},
"lease-database": { //租赁数据保存后端
"type": "mysql",
"name": "keadhcp",
"user": "keadhcp",
"password": "keadhcp",
"host": "localhost",
"port": 3306,
"lfc-interval": 3600
},
"hosts-database": { //保留IP数据保存后端
"type": "mysql",
"name": "keadhcp",
"user": "keadhcp",
"password": "keadhcp",
"host": "localhost",
"port": 3306
},
"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",
// "code": 6,
// "csv-format": "true",
// "space": "dhcp4",
// "data": "192.0.2.1, 192.0.2.2"
// }
{
"name": "domain-name-servers", //dns参数
"data": "114.114.114.114, 192.168.4.1"
},
{
"code": 15,
"data": "example.org"
},
{
"name": "domain-search",
"data": "mydomain.example.com, example.com"
},
{
"name": "boot-file-name",
"data": "EST5EDT4\\,M3.2.0/02:00\\,M11.1.0/02:00"
},
{
"name": "default-ip-ttl",
"data": "0xf0"
}
],
"client-classes": [
{
"name": "voip",
"test": "substring(option[60].hex,0,6) == 'Aastra'",
"next-server": "192.0.2.254",
"server-hostname": "hal9000",
"boot-file-name": "/dev/null"
}
],
// hook libraries, see https://gitlab.isc.org/isc-projects/kea/wikis/Hooks-available.
// "hooks-libraries": [
// {
// "library": "/usr/local/lib/kea/hooks/libdhcp_legal_log.so",
// "parameters": {
// "path": "/var/lib/kea",
// "base-name": "kea-forensic4"
// }
// },
// {
// "library": "/usr/local/lib/kea/hooks/libdhcp_flex_id.so",
// "parameters": {
// "identifier-expression": "relay4[2].hex"
// }
// }
// ],
"subnet4": [
{
"subnet": "192.168.4.0/24", //DHCP子网
"pools": [ { "pool": "192.168.4.30 - 192.168.4.80" }, //DHCP地址池
{ "pool": "192.168.4.130 - 192.168.4.180" }
],
"option-data": [
{
"name": "routers", //路由设置
"data": "192.168.4.1"
}
],
"reservations": [ //保留IP设置,“{}”内为一个保留,可以有多个“{}”用“,”隔开
{
"hw-address": "1a:1b:1c:1d:1e:1f",
"ip-address": "192.168.4.201"
},
{
"client-id": "01:11:22:33:44:55:66",
"ip-address": "192.168.4.202",
"hostname": "special-snowflake"
},
{
"duid": "01:02:03:04:05",
"ip-address": "192.168.4.203",
"option-data": [ {
"name": "domain-name-servers",
"data": "192.168.4.1, 114.114.114.114"
} ]
},
{
"client-id": "01:12:23:34:45:56:67",
"ip-address": "192.168.4.204",
"option-data": [
{
"name": "vivso-suboptions",
"data": "4491"
},
{
"name": "tftp-servers",
"space": "vendor-4491",
"data": "192.168.4.202, 192.168.4.203"
}
]
},
{
"client-id": "01:0a:0b:0c:0d:0e:0f",
"ip-address": "192.168.4.205",
"next-server": "192.0.2.1",
"server-hostname": "hal9000",
"boot-file-name": "/dev/null"
},
{
"flex-id": "'s0mEVaLue'",
"ip-address": "192.168.4.206"
}
// You can add more reservations here.
]
// You can add more subnets there.
}
],
"loggers": [
{
"name": "kea-dhcp4",
"output_options": [
{
"output": "/usr/local/var/log/kea-dhcp4.log"
}
],
"severity": "INFO",
"debuglevel": 0
}
]
}
}
修改配置文件/usr/local/etc/kea/keactrl.conf,暂时关闭DHCPv6功能
root@zhou-virtual-machine:~# vim /usr/local/etc/kea/keactrl.conf
# Start DHCPv6 server?
dhcp6=no //第34行
root@zhou-virtual-machine:~# keactrl stop
root@zhou-virtual-machine:~# keactrl start //重启kea-dhcp服务
二、测试DHCP功能
测试虚拟机分配IP(虚拟机需要设置在一个网络)
![](https://i-blog.csdnimg.cn/blog_migrate/c1f5124b8daa1d170b7e1444a76b5ab2.png)
测试kea-DHCP成功分配IP
三、进制转换
查看数据库lease4表,分配了一个IP;IP地址为十进制数:3232236574,需要转化为二进制,在对应为IP地址;
![](https://i-blog.csdnimg.cn/blog_migrate/7e682fda48bcaf5b66d87466346a84d5.png)
使用进制转换器查看,二进制数为:11000000101010000000010000011110
![](https://i-blog.csdnimg.cn/blog_migrate/eeffb93ddb24c12141e46ba4bade3751.png)
将二进制转化为IP地址则为192.168.4.30
![](https://i-blog.csdnimg.cn/blog_migrate/849b5f93019e226e4ac593c8110b2dc7.png)
保存虚拟机快照进行下一阶段
安装stork服务
stork服务有两个软件,一个stork-server另一个stork-agnet
两者的区别:server为stork仪表盘,可以不安装在kea服务器。收集agent端搜集的数据,整理到web界面显示。需要postgresql数据库提供后端存储。
agent为stork代理端,需要安装在kea服务所在的服务器上。监视kea服务状态以及所有操作,提供给server。不需要依赖软件但是需要跟stork-server服务进行授权才可以交互。
一、配置stork安装源
根据官网提供的安装源
Debian/Ubuntu:
curl -1sLf 'https://dl.cloudsmith.io/public/isc/stork/cfg/setup/bash.deb.sh' | sudo bash
CentOS/RHEL/Fedora:
curl -1sLf 'https://dl.cloudsmith.io/public/isc/stork/cfg/setup/bash.rpm.sh' | sudo bash
root@zhou-virtual-machine:~# curl -1sLf 'https://dl.cloudsmith.io/public/isc/stork/cfg/setup/bash.deb.sh' | sudo bash
为了节省资源,本次测试将stork-server、stork-agnet安装到同一台服务器
二、安装stork-server
安装stork-server
root@zhou-virtual-machine:~# sudo apt install isc-stork-server
安装postgresql数据库,配置stork后端数据库
![](https://i-blog.csdnimg.cn/blog_migrate/72023d2215eaa41a4fde8929e59ee1af.png)
创建postgresql用户连接postgresql数据库
root@zhou-virtual-machine:~# cd /home/
root@zhou-virtual-machine:/home# id postgres
uid=125(postgres) gid=129(postgres) 组=129(postgres),110(ssl-cert)
root@zhou-virtual-machine:/home# mkdir postgres #创建postgres用户
root@zhou-virtual-machine:/home# chown postgres postgres #将postgres用户添加到postgres组
root@zhou-virtual-machine:/home# su postgres #切换到postgres用户
postgres@zhou-virtual-machine:/home$ createdb stork #创建stork数据库
postgres@zhou-virtual-machine:/home$ psql #进入postgresql命令行
psql (10.23 (Ubuntu 10.23-0ubuntu0.18.04.1))
Type "help" for help
postgres=# CREATE USER stork WITH PASSWORD 'stork'; #创建stork用户,以及设置密码
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE stork TO stork; #为stork用户授权
GRANT
postgres=# ALTER USER stork WITH SUPERUSER; 将stork用户设置为超级用户,否则stork-server程序无法连接postgresql数据库
ALTER ROLE
配置stork-server连接数据库
stork-server配置文件
root@zhou-virtual-machine:/home# vim /etc/stork/server.env
### the address of a PostgreSQL database
STORK_DATABASE_HOST=192.168.4.10 #PostgreSQL 数据库的地址;默认是本地主机
### the port of a PostgreSQL database
STORK_DATABASE_PORT=5423 #PostgreSQL 数据库的端口;默认值为5432
### the name of a database
STORK_DATABASE_NAME=stork #数据库名称;默认是stork
### the username for connecting to the database
STORK_DATABASE_USER_NAME=stork #连接数据库的用户名;默认是stork
………………
………………
STORK_DATABASE_PASSWORD=stork #连接到数据库的用户名的密码
………………
测试启动server服务
root@zhou-virtual-machine:/home# systemctl start isc-stork-server.service
Failed to start isc-stork-server.service: Unit isc-stork-server.service is not loaded properly: Exec format error.
See system logs and 'systemctl status isc-stork-server.service' for details.
使用systemctl启动stork-server启动失败
原因为/lib/systemd/system/isc-stork-server.service文件内ExecStart值不是stork-server程序的绝对路径
解决方法:
root@zhou-virtual-machine:/home# which stork-server
/usr/bin/stork-server #找到stork-server绝对路径
root@zhou-virtual-machine:/home# vim /lib/systemd/system/isc-stork-server.service
…………
ExecStart=/usr/bin/stork-server
…………
修改后可以使用systemctl命令开启server服务,但是服务开启没有成功连接数据库。没有8080端口。所以暂时不能使用systemctl启动stork-server服务
正确开启stork-server方法
root@zhou-virtual-machine:/home# stork-server
database password: #postgresql中创建的stork用户密码
#ps:注意开启stork-server后,程序会占用一个终端,不可以将终端关闭,否则程序也会退出
zhou@zhou-virtual-machine:~$ ss -antulp | grep 8080 #检查stork-server端口
tcp LISTEN 0 128 *:8080 *:*
使用浏览器访问http://服务器IP:8080
用户名:admin
密码:admin
![](https://i-blog.csdnimg.cn/blog_migrate/b58de741ae78f14c0b29c62b545b8ee6.png)
stork-server没有中文模式,需要使用浏览器翻译
![](https://i-blog.csdnimg.cn/blog_migrate/154c10dce45c462598465dff336bc78f.png)
现在stork-server的安装已经完成。虚拟机保存快照进行stork-agent的安装
三、安装stork-agent
agent有两种安装方法
方法一:stork-server web端提供了agent的安装脚本
Services——>Machines——>How to lnstall Agent on New Machine
![](https://i-blog.csdnimg.cn/blog_migrate/dc326ea68710763bbe087a34bf6ffdca.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f50bfff8c1a729bf5ffd111d506219c9.png)
此外也有agent的授权令牌
但是此方法不可使用,stork-server上没有agent的安装脚本
方法二:直接使用apt源安装isc-stork-agent
root@zhou-virtual-machine:~# apt-get install isc-stork-agent
root@zhou-virtual-machine:~# systemctl start isc-stork-agent.service
Failed to start isc-stork-agent.service: Unit isc-stork-agent.service is not loaded properly: Exec format error.
See system logs and 'systemctl status isc-stork-agent.service' for details.
使用systemctl开启stork-agnet仍旧失败——按照“使用systemctl启动stork-server启动失败”方案解决。
因为stork-server和stork-agnet安装在同一台服务器上,并且两个进程开启都占用8080端口,所以需要修改agent进程的端口号——如果两个进程没有在同一台服务器则无需操作(后面经过测试在agent配置文件内将端口改为8081后运行agent,开启端口仍是8080,此方法不可用,解决方法在后续提供)
root@zhou-virtual-machine:~# vim /etc/stork/agent.env
…………
STORK_AGENT_PORT=8081
…………
四、stork-agent授权
stork-agent与stork-server的区别
stork-agent:作为代理需要安装在kea-dhcp服务上,用来监视kea-dhcp服务的状态与动作
stork-server:stork服务端,主要与stork-agent进行交互,使用stork-server提供token授权stork-agent后,二者才可以进行交互提供数据。
授权方法有两种:
stork-server提供授权
使用stork-server提供安装agent方式进行授权agent(个人测试server提供安装方式不可用)
![](https://i-blog.csdnimg.cn/blog_migrate/4a517e9ee191ce81df3153fd785a5d61.png)
stork-agent申请授权
使用apt-get命令安装agent后,使用agent命令进行交互式申请授权
# stork-agent register -u http://stork-server_ip:8080
root@zhou-virtual-machine:~# stork-agent register -u http://192.168.4.10:8080
>>>> Server access token (optional): #此项为服务器提供令牌不输入直接回车
>>>> IP address or FQDN of the host with Stork Agent (for the Stork Server connection) [zhou-virtual-machine]: 192.168.4.10 #此项为agent服务器IP,目前agent_ip与server_ip一致
>>>> Port number that Stork Agent will listen on [8080]: 8081 #agent进程端口号(不填默认8080)
![](https://i-blog.csdnimg.cn/blog_migrate/cf4b5ad37c7da89df285ed0b6eeac3b1.png)
agent申请授权后,打开stork-server web端,查看服务——>机器——>未经授权页面可以看到agent申请授权的列表
![](https://i-blog.csdnimg.cn/blog_migrate/e0e376e1406e234af79e76f9314d9a93.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3b749e0731de49673656eaa2a614bf1a.png)
授权成功
授权成功后,server web端显示无法获取计算机状态,原因是agent没有正常运行导致。
ps:因为server和agent两个程序安装在一个服务器上,(因上面修改agent端口未生效导致)所以使用第二中方案,使用stork-agent --port [端口] 进行指定端口运行agent程序(此命令运行程序占用一个终端)
![](https://i-blog.csdnimg.cn/blog_migrate/e3c2cef5bec941ab0299521b1e525839.png)
root@zhou-virtual-machine:~# stork-agent --port 8081 #指定agent以8081端口运行
![](https://i-blog.csdnimg.cn/blog_migrate/870f945f04802a2fae03f4810b120347.png)
计算机状态恢复正常,显示主机名、kea进程、服务器状态等
hooks库扩展
以上操作完成后,实现了kea与stork之间的互动,但是目前的功能投入实际生产环境还是远远不够的。
比如:创建的地址池,显示地址池数量与分配的IP数,与我本身设置的不对应。
![](https://i-blog.csdnimg.cn/blog_migrate/c67af937e59e44c18bb948b6509c253d.png)
查看配置审查报告(如下图)
![](https://i-blog.csdnimg.cn/blog_migrate/e682af2be4c73a9062e1915be91c5bbf.png)
libdhcp_stat_cmds 库提供用于检索Kea DHCP服务器的准确DHCP租约统计信息的命令。Stork发送这些命令以获取仪表板、子网和共享网络视图中显示的租赁统计信息。
所以需要在kea-dhcpv4配置文件里,添加libdhcp_stat_cmds 库
查看配置文件kea的hooks库的路径为/usr/local/lib/kea/hooks/
![](https://i-blog.csdnimg.cn/blog_migrate/71a30601faac36899795288ecac7da55.png)
root@zhou-virtual-machine:~# ls /usr/local/lib/kea/hooks/
libdhcp_bootp.a libdhcp_flex_option.a libdhcp_ha.a libdhcp_lease_cmds.a libdhcp_mysql_cb.a libdhcp_run_script.a libdhcp_stat_cmds.a
libdhcp_bootp.la libdhcp_flex_option.la libdhcp_ha.la libdhcp_lease_cmds.la libdhcp_mysql_cb.la libdhcp_run_script.la libdhcp_stat_cmds.la
libdhcp_bootp.so libdhcp_flex_option.so libdhcp_ha.so libdhcp_lease_cmds.so libdhcp_mysql_cb.so libdhcp_run_script.so libdhcp_stat_cmds.so
修改kea-dhcpv4配置文件添加hooks库
vim /usr/local/etc/kea/kea-dhcp4.conf
…………
"Dhcp4": {
"server-tag": "my DHCPv4 server",
"config-control": {
"config-databases": [{
"type": "mysql",
"name": "keadhcp",
"user": "keadhcp",
"password": "keadhcp",
"host": "localhost",
"port": 3306
}],
"config-fetch-wait-time": 20
},
"hooks-libraries": [
{
"library": "/usr/local/lib/kea/hooks/libdhcp_mysql_cb.so" #后端配置库
},
{
"library": "/usr/local/lib/kea/hooks/libdhcp_stat_cmds.so" #libdhcp_stat_cmds库
},
{
"library": "/usr/local/lib/kea/hooks/libdhcp_lease_cmds.so" #测试功能
}
],
"interfaces-config": {
"interfaces": [
"ens33/192.168.4.10"
]
},
…………
重启kea-dhcp服务后查看stork-server界面
root@zhou-virtual-machine:~# keactrl stop
root@zhou-virtual-machine:~# keactrl start
![](https://i-blog.csdnimg.cn/blog_migrate/9f8637b59e9a7b3e741f94eb3c60789b.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2d2d0961cd9506bdc57e8529df89fbd7.png)
显示IP分配情况、以及IP使用率
总结:
kea有很多hooks库来扩展功能需要,研究官网文档16章节Hooks Libraries来扩展功能
不清楚是自身能力问题还是软件开发有bug,搭建起来遇到很多问题;
如stork-server不能正常使用systemctl命令运行、stork-agent修改配置文件更改端口无效、以及stork子网地址池数量与实际地址池数不一致;这些问题还需要仔细研究。
目前自己只将kea-DHCP研究到这里,创作不易,如果对你有所帮助,可以一块研究学习。
整理数天,实属不易;记得收藏点赞@_@