티스토리 뷰
참고 : 이 문서는 완성된 문서가 아니며, 개발자 입장에서 작성 되어 정확 하지 않을수 있으며 가장 기본적인 설정만 다룰 것이다. 상세한 설정은 zabbix 홈페이지(메뉴얼이 굉장히 잘 되어 있음) 또는 정리가 잘 된 다른 사이트나 블로그를 이용.
참고 : zabbix 와 prometheus 두가지를 가지고 고민 하던중, 설정이 매우 간편 하다는 점과, 내가 가진 서버 사양이 좋지 않다는 점과 아이폰, 아이패드 환경 에서도 모니터링이 가능한 ZBX Viewer 가 있는 zabbix 를 선택 하게 되었다. ZBX Viewer 홈페이지를 보니 현재(2021.10.26) 안드로이드 계열 디바이스는 지원 하지 않는 것으로 보인다.
1. 시스템 구성도
내 상황에서는 위와 같이 구성할 것이다. 구성이 조금 이상해 보인다. 개인적으로 zabbix-proxy-server 를 이용하여 내 개인 서버와 회사 서버를 모니터링을 테스트 해보고 싶었기 때문에 위와 같이 이상하게 구성이 되었다.
아이피 주소 | 역할 |
192.168.0.1~19 | Zabbix Agent |
192.168.0.20 | Zabbix Proxy Server Zabbix Frontend Server Zabbix Agent MySQL Server Nginx Server |
192.168.0.30 | Zabbix Frontend Server Zabbix Agent Nginx Server |
192.168.0.40 | MySQL Server Zabbix Agent |
모니터링 대상의 노드에는 Zabbix Agent 가 설치 되어야 한다.
2. Zabbix Package Download
https://www.zabbix.com/download 에 접속 하여 서버에 맞는 레파지토리 패키지를 다운로드 한다.
# wget https://repo.zabbix.com/zabbix/5.4/debian/pool/main/z/zabbix-release/zabbix-release_5.4-1+debian10_all.deb # dpkg -i zabbix-release_5.4-1+debian10_all.deb # apt update # rm -rf zabbix-release_5.4-1+debian10_all.deb |
모니터링 대상 및 서버의 모든 노드 에서 Zabbix 의 repository 정보가 들어 있는 패키지를 설치 한다.
참고 : 이 문서에서의 '모니터링 대상의 모든 노드' = 192.168.0.1~19, 192.168.0.20, 192.168.0.30, 192.168.0.40
3. MySQL 서버에 사용자, 데이터베이스 생성 및 zabbix-agent 설치, 설정
이미, 192.168.0.40 서버에 MySQL 서버가 설치 되었다는 가정 하에 진행 하도록 한다.
192.168.0.40 서버에 MySQL Server, Zabbix Agent 를 설치 하고 Zabbix Frontend Server(192.168.0.30), Zabbix Proxy Server(192.168.0.20) 에서 사용할 데이터베이스를 생성해 주는 단계.
# zabbix repository package 설치 - 이 문서 윗부분에서 설치 했다면 건너 뛰도록 한다. root@192.168.0.40# wget https://repo.zabbix.com/zabbix/5.4/debian/pool/main/z/zabbix-release/zabbix-release_5.4-1+debian10_all.deb root@192.168.0.40# dpkg -i ./zabbix-release_5.4-1+debian10_all.deb root@192.168.0.40# apt update root@192.168.0.40# rm -rf ./zabbix-release_5.4-1+debian10_all.deb root@192.168.0.40# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 28187 Server version: 8.0.26 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.26 | +-----------+ 1 row in set (0.00 sec) # zabbix server 에서 사용할 데이터베이스 생성 mysql> create database zabbix character set utf8 collate utf8_bin; # zabbix proxy server 에서 사용할 데이터베이스 생성 mysql> create database zabbix_proxy character set utf8 collate utf8_bin; # zabbix 기초 테이블 스크립트를 밀어 넣기 위해 localhost 계정 생성. 스크립트 실행 후, 삭제 처리 할 것. mysql> create user zabbix@localhost identified by 'P@ssW0rd'; # zabbix frontend server 에서 사용할 계정 생성 mysql> create user zabbix@'192.168.0.30' identified by 'P@ssW0rd'; # zabbix proxy server 에서 사용할 계정 생성 mysql>create user zabbix@'192.168.0.20' identified by 'P@ssW0rd'; # 스크립트를 밀어 넣기 위해 zabbix 사용자에게 zabbix, zabbix_proxy 데이터베이스의 권한 부여 mysql> grant all privileges on zabbix.* to zabbix@localhost; mysql> grant all privileges on zabbix.* to zabbix@'192.168.0.30'; mysql> grant all privileges on zabbix_proxy.* to zabbix@localhost; mysql> grant all privileges on zabbix_proxy.* to zabbix@'192.168.0.20'; mysql> flush privileges; mysql> quit; root@192.168.0.40# apt install zabbix-sql-scripts root@192.168.0.40# cd /usr/share/doc/zabbix-sql-scripts/mysql root@192.168.0.40# ls create.sql.gz double.sql schema.sql root@192.168.0.40# gunzip create.sql.gz root@192.168.0.40# ls create.sql double.sql schema.sql root@192.168.0.40# mysql -uzabbix -p < create.sql Enter password: * 참고 : 서버 성능이 좋지 않아 이 단계에서 약 40분 정도 시간이 소요 됨. root@192.168.0.40# mysql -uzabbix -p < schema.sql Enter password: * 참고 : 서버 성능이 좋지 않아 이 단계에서 약 40분 정도 시간이 소요 됨. root@192.168.0.40# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 28187 Server version: 8.0.26 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # zabbix@localhost 사용자 삭제 mysql> drop user zabbix@localhost; mysql> flush privileges; mysql> quit; |
MySQL 서버인 192.168.0.40 서버도 모니터링 대상 노드 이기 때문에, zabbix-agent 를 설치해 준다.
root@192.168.0.40# apt install zabbix-agent root@192.168.0.40# cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.ori root@192.168.0.40# vi /etc/zabbix/zabbix_agentd.conf Server=192.168.0.30 Hostname=freecatz-mysql root@192.168.0.40# service zabbix-agent restart root@192.168.0.40# systemctl enable zabbix-agent |
Hostname 의 경우 zabbix frontend server(192.168.0.30) 에 등록시 사용 하며, 실제 서버의 호스트네임과 동일하게 설정 하면 좋으나, 각자 구분 하기 편한대로 작성 한다.
4. zabbix frontend server, zabbix agent, nginx 설치 및 설정
192.168.0.30 이 서버에서는 nginx 서버와 zabbix web UI 를 보여주는 zabbix frontend server 를 구성 할 것 이다.
아울러, 이 서버 역시 모니터링 대상이므로 zabbix agent 를 설치 합니다. DNS 설정을 상황에 맞게 변경 해야 할 수도 있다.
# zabbix repository package 설치 - 이 문서 윗부분에서 설치 했다면 건너 뛰도록 한다. root@192.168.0.30# wget https://repo.zabbix.com/zabbix/5.4/debian/pool/main/z/zabbix-release/zabbix-release_5.4-1+debian10_all.deb root@192.168.0.30# dpkg -i ./zabbix-release_5.4-1+debian10_all.deb root@192.168.0.30# apt update root@192.168.0.30# rm -rf ./zabbix-release_5.4-1+debian10_all.deb root@192.168.0.30# apt install nginx zabbix-frontend-php zabbix-agent root@192.168.0.30# vi /etc/nginx/sites-available/zabbix.freecatz.pe.kr server { listen 80; root /usr/share/zabbix; index index.php index.html index.htm; server_name zabbix.freecatz.pe.kr; location / { try_files $uri $uri/ =404; } location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; } } root@192.168.0.30# ln -s /etc/nginx/sites-available/zabbix.freecatz.pe.kr /etc/nginx/sites-enabled/ root@192.168.0.30# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful root@192.168.0.30# /etc/init.d/nginx restart root@192.168.0.30# systemctl enable nginx php7.3-fpm root@192.168.0.30# cp /etc/zabbix/zabbix_agent.conf /etc/zabbix/zabbix_agent.conf.ori root@192.168.0.30# vi /etc/zabbix/zabbix_agent.conf Server=127.0.0.1 ServerActive=127.0.0.1 Hostname=freecatz-web root@192.168.0.30# cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.ori root@192.168.0.30# vi /etc/zabbix/zabbix_server.conf DBHost=192.168.0.40 DBName=zabbix DBUser=zabbix DBPassword=P@ssW0rd DBPort=3306 root@192.168.0.30# /etc/init.d/zabbix-server restart root@192.168.0.30# /etc/init.d/zabbix-agent restart root@192.168.0.30# systemctl enable zabbix-server zabbix-agent |
5. 방화벽 내부의 zabbix proxy server 설치 및 설정
192.168.0.20 이 서버는 역할이 가장 많은 서버다. 방화벽 내부의 노드들을 모니터링 하고, 로컬의 MySQL 서버에 데이터를 적재 시키고, Zabbix Proxy 로 192.168.0.30 서버와 통신 하며, 192.168.0.40 의 MySQL 서버의 zabbix 계정으로 zabbix_proxy 테이블에 데이터를 기록 한다. 이 서버의 일부 포트가 외부와 연결 가능 하도록 운영체제 방화벽 또는 물리 방화벽 설정이 필요 하다.
서비스 | 포트 | 타입 |
Nginx | 80 | TCP |
MySQL | 3306 | TCP |
Zabbix Agent | 10050 | TCP |
Zabbix Server | 10051 | TCP |
Zabbix Proxy Listen | 10052 | TCP |
* 참고
Active 설정인 경우 Agent 에서 Server 로 데이터를 전송 하며 이때 TCP 10051 포트를 사용 한다고 한다.
Passive 설정(기본값)인 경우 Server 에서 Agent 의 데이터를 수집 하는 형태 이며, 이때 TCP 10050 포트를 사용 한다고 한다.
아직 zabbix 에 대해서 잘 몰라서 192.168.0.20 의 zabbix proxy server 의 경우 80, 3006, 10050, 10051, 10052 포트를 오픈 하였다. 192.168.0.20 서버의 경우 개발용 서버라서 부담 없이 포트를 오픈 요청 하였고, 승낙을 받았다.
이 서버에는 MySQL 서버는 이미 설치 되어 있다고 가정 하고 나머지 Nginx, Zabbix Frontend Server, Zabbix Proxy, Zabbix Agent 를 설치 할 것이다. 패키지 설치나 설정을 보면 이전 단계에서 했던 종합이라고 볼 수 있다. 단, 이 서버에 설치된 MySQL 에 zabbix_proxy 데이터베이스는 생성 하지 않는다. schema.sql 스크립트를 밀어 넣지 않는다.
# zabbix repository package 설치 - 이 문서 윗부분에서 설치 했다면 건너 뛰도록 한다. root@192.168.0.20# wget https://repo.zabbix.com/zabbix/5.4/debian/pool/main/z/zabbix-release/zabbix-release_5.4-1+debian10_all.deb root@192.168.0.20# dpkg -i ./zabbix-release_5.4-1+debian10_all.deb root@192.168.0.20# apt update root@192.168.0.20# rm -rf ./zabbix-release_5.4-1+debian10_all.deb # 귀찮으니 이제 패키지를 한번에 설치 하자. root@192.168.0.20# apt install nginx zabbix-frontend-php zabbix-proxy-mysql zabbix-sql-scripts zabbix-agent root@192.168.0.20# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 28187 Server version: 8.0.26 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.26 | +-----------+ 1 row in set (0.00 sec) # zabbix server 에서 사용할 데이터베이스 생성 mysql> create database zabbix character set utf8 collate utf8_bin; # zabbix 기초 테이블 스크립트를 밀어 넣고, zabbix frontend server 에서 사용할 계정 생성 mysql> create user zabbix@localhost identified by 'P@ssW0rd'; # zabbix 사용자에게 zabbix 데이터베이스의 권한 부여 mysql> grant all privileges on zabbix.* to zabbix@localhost; mysql> flush privileges; mysql> quit; root@192.168.0.20# cd /usr/share/doc/zabbix-sql-scripts/mysql root@192.168.0.20# ls create.sql.gz double.sql schema.sql root@192.168.0.20# gunzip create.sql.gz root@192.168.0.20# ls create.sql double.sql schema.sql root@192.168.0.20# mysql -uzabbix -p < create.sql Enter password: * 참고 : 이 서버는 성능이 좋아 약 1분 정도 시간이 소요 됨. root@192.168.0.20# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 28187 Server version: 8.0.26 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # zabbix@localhost 사용자 삭제 mysql> drop user zabbix@localhost; mysql> flush privileges; mysql> quit; root@192.168.0.20# vi /etc/nginx/sites-available/dev.freecatz.pe.kr server { listen 80; root /usr/share/zabbix; index index.php index.html index.htm; server_name dev.freecatz.pe.kr; location / { try_files $uri $uri/ =404; } location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; } } root@192.168.0.20# ln -s /etc/nginx/sites-available/dev.freecatz.pe.kr /etc/nginx/sites-enabled/ root@192.168.0.20# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful root@192.168.0.20# /etc/init.d/nginx restart root@192.168.0.20# systemctl enable nginx php7.3-fpm root@192.168.0.20# cp /etc/zabbix/zabbix_agent.conf /etc/zabbix/zabbix_agent.conf.ori root@192.168.0.20# vi /etc/zabbix/zabbix_agent.conf Server=127.0.0.1,192.168.0.30 ServerActive=127.0.0.1 Hostname=DEV-WEB root@192.168.0.20# cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.ori root@192.168.0.20# vi /etc/zabbix/zabbix_server.conf DBHost=127.0.0.1 DBName=zabbix DBUser=zabbix DBPassword=P@ssW0rd DBPort=3306 root@192.168.0.20# cp /etc/zabbix/zabbix_proxy.conf /etc/zabbix/zabbix_proxy.conf.ori root@192.168.0.20# vi /etc/zabbix/zabbix_proxy.conf ProxyMode=0 Server=127.0.0.1,192.168.0.30 Hostname=ZABBIX-PROXY ListenPort=10052 DBHost=192.168.0.40 DBName=zabbix_proxy DBUser=zabbix DBPassword=P@ssW0rd DBPort=3306 ConfigFrequency=60 root@192.168.0.20# /etc/init.d/zabbix-server restart root@192.168.0.20# /etc/init.d/zabbix-agent restart root@192.168.0.20# /etc/init.d/zabbix-proxy restart root@192.168.0.20# systemctl enable zabbix-server zabbix-proxy zabbix-agent |
6. 모니터링 대상 노드에 Zabbix Agent 설치
# zabbix repository package 설치 - 이 문서 윗부분에서 설치 했다면 건너 뛰도록 한다. root@192.168.0.1# wget https://repo.zabbix.com/zabbix/5.4/debian/pool/main/z/zabbix-release/zabbix-release_5.4-1+debian10_all.deb root@192.168.0.1# dpkg -i ./zabbix-release_5.4-1+debian10_all.deb root@192.168.0.1# apt update root@192.168.0.1# rm -rf ./zabbix-release_5.4-1+debian10_all.deb root@192.168.0.1# apt install zabbix-agent root@192.168.0.1# cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.ori root@192.168.0.1# vi /etc/zabbix/zabbix_agentd.conf Server=192.168.0.20 Hostname=DEV-S1 root@192.168.0.1# /etc/init.d/zabbix-agent restart root@192.168.0.1# systemctl enable zabbix-agent |
위에서 Hostname 설정과 같이 구분 하기 편하고 겹치지 않게 작성 한다. 이 문서의 경우 192.168.0.1~19 까지 19개의 노드가 있으므로, DEV-S1 ~ 19 까지 설정이 되어야 한다.
모니터링 대상 노드들과 프록시 등록하는 부분을 스크린샷 첨부로 보기 편하게 하려고 하였으나, 회사 내부의 보안 지침상의 이유로 보안상의 이유로 스크린샷을 첨부 할 수가 없다.
개인적인 생각에는 스크린샷 첨부가 별 문제가 없을거라 생각 하지만, 나중에 문제가 되는 것도 싫고 보안 담당자를 설득 하기 귀찮아서 회사 내부의 보안 지침을 따르겠다.
참고 : 보안에 대해서 잘은 모르겠으나, 모든 스크린샷에 워터 마크 및 파일 헤더에 특정 데이터를 기록 하는 것으로 알려져 있음.
절대 스크린샷 찍기 귀찮아서 변명 하는건 아님. 진짜...
브라우저를 이용하여 http://192.168.0.20 서버에 접근 하여, 모니터링 대상의 192.168.0.1 ~ 19 노드들을 등록해 주어야 한다.
브라우저를 이용하여 http://192.168.0.30 서버에 접근 하여, 192.168.0.20의 프록시를 등록 하여야 한다. 프록시 등록 후, 방화벽 내부(192.168.0.1~19)의 모니터링 대상 노드들을 등록시 프록시를 선택해 등록해 주어야 한다.
이렇게 구성이 되면, 192.168.0.20 에서는 방화벽 내부의 192.168.0.1~19 노드들을 모니터링 하게 되고 수집된 데이터를 192.168.0.30 서버와 통신 하며 192.168.0.40 의 MySQL 서버의 zabbix_proxy 데이터베이스에 기록 하게 된다.
- Total
- Today
- Yesterday
- gpkiapi
- Compile
- JavaScript
- dart
- devel
- kotlin
- SSL
- Flutter
- Mobile
- development
- Security
- Android
- Linux
- place
- 맛집
- food
- web
- Java
- Fun
- samba
- json parse
- TIP
- Spring
- MySQL
- devtools
- ssh
- Review
- springboot
- 엘리스센터
- HTTP
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |