zabbix agent 配置
http://blog.csdn.net/z644041867/article/details/76618644
https://www.cnblogs.com/miclesvic/p/6144924.html
http://blog.chinaunix.net/uid-29155617-id-4668602.html
###############1
Zabbix Agent端配置文件說明
由於工作中經常接觸到zabbix,所以將agent配置整理一下,方便日常查看。
# This is a config file for the Zabbix agent daemon (Unix)
# To get more information about Zabbix, visit http://www.zabbix.com
############ GENERAL PARAMETERS #################
### Option: PidFile
# Name of PID file.
#
# Mandatory: no
# Default:
#pidFile=PID路徑
#說明:指定程程序PIDFILE路徑,可修改到其它路徑,但SNC不建議修改
PidFile=/smp/sncmon/zabbix_agentd.pid
### Option: LogFile
# Name of log file.
# If not set, syslog is used.
#
# Mandatory: no
# Default:
# LogFile=
#LogFile=路徑
#說明:客戶端AGENT運行產生的日誌文件路徑,可修改到其它路徑,如/var/log/zabbix_agnetd.log,視具體情況修改,也可保持默認
LogFile=/smp/sncmon/zabbix_agentd.log
### Option: LogFileSize
# Maximum size of log file in MB.
# 0 - disable automatic log rotation.
#
# Mandatory: no
# Range: 0-1024
# Default:
#LogFileSize=
#說明:AGENT產生日誌大小控制,默認1M,若為0,則表示不產生任何日誌,數字範圍(1-1024M)不建議關閉日誌功能,建議保持默認
LogFileSize=1
### Option: DebugLevel
# Specifies debug level
# 0 - no debug 無日誌級別
# 1 - critical information 災難信息級別
# 2 - error information 一般錯誤信息級別
# 3 - warnings 警告級別
# 4 - for debugging (produces lots of information) 調試級別
#說明:0~4級別,日誌產生量在相同單位時間,生成的日誌量為遞增,即0級別日誌量最少,4級別最多,默認3級別,建議視具體情況,自行把握
#
# Mandatory: no
# Range: 0-4
# Default:
DebugLevel=3
### Option: SourceIP
# Source IP address for outgoing connections.
#
# Mandatory: no
# Default:
#SourceIP=IP地址
#說明:當系統設置有多個IP時,需要指定一個IP與二級代理或服務端通信,若系統只有一個IP,也建議指定一個IP
SourceIP=192.168.1.3
### Option: EnableRemoteCommands
# Whether remote commands from Zabbix server are allowed.
# 0 - not allowed 不允許
# 1 - allowed 允許
#
# Mandatory: no
# Default:
#EnableRemoteCommands=0或1
#說明:是否允許在本地執行遠程命令,建議設置為“允許”,因為SNC對命令下發功能進行了二次開發,功能強大,極大的方便日誌運維工作
EnableRemoteCommands=1
### Option: LogRemoteCommands
# Enable logging of executed shell commands as warnings.
# 0 - disabled 不產生日誌
# 1 - enabled 產生日誌
#
# Mandatory: no
# Default:
#LogRemoteCommands=1或0
#說明:在參數EnableRemoteCommands=1的情況下,執行遠程命令是否保存操作日誌,若已設置EnableRemoteCommands=1
#建議LogRemoteCommands=1,以便 日後查證。若EnableRemoteCommands=0,此參數不生效
LogRemoteCommands=1
##### Passive checks related
#與被動模式有關的參數設置
#什麽是被動模式?
#被動模式下,由二級代理或服務端主動請求AGENT,去獲取所采集到的監控數據
### Option: Server
# List of comma delimited IP addresses (or hostnames) of Zabbix servers.
# Incoming connections will be accepted only from the hosts listed here.
# If IPv6 support is enabled then ‘127.0.0.1‘, ‘::127.0.0.1‘, ‘::ffff:127.0.0.1‘ are treated equally.
#
# Mandatory: no
# Default:
# Server=
#Server=IP地址或主機名,建議IP地址
#說明:在有二級代理情況下,此IP地址應該填寫二級代理服務器的IP,反之,若無二級代理服務器,則此IP應設置為服務端#IP
Server=192.168.1.14
### Option: ListenPort
# Agent will listen on this port for connections from the server.
#
# Mandatory: no
# Range: 1024-32767 (監控端口範圍)
# Default:
# ListenPort=數字
#說明:此AGENT端以本地服務的形式運行,需要監聽端口,強烈建議設置為10050,以便移動整個系統統一規劃管理,當然,特殊情況下可修改為1024-32767 未使用的端口
ListenPort=10050
### Option: ListenIP
# List of comma delimited IP addresses that the agent should listen on.
# First IP address is sent to Zabbix server if connecting to it to retrieve list of active checks.
#
# Mandatory: no
# Default:
## ListenIP=IP地址
#說明:對應的ListenPort監聽到哪個IP上面,建議指定IP時,不用0.0.0.0
# ListenIP=192.168.1.6
### Option: StartAgents
# Number of pre-forked instances of zabbix_agentd that process passive checks.
# If set to 0, disables passive checks and the agent will not listen on any TCP port.
#
# Mandatory: no
# Range: 0-100 數字範圍(0-100)
# Default:
#StartAgents=數字
#說明:在被動模式下,此參數用於設置控制監聽進程可啟用的子進程的數量,若監控項較多且采集很頻繁,建議加大此數值
;若此數值為0,則禁止使用被動模式。另外,一般情況,不建議修改此數值,當且僅當某些監控項無法采集到數據,或數據采集數據有延遲現象時,可調整。第四,啟用線程越多,則相對越耗系統資源
StartAgents=5
##### Active checks related
#主動模式相關參數設置
#什麽時主動模式?
#在主動模式下,AGENT端(即采集客戶端)將所采集的結果,主動提交給二級代理服務器或服務器,而此種情況下,二級代理服務器或服務器將被動接收采集信息
### Option: ServerActive
# List of comma delimited IP:port (or hostname:port) pairs of Zabbix servers for active checks.
# If port is not specified, default port is used.
# IPv6 addresses must be enclosed in square brackets if port for that host is specified.
# If port is not specified, square brackets for IPv6 addresses are optional.
# If this parameter is not specified, active checks are disabled.
# Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
#
# Mandatory: no
# Default:
# ServerActive=
#ServerActive=IP地址或IP地址:端口號
#說明:在主動模式下,ServerActive為二級代理服務器或服務器,默認端口為10051,若需更改端口,則為#ServerActive=IP:port,非特殊情況下,不建議修改。
ServerActive=192.168.1.14
### Option: Hostname
# Unique, case sensitive hostname.
# Required for active checks and must match hostname as configured on the server.
# Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
# Hostname=
# Hostname=主機名
#說明:手工自定義一個主機名,可以和系統的主機名一樣,也可以不一樣,此參數可根據實際情況啟用或關閉,建議關閉此參數,並啟用HostnameItem參數
#Hostname=Zabbix server
### Option: HostnameItem
# Item used for generating Hostname if it is undefined.
# Ignored if Hostname is defined.
#
# Mandatory: no
# Default:
#HostnameItem:自動獲取主機名
#說明:system.hostname是ZABBIX內置的一個自動獲取主機名的方法,為了方便配置,建議打開此參數而關閉Hostname參數#。註意:HostnameItem的優化級低於Hostname,當兩個參數都啟用且配置的情況下,ZABBIX獲取的主機名,將以Hostname為#準
HostnameItem=system.hostname
### Option: HostMetadata
# Optional parameter that defines host metadata.
# Host metadata is used at host auto-registration process.
# An agent will issue an error and not start if the value is over limit of 255 characters.
# If not defined, value will be acquired from HostMetadataItem.
#
# Mandatory: no
# Range: 0-255 characters 0-255個字符
# Default:
# HostMetadata=字符串
#說明:用於定義當前主機唯一標識符,最大長度255個,僅適用於自動發現情況下,默認不定義,建議不定義
# HostMetadata=
### Option: HostMetadataItem
# Optional parameter that defines an item used for getting host metadata.
# Host metadata is used at host auto-registration process.
# During an auto-registration request an agent will log a warning message if
# the value returned by specified item is over limit of 255 characters.
# This option is only used when HostMetadata is not defined.
#
# Mandatory: no
# Default:
#說明;用於獲取主機的HostMetadata,建議保持默認
# HostMetadataItem=
### Option: RefreshActiveChecks
# How often list of active checks is refreshed, in seconds.
#
# Mandatory: no
# Range: 60-3600
# Default:
#RefreshActiveChecks=數字
#說明:被監控的主機多久(秒)重新請求二級代理或服務端刷新一監控列表。範圍為60-3600秒。ZABBIX運行原理為:,zabbix客戶端啟動後,在等待RefreshActiveChecks秒後,開始從二級代理或服務端請求並下載監控項信息,保存在本地專門的buffersend中,再過RefreshActiveChecks秒後,重新獲取監控項信息。這就是為什麽當配置監控項,要過一會才能生效的原因。這個數值,就是等待時間。建議,不要將此數值設置過小,以免加大AGENT端和服務端及數據庫的壓力,建議為120秒。
RefreshActiveChecks=120
### Option: BufferSend
# Do not keep data longer than N seconds in buffer.
#
# Mandatory: no
# Range: 1-3600
# Default:
#BufferSend=數字
#說明:多少秒後,將BUFFER中的數據提交到二級代理或服務端。範圍(1-36600)此數值的大小決定了采集後,提交數據的及時性,數值越小,則提交得越頻繁,對服務器壓力越大,同時對AGENT端系統資源消耗越大,則表現出來的現象是報警非常及時,建議根據實際情況自行考慮,也可保持默認,若發現ZABBIX消耗資源較多,建議加大此數值。
BufferSend=5
### Option: BufferSize
# Maximum number of values in a memory buffer. The agent will send
# all collected data to Zabbix Server or Proxy if the buffer is full.
#
# Mandatory: no
# Range: 2-65535
# Default:
#BufferSize=數值
#說明:此參數作用設置保存采集數據在內存中的容量大小。若此agent端監控項較多,建議加大此數值。BufferSize與BufferSend之間有聯系的。當達到bUFFERSEND或Buffersize已滿時,都會觸發數據提交動作。
BufferSize=100
### Option: MaxLinesPerSecond
# Maximum number of new lines the agent will send per second to Zabbix Server
# or Proxy processing ‘log‘ and ‘logrt‘ active checks.
# The provided value will be overridden by the parameter ‘maxlines‘,
# provided in ‘log‘ or ‘logrt‘ item keys.
#
# Mandatory: no
# Range: 1-1000
# Default:
#MaxLinesPerSecond=數值
#說明:定義了AGENT在1秒內發送的日誌行數,用於避免網絡或cpu過載,建議保持默認
# MaxLinesPerSecond=100
############ ADVANCED PARAMETERS #################
#高級參數設置
### Option: Alias
# Sets an alias for parameter. It can be useful to substitute long and complex parameter name with a smaller and simpler one.
#
# Mandatory: no
# Range:
# Default:
#設置參數的別名。它可以替代長和復雜的一個小而簡單的一個有用的參數名稱
#alias_name=long_command
### Option: Timeout
# Spend no more than Timeout seconds on processing
#
# Mandatory: no
# Range: 1-30
# Default:
#Timeout=數值
#說明:當agent采集一個數據時,多長少算超時。建議保持默認
Timeout=30
### Option: AllowRoot
# Allow the agent to run as ‘root‘. If disabled and the agent is started by ‘root‘, the agent
# will try to switch to user ‘zabbix‘ instead. Has no effect if started under a regular user.
# 0 - do not allow
# 1 - allow
#
# Mandatory: no
# Default:
#AllowRoot=0或1
#說明:是否允許ROOT帳號運行此客戶端。0:不允許,1:允許,當一個腳本執行需要以ROOT身份執行的,則此開關必須打開,建議根據實際情況開啟或關閉,
AllowRoot=0
### Option: Include
# You may include individual files or all files in a directory in the configuration file.
# Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.
#
# Mandatory: no
# Default:
# Include=
# Include=目錄路徑或擴展配置文件路徑
#說明:從配置文件可管理性或擴展性考慮,若需配置大量參數的且為了方便後續管理可以啟用此參數,建議根據實際情況考慮,不過,一般情況下無須啟用
# Include=/usr/local/etc/zabbix_agentd.userparams.conf
# Include=/usr/local/etc/zabbix_agentd.conf.d/
####### USER-DEFINED MONITORED PARAMETERS #######
#自定義監控腳本
### Option: UnsafeUserParameters
# Allow all characters to be passed in arguments to user-defined parameters.
# 0 - do not allow
# 1 - allow
#
# Mandatory: no
# Range: 0-1
# Default:
#UnsafeUserParameters=0或1
#說明:是否啟用用戶自定義監控腳本,1啟用,0不啟用。由於ZABBIX實現監控方法的多樣性,一般都采用腳本來實現監控數據的采集,所以,建議開啟,否則功能將受限。
UnsafeUserParameters=1
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=,
# See ‘zabbix_agentd‘ directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
####### LOADABLE MODULES #######
### Option: LoadModulePath
# Full path to location of agent modules.
# Default depends on compilation options.
#
# Mandatory: no
# Default:
# LoadModulePath=${libdir}/modules
#說明:擴展模塊路徑,強烈建議不要改動,除非你具有AGENT 開發能力
# LoadModulePath=${libdir}/modules
### Option: LoadModule
# Module to load at agent startup. Modules are used to extend functionality of the agent.
# Format: LoadModule=
# The modules must be located in directory specified by LoadModulePath.
# It is allowed to include multiple LoadModule parameters.
#
# Mandatory: no
# Default:
#說明:擴展模塊路徑,強烈建議不要改動,除非你具有AGENT 開發能力
# LoadModule=
#UserParameter=
#說明:用戶自定義監控腳本,當且僅當UnsafeUserParameters=1時UserParameter生效。以下為SNC初始自定監控腳本,不建議修改,已有選項,但可自義添加。
#自定義監控項配置語法
#UserParameter=key,command
#如何使用:以獲取mysql監控為例
#步驟1,設置自定義腳本
#UserParameter=mysql.questions,mysqladmin -uroot --password=‘XXXXX‘ status|cut -f4 -d":"|cut -f1 -d"S"
#保存退出,並重啟AGENT
#步驟2,手工驗證
#在二級代理端或服務器端用命令 zabbix_get -s IP -k mysql.questions 將返回采集信息
#步驟3,在管理頁面添加監控項
#註意:成功關鍵,腳本本身具有可執行權限,且腳本運行正常
UserParameter=cmd[*],$1 $2 $3 $4 $5 $6 $7 $8 $9
UserParameter=setenv[*],java -jar /smp/sncmon/java/setenv/setenv.jar $1 $2
UserParameter=oracle[*],java -jar /smp/sncmon/java/oracle/oracle.jar $1 /smp/sncmon/java/oracle/
UserParameter=db2[*],/smp/sncmon/java/db2/linux.sh $1
UserParameter=mindwaresctipt,setsid /smp/sncmon/shell/middleware/middle_zabbix.sh
UserParameter=agent.restart,/smp/sncmon/shell/agent/agentrestart.sh
UserParameter=diskmon,/smp/sncmon/shell/diskmon/disk_mon.sh $1
#############2
http://blog.csdn.net/weini1111/article/details/73824730
最近把zabbix配置及使用過程中遇到的一些問題,逐步做一個總結,也供遇到同樣問題的同學一些參考。
一、agent不能被發現
裝完zabbix後,在server上的agent不能被發現,並出現如下報警Zabbix agent on Zabbix server is unreachable for 5 minutes,這個時候只要明白agent配置文件,則很容易解決。
[root@zabbix-server zabbix]# grep -v ^# /etc/zabbix/zabbix_agentd.conf |grep -v ^$
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.2.128,127.0.0.1 //zabbix server的ip地址或主機名,可同時列出多個,需要用逗號隔開
ServerActive=192.168.2.128 //開啟主動檢查
Hostname=zabbix-server //在zabbix server前端配置時指定的主機名要相同,最重要的配置
Include=/etc/zabbix/zabbix_agentd.d/
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
配置文件寫正確,都能正常發現agent。
二、agent端無法重啟
1、首先查看防火墻是否開啟,如開啟則關閉(如果會寫策略也可以開啟),將SELinux關閉。
2、上面所示還不能啟動的情況下,這個時候先查看配置文件中日誌文件路徑(不知道日誌文件路徑情況下)
[root@zabbix-agent1 ~]# grep -v ^# /etc/zabbix/zabbix_agentd.conf |grep -v ^$
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log //日誌文件路徑
LogFileSize=0
Server=192.168.2.128
ServerActive=192.168.2.128
- 1
- 2
- 3
- 4
- 5
- 6
然後查看日誌發現如下提示
[root@zabbix-agent1 ~]# cat /var/log/zabbix/zabbix_agentd.log
......
zabbix_agentd [3351]: cannot create PID file [/var/run/zabbix/zabbix_agentd.pid]: [2] No such file or directory
zabbix_agentd [3388]: cannot create PID file [/var/run/zabbix/zabbix_agentd.pid]: [2] No such file or directory
zabbix_agentd [3467]: cannot create PID file [/var/run/zabbix/zabbix_agentd.pid]: [2] No such file or directory
zabbix_agentd [797]: cannot create PID file [/var/run/zabbix/zabbix_agentd.pid]: [2] No such file or directory
- 1
- 2
- 3
- 4
- 5
- 6
從上面可以看出PID文件無法被創建,不能正常啟動,這是查看/var/run/發現確實沒有。如果直接創建/var/run/zabbix/zabbix_agentd.pid,則依然無法啟動agent,因為文件權限問題。所以必須進行如下操作
[root@zabbix-agent1 run]# mkdir zabbix
[root@zabbix-agent1 run]# ls -ld zabbix
drwxr-xr-x 2 root root 40 6月 27 22:33 zabbix //發現所屬主所屬組是root
[root@zabbix-agent1 run]# chown zabbix.zabbix zabbix
[root@zabbix-agent1 run]# ls -ld zabbix
drwxr-xr-x 2 zabbix zabbix 40 6月 27 22:33 zabbix //此時已經可以啟動agent了,如果依然不行,則進行下面操作
[root@zabbix-agent1 run]# chmod g+w zabbix/ //給所屬組添加讀權限
[root@zabbix-agent1 run]# ls -ld zabbix
drwxrwxr-x 2 zabbix zabbix 40 6月 27 22:33 zabbix
[root@zabbix-agent1 run]# touch zabbix/zabbix_agentd.pid
[root@zabbix-agent1 zabbix]# systemctl restart zabbix-agent
[root@zabbix-agent1 zabbix]# systemctl status zabbix-agent
● zabbix-agent.service - LSB: Start and stop Zabbix agent
Loaded: loaded (/etc/rc.d/init.d/zabbix-agent; bad; vendor preset: disabled)
Active: active (running) since 二 2017-06-27 22:37:21 CST; 1s ago
......
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
在上面步驟中,修改完/var/run/zabbix/所屬組,agent依然無法啟動,則再給其所屬組添加讀權限,來重新啟動agent。這是zabbix-agent的一個bug,本人使用版本存在此bug,建議使用最新版本。
zabbix agent 配置