备注:

   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/
 
 
 
 
05-11 08:12