小知识,大挑战!本文正在参与“程序员必备小知识”创作活动
说明:因公司有频繁私有化部署需求,CI跑完后还需要手动在Bind9增加A记录,现使用CoreDNS+Etcd做内部DNS服务器,在部署任务完成后,部署工具根据jira提交内容完成Etcd数据插入
环境说明
- Etcd使用Yum安装
- CoreDNS
大体步骤
- 安装etcd
- 安装coredns
- coredns使用etcd作为数据来源
实施
- 安装etcd
yum install -y etcd
systemctl start etcd
复制代码
- 安装coredns
# 编写systemd文件
vim /etc/systemd/system/coredns.service
[Unit]
Description=CoreDNS
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
PermissionsStartOnly=true
LimitNOFILE=1048576
LimitNPROC=512
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=true
User=root
ExecStart=/usr/bin/coredns -conf=/etc/coredns/Corefile
ExecReload=/bin/kill -SIGUSR1 $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 下载coredns
wget https://github.com/coredns/coredns/releases/download/v1.8.4/coredns_1.8.4_linux_amd64.tgz
tar zxf coredns_1.8.4_linux_amd64.tgz -C /usr/bin/
复制代码
- coredns配置
新建/etc/coredns/Corefile文件
.:53 {
health
log
errors
cache 30
reload 10s
forward . 223.5.5.5 8.8.8.8
}
hive-intel.qa:53 {
etcd {
stubzones
path /coredns
endpoint http://127.0.0.1:2379 #etcd地址:端口
upstream 223.5.5.5:53 8.8.8.8:53 /etc/resolv.conf
}
template IN A hicloud.hive-intel.qa {
match .*\.hicloud\.hive-intel\.qa
answer "{{ .Name }} 60 IN A 172.168.1.224"
fallthrough
}
template IN A testhicloud.hive-intel.qa {
match .*\.testhicloud\.hive-intel\.qa
answer "{{ .Name }} 60 IN A 172.168.1.224"
fallthrough
}
health
log
errors
cache 30
reload 10s
}
hive-intel.devop:53 {
etcd {
stubzones
path /coredns
endpoint http://127.0.0.1:2379
upstream 223.5.5.5:53 8.8.8.8:53 /etc/resolv.conf
}
template IN A hicloud.hive-intel.devop {
match .*\.hicloud\.hive-intel\.devop
answer "{{ .Name }} 60 IN A 172.168.1.224"
fallthrough
}
health
log
errors
cache 30
reload 10s
}
localserver.hivetech.iego.net:53 {
etcd {
stubzones
path /coredns
endpoint http://127.0.0.1:2379
upstream 223.5.5.5:53 8.8.8.8:53 /etc/resolv.conf
}
health
log
errors
cache 30
reload 10s
}
复制代码
- 启动
systemctl enable coredns
systemctl start coredns
systemctl status coredns
复制代码