coredns 编译模式添加插件
备注:
coredns 默认已经安装了一些插件,比如大家用的多的kubernetes etcd ... 但是我们可以自己编译插件,构建我们自己的
coredns 版本,方便集成使用
1. 项目结构
├── Corefile
├── coredns.go
2. 参考代码
a. main.go
package main
import (
_ "github.com/coredns/example"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/etcd"
_ "github.com/coredns/coredns/plugin/federation"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/kubernetes"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/nsid"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reload"
_ "github.com/coredns/coredns/plugin/reverse"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/route53"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/template"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/trace"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/coredns/example"
_ "github.com/coredns/forward"
_ "github.com/mholt/caddy/onevent"
_ "github.com/mholt/caddy/startupshutdown"
_ "github.com/arvancloud/redis"
"github.com/coredns/coredns/core/dnsserver"
)
var directives = []string{
"example",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"trace",
"health",
"pprof",
"prometheus",
"errors",
"log",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"reverse",
"template",
"hosts",
"route53",
"federation",
"kubernetes",
"file",
"auto",
"secondary",
"etcd",
"redis",
"forward",
"proxy",
"erratic",
"whoami",
"on",
"startup",
"shutdown",
}
func init() {
dnsserver.Directives = directives
}
func main() {
coremain.Run()
}
b. Corefile
example.com {
proxy . 8.8.8.8:53
log
example
}
3. 代码说明
a. main.go
为集成全部插件,我使用了 coredns 源码中的plugins 配置代码里面包含了默认的全部,同时我添加了
官方的example 以及一个redis 插件
b. Corefile
配置文件使用已有的插件 example
4. 构建
a. 依赖包安装
简答的方式是使用源码包中的make 脚本,对于没有的使用go get 进行安装
b. 构建
go build
c. 查看编译的插件
./main -plugins
Password:
Server types:
dns
Caddyfile loaders:
flag
default
Other plugins:
dns.auto
dns.autopath
dns.bind
dns.cache
dns.chaos
dns.debug
dns.dnssec
dns.dnstap
dns.erratic
dns.errors
dns.etcd
dns.example
dns.federation
dns.file
dns.forward
dns.health
dns.hosts
dns.kubernetes
dns.loadbalance
dns.log
dns.nsid
dns.pprof
dns.prometheus
dns.proxy
dns.redis
dns.reload
dns.reverse
dns.rewrite
dns.root
dns.route53
dns.secondary
dns.template
dns.tls
dns.trace
dns.whoami
on
shutdown
startup
5. 运行
sudo ./main -conf Corefile
参考日志:
example.com.:53
2018/02/02 22:32:12 [INFO] CoreDNS-1.0.5
2018/02/02 22:32:12 [INFO] darwin/amd64, go1.9.3,
CoreDNS-1.0.5
darwin/amd64, go1.9.3,
2018/02/02 22:32:12 [INFO] "A IN connpm.gj.qq.com." - No such zone at dns://:53 (Remote: 192.168.31.161:59752)
2018/02/02 22:32:41 [INFO] "A IN www.thoughtworks.com." - No such zone at dns://:53 (Remote: 192.168.31.161:52965)
2018/02/02 22:32:45 [INFO] "A IN static.thoughtworks.com." - No such zone at dns://:53 (Remote: 192.168.31.161:54903)
2018/02/02 22:32:45 [INFO] "A IN s7.addthis.com." - No such zone at dns://:53 (Remote: 192.168.31.161:63212)
2018/02/02 22:32:45 [INFO] "A IN qzonestyle.gtimg.cn." - No such zone at dns://:53 (Remote: 192.168.31.161:54212)
2018/02/02 22:32:45 [INFO] "A IN app-e.marketo.com." - No such zone at dns://:53 (Remote: 192.168.31.161:62861)
2018/02/02 22:32:45 [INFO] "A IN dynamic.thoughtworks.com." - No such zone at dns://:53 (Remote: 192.168.31.161:54761)
2018/02/02 22:3
。。。。。
6. 参考资料
https://github.com/coredns/example
https://github.com/arvancloud/redis
https://github.com/coredns/coredns
https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)