引用文档里面的一句话,大概意思是要在编译时加--enable-cachedb参数

The Cache DB module must be configured in the module-config:
directive, e.g.: module-config: "validator cachedb iterator" and be
compiled into the daemon with --enable-cachedb.

我尝试了很多遍,unbound正常启动也能正常解析,redis里面就是没有数据直到今天我才看明白,下面就直接开始了

安装依赖

  • 全新编译和已安装再编译一样的
  • 这里讲下yum和apt如何去安装这个依赖
#apt(这个我没去尝试有问题自行百度)
apt install libhiredis-dev
#yum
yum install hiredis
yum install hiredis-devel

编译unbound

./configure --enable-subnet --with-libevent --with-libhiredis --enable-cachedb
  • 这里吐槽一下因为之前尝试少了--with-libhiredis所以一直没成功
  • 这里是建立在已经安装好redis的情况下
  • 没安装redis也可以尝试一下先编译unbound再安装redis

unbound redis配置

cachedb:
    backend: redis
    redis-server-host: 127.0.0.1
    redis-server-port: 6379
    redis-timeout: 100
    redis-expire-records: yes

这里需要注意一下,在module-config中要添加cachedb(例:module-config: "subnetcache validator cachedb iterator")

其它

redis-expire-records是用来控制redis里面数据有效期的,no代表永久缓存不过期
redis-expire-records配置为yes的时候注意,需要在sever:这个大板块里面加上以下参数.

server:
    verbosity: 1
    interface: 0.0.0.0
    port: 53
    do-ip4: yes
    do-udp: yes
    do-tcp: yes
    #do-ip6: yes
    access-control: 0.0.0.0/0 allow
    root-hints: "root.hints"
    send-client-subnet: 0.0.0.0/0
    harden-glue: yes
    .......
    # 通过下面两个参数就可以控制redis里面数据过期时间了(86400等于一天)
    serve-expired: yes 
    serve-expired-ttl: 86400

暂时没其它的了,等想到了再补充吧