[ Zabbix - DB monitoring 서버 구축 ] part 1

요즘 DB 모니터링을 위해 Zabbix를 많이 쓴다고합니다.

 

클라우드 콘솔에서 서버단 모니터링과 notification 서비스가 있지만, 어디까지나 서버단 리소스이라 DB를 모니터링할 tool이 필요해서 사용해보았습니다. 

 

대시보드도 보기 편하고 커스터마이징이 가능하며 자체 템플릿을 많이 지원합니다. 본인에 맞는 템플릿을 써도 되고 만들어서 편하게 사용하면 됩니다!

 

얼롯팅 또한 email , telegram 등 여러 템플릿을 지원하므로 메신저까지 연동하여 얼롯팅을 받아보도록 하겠습니다.

 
 

 테스트 환경

ZABBIX SERVER(Monitoring 수집서버) : 10.70.101.80
ZABBIX Agent1(Monitoring 대상 서버) : 10.70.101.78
ZABBIX Agent2(Monitoring 대상 서버) : 10.70.101.79

 

 

 

 테스트 시작

 

■ ZABBIX server 설치 (수집서버)

#rpm 이용 zabbix 5.0 install
[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm(을)를 복구합니다
준비 중...                         ################################# [100%]
Updating / installing...
   1:zabbix-release-5.0-1.el7         ################################# [ 50%]
Cleaning up / removing...
   2:zabbix-release-3.4-2.el7         ################################# [100%]



[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-agent

[root@localhost ~]# yum -y install centos-release-scl


[root@localhost ~]# vi /etc/yum.repos.d/zabbix.repo
 
[zabbix]
name=Zabbix Official Repository - $basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1                                       => 1로 수정
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1



[root@localhost ~]# yum -y install zabbix-web-mysql-scl

[root@localhost ~]# yum -y install zabbix-apache-conf-scl
 
 

 Selinux 해제

[root@localhost selinux]# vi /etc/selinux/config
SELINUX=disabled
 
 

 DB 설치 및 설정

- Zabbix는 DB를 이용하여 서버의 정보를 저장하며, 필요에 따라 쿼리문을 통해 원하는 데이터를 추출하기 때문에 DB를 설치해야하며 zcat 명령어를 이용하여 스키마와 데이터를 초기화

 

※ 아래 config 파일 경로로 mariadb 설치 진행

##Mariadb 설치
[root@localhost bin]# vi /etc/my.cnf

[mysqld]
datadir=/data/data
socket=/var/lib/mysql/mysql.sock              => socket을 /var/lib/mysql/mysql.sock으로 설치해야합니다..
log-error=/data/log/mariadb.log
pid-file=/data/log/mariadb.pid
symbolic-links=0


[mysqld_safe]
log-error=/data/log/mariadb.log
pid-file=/data/log/mariadb.pid


!includedir /etc/my.cnf.d





## DB start
[root@localhost ~]# mysqld --user=mysql --basedir=/data/maria &
[1] 7910
[root@localhost ~]# 2021-11-23 17:39:19 139639774644032 [Note] mysqld (mysqld 10.2.12-MariaDB) starting as process 7910 ...
 
 

 Zabbix-server DB 설정 

[root@localhost tmp]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.2.12-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]> CREATE DATABASE zabbix CHARACTER SET utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user 'zabbix'@'localhost' identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on *.* to  'zabbix'@'localhost' ;
Query OK, 0 rows affected (0.00 sec)




[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix



[root@localhost ~]# vi /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix




## php 시간대 수정
[root@localhost ~]# vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Seoul


## config 수정값을 먹이기 위해 restart
[root@localhost ~]# systemctl restart rh-php72-php-fpm.service



## 모든 서비스 실행
[root@localhost ~]# systemctl start zabbix-server.service zabbix-agent.service httpd rh-php72-php-fpm.service



##FIREWALL 
10050 / 10051 허용 설정
 
 
 
 
 

 ZABBIX Agent 외부 Host에 설치

※Zabbix server(수집 서버)에도 모니터링이 필요하기때문에 해당 서버에도 Agent 설치필요. DB서버 두대만 설치해도 무방합니다.

※ 현재 agent서버(10.70.101.78/10.70.101.79)에는 mariadb10.2.12 설치 뒤 replication을 맺은 상태입니다.

MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.70.101.78
                  Master_User: test
                  Master_Port: 3306
                Connect_Retry: 10
              Master_Log_File: mysql.000001
          Read_Master_Log_Pos: 527
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 551
        Relay_Master_Log_File: mysql.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 527
              Relay_Log_Space: 860
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
               Master_SSL_Crl:
           Master_SSL_Crlpath:
                   Using_Gtid: No
                  Gtid_IO_Pos:
      Replicate_Do_Domain_Ids:
  Replicate_Ignore_Domain_Ids:
                Parallel_Mode: conservative
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
1 row in set (0.00 sec)




[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm(을)를 복구합니다
준비 중...                         ################################# [100%]
Updating / installing...
   1:zabbix-release-5.0-1.el7         ################################# [ 50%]
Cleaning up / removing...
   2:zabbix-release-3.4-2.el7         ################################# [100%]




[root@localhost ~]# yum -y install zabbix-agent




[root@localhost ~]# vi /etc/zabbix/zabbix_agentd.conf
Server=10.70.101.80  ###자비스 서버 IP
#ServerActive=127.0.0.1
Hostname=10.70.101.78 ##AGENT 서버 IP




## zabbix agent 실행
[root@localhost ~]# systemctl start zabbix-agent.service



[root@localhost ~]# ps -ef | grep zabbix
zabbix   26166     1  0 06:28 ?        00:00:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbi_agentd.conf
zabbix   26167 26166  0 06:28 ?        00:00:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix   26168 26166  0 06:28 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix   26169 26166  0 06:28 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix   26170 26166  0 06:28 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
root     26199 25946  0 06:30 pts/0    00:00:00 grep --color=auto zabbix
 
 

Zabbix Server  웹 접속

 

■ URL : http://IP/zabbix         http://10.70.101.80/zabbix

 

1. 초기 setup화면

 


2.  error 발생시 OK상태를 맞춰야 next step갈 수 있습니다.

 
 

3. DB 설정할때 입력한 Database name과 User,Password 입력

 
 

4. Name은 대시보드상에 나타나는 이름을 지정해준다.

 
 

5. summary 확인

 

 

6. Install 완료

 
 

7. 접속

초기 암호 : Admin / zabbix

※ admin의 a는 대문자 A사용

 

 

 

첫 Dashboard 화면

 

 

 
여기까지 zabbix서버 설치와 web접속을 마치겠습니다.
다음 글에서는 Host설정과 DB 모니터링 설정을 하도록 하겠습니다~

 

 

참고