核心内容摘要
HY-Motion 1.0精彩案例:从‘stretch arms’生成肩胛骨运动与胸廓扩张
CoreDNS基本概念
CoreDNS概述CoreDNS 是 CNCF云原生计算基金会毕业的开源 DNS 服务器由 Miek Gieben 主导开发基于 Go 语言实现是云原生时代 kube-dns 的替代方案同时也可作为通用 DNS 服务独立部署。
其核心设计理念是「插件化、极简配置、云原生原生适配」既兼容传统 DNS 场景又能完美适配容器、K8s 等动态环境。
独立运行作为独立守护进程常驻内存监听 53 端口DNS 默认端口无需依附任何其他服务插件化扩展通过插件实现健康检查、域名重写、缓存、转发等功能配置极简多场景适配既支持传统内网域名的静态解析也支持云原生环境的动态服务发现热重载修改配置后无需重启进程通过信号量即可重载配置无服务中断。
与传统的DNS软件对比特性CoreDNSBindUnbound架构设计插件化、单进程、轻量模块化、多进程、重量级单进程、专注递归、轻量云原生适配原生支持 K8s/ETCD无原生支持无原生支持健康检查内置health插件需第三方脚本需第三方工具联动配置复杂度Corefile 声明式多配置文件专注递归动态能力插件化动态解析如 K8s静态配置为主静态 / 转发为主热重载原生支持SIGUSR1 信号支持但配置复杂支持unbound-control资源占用极低MB 级内存较高GB 级内存低MB 级监控能力内置prometheus插件需额外配置需额外配置
CoreDNS核心架构模型CoreDNS的核心是「插件链Corefile配置」。
所有功能均通过插件实现配置文件定义插件的执行顺序和规则。
插件链执行逻辑请求按Corefile中插件的声明顺序依次执行插件可决定终止请求返回结果或传递给下一个插件。
插件优先级核心基础插件如 log/errors通常放在最前业务插件如 hosts/kubernetes居中兜底插件如 forward/rewrite放在最后。
Corefile语法解析Corefile是CoreDNS的唯一配置文件采用【域插件块】的声明式语法格式极简。
域名[:端口] { 插件1[插件参数] 插件1[插件参数] ... }极简配置案例所有域名监听 53 端口.:53 { bind
0.
0.
0 # 绑定所有网卡 log # 记录查询日志 hosts { # 静态解析
192.
168.
1 www.meaauf.com } forward .
8.
8.
8 # 未匹配的域名转发到谷歌 DNS cache 60 # 缓存 60 秒 }
基础类插件介绍插件类核心功能示例bind指定监听的网卡 / 端口bind
192.
168.
10log记录所有DNS查询日志如客户端IP、域名、查询类型、响应状态等log【无需参数】errors记录解析过程中的错误日志如域名不存在、后端服务异常errors【无需参数】cache缓存解析结果减少重复查询提升性能cache 60【缓存60秒】reload支持配置热重载修改Corefile后自动重载无需重启进程reload【无需参数】
解析类插件介绍插件类核心功能示例hosts静态解析域名hosts {
192.
168.
1 www.meaauf.com;}forward将域名查询转发到上游DNS服务器forward
114.
114.
1
114kubernetesK8s 集群内域名解析kubernets cluster.loacal in-addr.arpa ip
arpa { pods verified; fallthrough}file从Zone文件Bind 格式读取解析记录兼容传统DNS配置file /etc/coredns/meaauf.zone
CoreDNS部署
二进制方式部署[Step1]访问CoreDNS的官网或GitHub下载CoreDNS二进制包。
官网https://coredns.io GitHubhttps://github.com/coredns/coredns/releases[Step2]将软件包上传到CoreDNS。
[Step3]将coredns解压缩解压出来的是一个二进制命令。
[rootCoreDNS ~]# tar zxf coredns_
1.
1
1_linux_amd
tgz[Step4]确保coredns命令具备执行权限将其移动到“/usr/local/bin”目录。
[rootCoreDNS ~]# chmod x coredns [rootCoreDNS ~]# mv coredns /usr/local/bin/[Step5]验证输出coredns的版本号。
[rootCoreDNS ~]# coredns -version
Docker方式部署[Step1]确保本地Docker服务状态正常。
[rootCoreDNS ~]# systemctl status docker.service[Step2]拉取官方镜像。
[rootCoreDNS ~]# docker pull coredns/coredns:latest[Step3]临时启动一个 CoreDNS 容器查看其版本信息并且容器运行结束后自动删除。
[rootCoreDNS ~]# docker run --rm coredns/coredns -version
传统内网静态解析案例配置
节点设置主机名网络参数系统版本说明CoreDNS
192.
168.
100/24Kylin Linux Advanced Server V11 (Swan
DNS服务器Client
192.
168.
200/24Kylin Linux Advanced Server V11 (Swan
测试客户端
CoreDNS服务器配置[Step1]安装coredns以下使用二进制安装方式。
[rootCoreDNS ~]# coredns -version[Step2]创建配置文件目录编写Corefile。
[rootCoreDNS ~]# mkdir /etc/coredns [rootCoreDNS ~]# vim /etc/coredns/Corefile # 写入下列内容 .:53 { bind
192.
168.
100 # 仅监听指定网卡增强安全性 log # 记录所有 DNS 查询日志 errors # 记录错误日志 reload # 支持配置热重载 # 静态解析域名 hosts {
192.
168.
100 coredns.meaauf.com
192.
168.
101 www.meaauf.com
192.
168.
200 client.meaauf.com } cache 60 # 缓存优化 }[Step3]启动coredns同时观察回显日志。
[rootCoreDNS ~]# coredns -conf /etc/coredns/Corefile
客户端验证[Step1]验证使用nslookup测试正向解析该命令需要先安装bind-utils。
[rootclient ~]# dnf install -y bind-utils [rootclient ~]# nslookup coredns.meaauf.com [rootclient ~]# nslookup www.meaauf.com [rootclient ~]# nslookup client.meaauf.com[Step2]验证使用nslookup测试反向解析。
[rootclient ~]# nslookup
192.
168.
100 [rootclient ~]# nslookup
192.
168.
101 [rootclient ~]# nslookup
192.
168.
200[Step3]验证在CoreDNS上查看日志信息能够看到刚刚的解析记录。
系统服务部署[Step1]在CoreDNS服务器上创建CoreDNS systemd服务文件。
[rootCoreDNS ~]# vim /etc/systemd/system/coredns.service # 写入下列内容 [Unit] DescriptionCoreDNS DNS Server Documentationhttps://coredns.io Afternetwork.target network-online.target Wantsnetwork-online.target [Service] Userroot Grouproot ExecStart/usr/local/bin/coredns -conf /etc/coredns/Corefile Restarton-failure RestartSec5s StartLimitInterval0 StandardOutputjournal StandardErrorjournal SyslogIdentifiercoredns Nice-5 [Install] WantedBymulti-user.target[Step2]在CoreDNS服务器重新加载systemd配置启动CoreDNS服务并设置开机自启。
[rootCoreDNS ~]# systemctl daemon-reload [rootCoreDNS ~]# systemctl enable --now coredns.service
搭配file模块实现静态解析
节点设置主机名网络参数系统版本说明CoreDNS
192.
168.
100/24Kylin Linux Advanced Server V11 (Swan
DNS服务器Client
192.
168.
200/24Kylin Linux Advanced Server V11 (Swan
测试客户端
CoreDNS服务器配置[Step1]安装coredns以下使用二进制安装方式。
[Step2]创建配置文件目录编写Corefile。
[rootCoreDNS ~]# mkdir /etc/coredns [rootCoreDNS ~]# vim /etc/coredns/Corefile # 写入下列内容 .:53 { bind
192.
168.
100 # 仅监听指定网卡增强安全性 log # 记录所有 DNS 查询日志 errors # 记录错误日志 reload # 支持配置热重载 # 使用file插件加载解析规则替代hosts file /etc/coredns/zones/meaauf.db cache 60 # 缓存优化 }[Step3]编写“meaauf.db”文件类似于Bind的解析文件。
[rootCoreDNS ~]# mkdir /etc/coredns/zones [rootCoreDNS ~]# vim /etc/coredns/zones/meaauf.db # 写入下列内容 $TTL 1D IN SOA rname.invalid. ( 2026012701 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum coredns.meaauf.com. IN A
192.
168.
100 www.meaauf.com. IN A
192.
168.
101 client.meaauf.com. IN A
192.
168.
200[Step4]编写systemd服务文件编写systemd服务文件的过程省略。
启动coredns服务。
[rootCoreDNS ~]# systemctl restart coredns.service
客户端验证[Step1]验证使用nslookup测试正向解析该命令需要先安装bind-utils。
[rootclient ~]# dnf install -y bind-utils [rootclient ~]# nslookup coredns.meaauf.com [rootclient ~]# nslookup www.meaauf.com [rootclient ~]# nslookup client.meaauf.com