部署
本文继续介绍named的监控部署工作,部署named所需的监控exporter需要一些前置条件:
- 之前编译安装的时候必须携带参数libxml2,如果没有看过之前的文章写点击[跨region的智能DNS解决方案(一)]
检查命令如下:
/opt/soft/named/sbin/named -V|grep libxml2
built by make with '--prefix=/opt/soft/named' '--sbindir=/opt/soft/named/sbin/' '--bindir=/opt/soft/named/bin/' 'CFLAGS=-g -fPIC' '--enable-threads' '--with-openssl=yes' '--with-libjson=no' '--with-libxml2=yes'
compiled with libxml2 version: 2.9.1
linked to libxml2 version: 20901
- 安装go语言
yum install golang -y
- 安装bind_exporter
go get github.com/digitalocean/bind_exporter
cd $GOPATH/src/github.com/digitalocean/bind_exporter
# 如果go get 不成功,建议通过git clone把源码down到本地,然后通过go build 直接编译。
- 安装Prometheus Server grafana dashborad
简易安装 本文通过docker-compose 直接安装promethues以及grafana
git地址:https://github.com/vegasbrianc/prometheus
下文所需编辑的promethues.yaml所在路径为项目当前目录下
/root/prometheus/prometheus/prometheus.yml
设置 BIND DNS server
echo >> /etc/named/named.conf << EOF
statistics-channels {
inet 127.0.0.1 port 8053 allow { 127.0.0.1; };
};
EOF
创建Bind Exported systemd 服务
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
echo >> /etc/systemd/system/bind_exporter.service << EOF
[Unit]
Description=Prometheus
Documentation=https://github.com/digitalocean/bind_exporter
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/bind_exporter \
--bind.pid-file=/var/run/named/named.pid \
--bind.timeout=20s \
--web.listen-address=0.0.0.0:9153 \
--web.telemetry-path=/metrics \
--bind.stats-url=http://localhost:8053/ \
--bind.stats-groups=server,view,tasks
SyslogIdentifier=prometheus
Restart=always
[Install]
WantedBy=multi-user.target
EOF
启动服务
sudo systemctl daemon-reload
sudo systemctl restart bind_exporter.service
调试启动
./bind_exporter
INFO[0000] Starting bind_exporter (version=, branch=, revision=) source="bind_exporter.go:477"
INFO[0000] Build context (go=go1.13, user=, date=) source="bind_exporter.go:478"
INFO[0000] Configured to collect statistics "server,view" source="bind_exporter.go:479"
INFO[0000] Starting Server: :9119 source="bind_exporter.go:501"
开机自启动
sudo systemctl enable bind_exporter.service
Created symlink from /etc/systemd/system/multi-user.target.wants/bind_exporter.service to /etc/systemd/system/bind_exporter.service.
Confirm that the service is listening on port 9153 as configured
配置Prometheus服务
添加一个job 请注意promethues是严格缩进的 端口是9119 很多文章实践给的是其他端口如9153
- job_name: dns-master
static_configs:
- targets: ['10.1.0.100:9119']
labels:
alias: dns-master
重启promethues服务
添加grafana dashboard
dashboard 由Cristian Calin提供
ID为1666可以直接下载并添加数据源即可使用。
最终图表展示
上面可以看到所有view(区域的)各个操作行为,执行时间等,非常详细。
至此,通过named服务完成了跨region同一域名解析到不同ip地址包括增删改查、监控在内的全套流程。