[Zabbix] Zabbix에서 named 모니터링하기

개요

Zabbix Server에서 named의 쿼리를 모니터링을 어떻게 하면 될까? bind의 통계 기능을 zabbix-agent가 긁어서 zabbix server에 쌓는 방법을 알아보자.

구성

  • Zabbix Server 6.x
  • Zabbix Agent
  • Rocky 8.x(Named 서버)
  • Bind 9.x

설정 방법

1. named 설정

우선 named의 통계기능을 활성화하여야 한다. bind가 받는 쿼리에 대한 통계를 HTTP GET(localhost:8053)에 응답하도록 설정하자.

/etc/named.conf에 아래 설정을 추가한 후 named를 재시작한다.

statistics-channels {
inet 127.0.0.1 port 8053 allow { 127.0.0.1; };
};

2. zabbix-agent 설정

named 서버의 통계를 Zabbix Server가 가져갈 수 있도록 zabbix agent의 설정을 변경한다. zabbix_agentd.conf에 아래 설정을 추가한다. zabbix server에서 날아오는 요청을 bind로 던져서(localhost:8053) 긁은 후 서버로 다시 던져준다.

UserParameter=bind.net.udp,netstat -nua | grep :53 | wc -l
UserParameter=bind.net.tcp,netstat -nta | grep :53 | wc -l
UserParameter=bind.queries.in[*],curl http://127.0.0.1:8053/ 2>/dev/null | xml2 | grep -A1 "/statistics/server/counters/counter/@name=$1$" | tail -1 | cut -d= -f2
UserParameter=bind.queries.out[*],curl http://127.0.0.1:8053/ 2>/dev/null | xml2 | grep -A1 "/statistics/views/view/counters/counter/@name=$1$" | tail -1 | cut -d= -f2
UserParameter=bind.queries.query[*],curl http://127.0.0.1:8053/ 2>/dev/null | xml2 | grep -A1 "/statistics/server/counters/counter/@name=Qry$1$" | tail -1 | cut -d= -f2

3. xml2 설치

2번의 설정을 보면 xml2를 사용하는데 Rocky 8에서 Bind를 운영 중이므로 아래 방법을 통하여 xml2를 설치해준다.

dnf install https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/x/xml2-0.5-7.el7.x86_64.rpm

https://github.com/zabbix/community-templates/issues/73

4. selinux 설정

계속 no data가 나와서 살펴보니 selinux 문제였다. bind에서 8053을 http 포트로 사용하는데 zabbix agent에서 curl로 값을 땡겨가려고 하면 selinux에 막힌다. (/var/log/messages나 audit쪽 로그를 보면 확인 가능) tcp 8053포트를 http_port_t에 추가하자.

semanage port -a -t http_port_t -p tcp 8053

5. 서버 템플릿 추가

자빅스 서버에 템플릿이 설정된 아래 yaml 파일을 import한다. https://github.com/zabbix/community-templates/blob/main/Applications/DNS/template_bind_stat/6.0/template_bind_stat.yaml

6. bind서버에 template추가

모니터링하고 있는 bind 서버에 template을 추가해준다. 그리고 그래프를 보면 bind로 들어오는 다양한 쿼리가 몇개나 들어오고(IN) 밖으로 요청하는지(OUT) 확인할 수 있다.

7. 끝

끝.

참조

https://www.zabbix.com/integrations/dns https://github.com/zabbix/community-templates/issues/73