Try   HackMD

Zabbix Agent 建置操作手冊

tags: 監控工具安裝手冊

第一部分 : 設定時區

# timedatectl set-timezone Asia/Taipei

第二部分 : 安裝 Zabbix

下載 & 解壓縮安裝包

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.0.tar.gz # tar -zxvf zabbix-5.0.0.tar.gz

創建 zabbix 用戶

# groupadd --system zabbix # useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix # mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix # chown zabbix:zabbix /usr/lib/zabbix

安裝其他套件及配置

# yum install gcc mysql-devel libxml2-devel net-snmp-devel OpenIPMI OpenIPMI-devel libevent-devel curl curl-devel automake autoconf libtool make # cd /home/ec2-user/zabbix-5.0.0 # ./configure --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --prefix=/usr/local/zabbix # make install

查看是否安裝成功

# cd /usr/local/zabbix/sbin/ # ls zabbix_agentd

第三部分 : 配置 Zabbix

修改 zabbix_agentd.conf

  • 將配置文件中的Server、ServerActive、Hostname參數設置成zabbix服務器的IP地址即可,如果安裝的zabbix_agentd和zabbix_server在同一服務器上,則IP地址為本機IP地址。
# vim /usr/local/zabbix/etc/zabbix_agentd.conf Server=192.169.0.103 ServerActive=192.169.0.103 Hostname=192.169.0.103

防火牆配置

# yum install firewalld # systemctl start firewalld # firewall-cmd --permanent --add-port=10051/tcp # firewall-cmd --permanent --add-port=10051/tcp # systemctl stop firewalld

將資源包中提供的 init.d 啟動腳本拷貝到系統中並修改位置

# cp /home/ec2-user/zabbix-5.0.0/misc/init.d/fedora/core/zabbix_* /etc/init.d/ -v ‘/home/ec2-user/zabbix-5.0.0/misc/init.d/fedora/core/zabbix_agentd’ -> ‘/etc/init.d/zabbix_agentd’ ‘/home/ec2-user/zabbix-5.0.0/misc/init.d/fedora/core/zabbix_server’ -> ‘/etc/init.d/zabbix_server’ # vim /etc/init.d/zabbix_agentd BASEDIR=/usr/local/zabbix

啟動服務

# /etc/init.d/zabbix_agentd start Reloading systemd: [ OK ] Starting zabbix_server (via systemctl): [ OK ] # /etc/init.d/zabbix_agentd status ● zabbix_server.service - SYSV: Starts and stops Zabbix Server using chkconfig Loaded: loaded (/etc/rc.d/init.d/zabbix_server; bad; vendor preset: disabled) Active: active (running) since Tue 2022-10-18 13:44:58 CST; 7s ago

設定開機啟動服務

# chkconfig --add zabbix_agentd # chkconfig --level 35 zabbix_agentd on # chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off zabbix_agentd 0:off 1:off 2:off 3:on 4:off 5:on 6:off zabbix_server 0:off 1:off 2:off 3:on 4:off 5:on 6:off

第四部分 : 在 Server 上設定監控 Agent

1. Configuration -> Hosts -> Create host

2. 選擇該主機並設定 Templatetes -> Add

3. 成功開啟監控 agent

出錯排除

問題

1. zabbix 報錯 : Received empty response from Zabbix Agent at [127.0.0.1]. Assuming that agent dropped connection because of access permissions

2. 檢查服務是否被監聽

# netstat -lntup|grep 10050
    tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      7440/zabbix_agentd
    tcp6       0      0 :::10050                :::*                    LISTEN      7440/zabbix_agentd

3. 查看配置文件

  • 這裡的 ServerActive 要配置成 127.0.0.1 以解決錯誤
# vim /usr/local/zabbix/etc/zabbix_agentd.conf Server=192.169.0.103 ServerActive=127.0.0.1 Hostname=192.169.0.103

4. 解決方法

  1. Web 修改主機 IP
  2. zabbix-agentd.conf 配置文件中 ServerActive 改為 127.0.0.1

5. 重新啟動服務

# /etc/init.d/zabbix_agentd restart Restarting zabbix_agentd (via systemctl): [ OK ] # /etc/init.d/zabbix_server restart Restarting zabbix_server (via systemctl): [ OK ]

6. 結果