部署
本文繼續介紹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位址包括增删改查、監控在内的全套流程。
