[모니터링] zabbix-agent 프로그램 설치

김봉남·2024년 1월 21일

모니터링

목록 보기
2/9
post-thumbnail

Zabbix

네트워크 및 서버 리소스, 성능 및 가용성을 모니터링하는 오픈 소스 기반의 IT 인프라 모니터링 솔루션

zabbix-agent 프로그램 설치

  1. zabbix 레포 추가 ( zabbix 사이트에서 확인 후 진행 할 것 )
    rpm -Uvh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

  2. zabbix agnet 설치
    yum install zabbix-agent -y

  3. zabbix service on ( 자동 재시작 )
    chkconfig zabbix-agent on

  4. conf 설정
    vi /etc/zabbix/zabbix_agentd.conf

Server=자빅스서버IP (수집서버)
ServerActive=자빅스서버IP (수집서버)
Hostname=로컬서버IP (실아이피쓸것)

위 3개만 설정하고 로그 확인 필요시 아래 처럼 설정 후 확인

DebugLevel=4 -> 실제 정상 통신 확인을 위한 로그레벨설정, 기본은 3

로그는 /var/log/zabbix 에 쌓임

  1. 서비스 시작
    service zabbix-agent restart
  1. iptables 수정
    vi /etc/sysconfig/iptables
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT

service iptables restart

zabbix SMS 구성

  • 감지 스크립트를 만들어서 "0"은 정상, "1"은 비정상 출력
  • Zabbix 모니터링 GUI에서 Triggers 항목에 0보다 크면 동작하게 생성

passwd_chk.sh 스크립트

#!/bin/bash
sudo pam_tally2 -u gt01 | tail -1 | awk '{if ($2 <= 5) printf "0";else printf "1"}'

zabbix_agentd.conf 환경설정

vi /etc/zabbix/zabbix_agentd.conf
### Option: UserParameter
#	User-defined parameter to monitor. There can be several user-defined parameters.
#	Format: UserParameter=<key>,<shell command>
#	See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
UserParameter=custom.ftp_lock,sudo /etc/zabbix/passwd_chk.sh

Zabbix GUI 에서 enable 안될 경우 sudo 권한 및 zabbix sudo 추가

# Allow user zabbix to run sudo without tty
Defaults:zabbix !requiretty
zabbix  ALL=(ALL:ALL) NOPASSWD:ALL

Zabbix GUI Item 추가

해당 서버 → Items → Name 작성 → Type : Zabbix_agent → Key : custom.ftp_lock(Zabbix_agentd.conf 파일 내에 Parameter값과 동일하게 설정) → Application 선택

# key 값이 중요
key : custom.acc_lock

Zabbix GUI Triggers 추가

Name : 작성 → Expression : {호스트명:custom.ftp_lock.last(#2)}>0 → Seventy High 선택

# Expression 값이 중요
{testVM01:custom.acc_lock.last(#2)}>0
{testVM02:custom.acc_lock.last(#2)}>0
{testVM03:custom.ftp_lock_dats.last(#2)}>0

Ansible 이용하여 Zabbix 설치

drwxr-xr-x 2 test test  6 Oct 18  2021 files
drwxr-xr-x 2 test test 22 Oct 18  2021 handlers
drwxr-xr-x 2 test test 22 Aug 26  2022 tasks
drwxr-xr-x 2 test test 69 Oct 18  2021 templates


[root@testVM01 handlers]# vi main.yml 
---
# handlers file for zabbix
- name: restart zabbix-agent
  service:
    name: zabbix-agent
    state: restarted
    enabled: yes


[root@testVM01 tasks]# vi main.yml 
---
# tasks file for zabbix

- name: Download RHEL 6
  template: src=zabbix6.repo.j2 dest=/etc/yum.repos.d/zabbix6.repo
  when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") or
        (ansible_distribution == "RedHat" and ansible_distribution_major_version == "6")

- name: Download RHEL 7
  template: src=zabbix7.repo.j2 dest=/etc/yum.repos.d/zabbix7.repo
  when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7") or
        (ansible_distribution == "RedHat" and ansible_distribution_major_version == "7")


- name: Zabbix YUM Install
  shell: yum install -y zabbix-agent

- name: Zabbix config file replace
  shell: hostname -s
  register: server_hostname

- name: zabbix config file
  template: src=zabbix.j2 dest=/etc/zabbix/zabbix_agentd.conf
  notify:
  - restart zabbix-agent

- name: RHEL6 Zabbix Service Enable
  shell: chkconfig zabbix-agent on
  when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") or
        (ansible_distribution == "RedHat" and ansible_distribution_major_version == "6")

- name: RHEL7 Zabbix Service Enable
  shell: systemctl enable zabbix-agent
  when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7") or
        (ansible_distribution == "RedHat" and ansible_distribution_major_version == "7")


[root@testVM01 zabbix]# cd templates/
[root@testVM01 templates]# ll
total 12
-rw-r--r-- 1 test test  91 Oct 18  2021 zabbix6.repo.j2
-rw-r--r-- 1 test test  91 Oct 18  2021 zabbix7.repo.j2
-rw-r--r-- 1 test test 247 Oct 18  2021 zabbix.j2

[root@testVM01 templates]# cat zabbix6.repo.j2 
[ZABBIX6_YUM]
name=Zabbix6_updata
baseurl=http://00.00.00.00/zabbix6
enabled=1
gpgcheck=0

[root@testVM01 templates]# cat zabbix7.repo.j2 
[ZABBIX7_YUM]
name=Zabbix7_updata
baseurl=http://00.00.00.00/zabbix7
enabled=1
gpgcheck=0

[root@testVM01 templates]# cat zabbix.j2 
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=00.00.00.00
ServerActive=00.00.00.00
Hostname={{ server_hostname.stdout }}
HostMetadataItem=system.uname
Include=/etc/zabbix/zabbix_agentd.d/
profile
남자다

0개의 댓글