zabbix5.0 installation documentation

Posted by dacs on Tue, 25 Jan 2022 06:53:10 +0100

server installation

#Download configuration using yum

# rpm -Uvh
# yum clean all

# vim  /etc/yum.repos.d/zabbix.repo

#zabbix package download

# yum -y install zabbix-server-mysql zabbix-agent 
# yum -y install centos-release-scl 		#If this is not installed, an error will be reported in the next installation

# yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl 

#Install database

# yum install mariadb-server -y 
# systemctl enable --now mariadb
# mysql_secure_installation
. . . 
The database password can be set in the middle
. . . 

# mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;

#Import data template into database

# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -ppassword zabbix

#Modify profile

# vim /etc/zabbix/zabbix_server.conf 
    DBHost=localhost		#Database host address
    DBName=zabbix 			#Database name
    DBUser=zabbix 			#Database user
    DBPassword=123456		#Database user password

#Modify time zone

vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
    php_value[date.timezone] = Asia/Shanghai

#Start zabbix service

# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
# systemctl enable --now zabbix-server zabbix-agent httpd rh-php72-php-fpm 

web configuration

Browser access:

​ http://zabbix_server/zabbix

Login user: Admin

Password: zabbix

Set Chinese:

​ usersettings--------------language----chinese(zh_CN)

agent installation

ZABBIX agent installation configuration

# yum -y install zabbix-agent

# vi /etc/zabbix/zabbix_agentd.conf
	Server=			#Specify the address of the ZABBIX server
	ServerActive=		#ZABBIX server address during automatic registration
	Hostname=host1					#Host name when adding host

# systemctl enable --now zabbix-agent

ZABBIX server add host

add template

Custom monitor

#Custom key value (modify zabbix_agentd.conf file)
# vi /etc/zabbix/zabbix_agentd.conf
	# Format: UserParameter=key_name,command
	UserParameter=tcp_conn,ss -ant | grep ESTAB | wc -l

# Write the command manually to get the value you want to get
UserParameter=mysql.questions,mysqladmin -uroot -pxyh,.123 status | cut -f4 -d":" | cut -f1 -d"S",free -h | awk 'NR==2{print $4}'

#Note that when the $1 used is not a bit parameter, two are required$[*],df -h | grep $1 | awk '{print $$2}'

restart zabbix_agent

Test whether the set key is valid through ZABBIX get. It is on the server side

[root@k8s-master1 ~]# zabbix_get -s -p 10050 -k tcp_conn

[root@localhost yum.repos.d]# zabbix_get -s -p 10050 -k
[root@localhost yum.repos.d]# zabbix_get -s -p 10050 -k mysql.questions
[root@localhost yum.repos.d]# zabbix_get -s -p 10050 -k['/dev/sda1']

Configure monitoring items on the web side

View and define monitoring items

If the value to be obtained cannot be obtained through a command


vi /etc/zabbix/
function  ESTAB { 
/usr/sbin/ss  -ant |  awk  '{++s[$1]} END {for(k in s) print k,s[k]}'  |  grep  'ESTAB'  |  awk  '{print $2}'
function  TIMEWAIT { 
/usr/sbin/ss  -ant |  awk  '{++s[$1]} END {for(k in s) print k,s[k]}'  |  grep  'TIME-WAIT'  |  awk  '{print $2}'
function  LISTEN { 
/usr/sbin/ss  -ant |  awk  '{++s[$1]} END {for(k in s) print k,s[k]}'  |  grep  'LISTEN'  |  awk  '{print $2}'

vi /etc/zabbix/zabbix_agentd.d/zabbix_get.conf
	UserParameter=tcp[*],bash /etc/zabbix/ $1
systemctl restart zabbix-agent

ZABBIX get test

[root@k8s-master1 ~]# zabbix_get -s -p 10050 -k tcp[TIMEWAIT]
[root@k8s-master1 ~]# zabbix_get -s -p 10050 -k tcp[ESTAB]
[root@k8s-master1 ~]# zabbix_get -s -p 10050 -k tcp[LISTEN]

web side configuration

Add custom monitoring item to template

Add trigger

Configure monitoring alarm sound

Graphic drawing

Garbled code change

  • Locate the Windows directory C:\Windows\Fonts
  • Copy the font file to the desktop. Remember to copy, not cut
  • Upload to the server directory / usr/share/fonts/dejavu. It is recommended to use simhei in bold TTF, tried several fonts, garbled, unable to modify
cd /usr/share/fonts/dejavu
mv DejaVuSans.ttf DejaVuSans.ttf_bak
mv ALGER.TTF DejaVuSans.ttf

# Note that many documents suggest modifying / usr/share/zabbix/assets/fonts /, but you will find that this directory is only a soft link, and finally points to the above directory

Trigger configuration

Mail alarm

1. Configure sender

Generate authorization code

2. Recipient configuration

Define action

Enterprise wechat alarm

1. Lowest enterprise id

Create an app

Write script for sending enterprise wechat information

  • Major modifications
    • corpid is your enterprise ID
    • appsecret is your app Secret
    • agentid is the agentid of your application
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import requests
import sys
import os
import json
import logging

logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
                datefmt = '%a, %d %b %Y %H:%M:%S',
                filename = os.path.join('/tmp','weixin.log'),
                filemode = 'a')

#Get accesstoken
token_url='' + corpid + '&corpsecret=' + appsecret

#send message
msgsend_url='' + accesstoken

message=sys.argv[2] + "\n\n" +sys.argv[3]

        "touser": touser,
#       "toparty": toparty,
        "msgtype": "text",
        "agentid": agentid,
        "text": {
                "content": message
}, data=json.dumps(params))'sendto:' + touser + ';;subject:' + subject + ';;message:' + message)
# test

python '$own ID' '$Message title' '$Message content'

python XiongYunHua hello Hello
# Place the script in the directory where ZABBIX server stores the script
cp -a ~/ /usr/lib/zabbix/alertscripts
chmod +x

web side configuration


Message sending failed

zabbix common options

[root@localhost yum.repos.d]# zabbix_server -h
  zabbix_server [-c config-file]
  zabbix_server [-c config-file] -R runtime-option
  zabbix_server -h
  zabbix_server -V

The core daemon of Zabbix software.

  -c --config config-file        Specify profile startup
                                 (default: "/etc/zabbix/zabbix_server.conf")
  -f --foreground                Foreground operation server
  -R --runtime-control runtime-option  Specify parameters at startup

    Runtime control options:
      config_cache_reload        Overload configuration cache
      housekeeper_execute        Actuator cleaner
      log_level_increase=target  Increase log level, affects all processes if
                                 target is not specified
      log_level_decrease=target  Decrease log level, affects all processes if
                                 target is not specified
      snmp_cache_reload          Reload SNMP cache
      diaginfo=section           Log internal diagnostic information of the
                                 section (historycache, preprocessing, alerting,
                                 lld, valuecache, locks) or everything if section is
                                 not specified

      Log level control targets:
        process-type             All processes of specified type,Name of the process
                                 (alerter, alert manager, configuration syncer,
                                 discoverer, escalator, history syncer,
                                 housekeeper, http poller, icmp pinger,
                                 ipmi manager, ipmi poller, java poller,
                                 poller, preprocessing manager,
                                 preprocessing worker, proxy poller,
                                 self-monitoring, snmp trapper, task manager,
                                 timer, trapper, unreachable poller,
                                 vmware collector)
        process-type,N           Process type and number (e.g., poller,3)
        pid                      Process identifier, up to 65535. For larger
                                 values specify target as "process-type,N"

  -h --help                      Display this help message
  -V --version                   Display version number

Some configuration parameter default locations:
  AlertScriptsPath               "/usr/share/zabbix/alertscripts"		#Script storage location
  ExternalScripts                "/usr/share/zabbix/externalscripts"	
  SSLCertLocation                "/usr/share/zabbix/ssl/certs"			#Certificate storage location
  SSLKeyLocation                 "/usr/share/zabbix/ssl/keys"			#Public key storage location
  LoadModulePath                 "/usr/lib64/zabbix/modules"			#Module storage location

Example of reloading the server configuration cache using runtime controls:

shell> zabbix_server -c /usr/local/etc/zabbix_server.conf -R config_cache_reload

Example of collecting diagnostic information using runtime controls:

Collect all available diagnostic information in the server log file:
Shell> zabbix_server -R diaginfo

Collect history cache statistics in the server log file:
Shell> zabbix_server -R diaginfo = historycache

Example of reloading SNMP cache using runtime controls:

Shell> zabbix_server -R snmp_cache_reload  

Examples of using runtime controls to trigger housekeeper execution:

shell> zabbix_server -c /usr/local/etc/zabbix_server.conf -R Housekeeper execution

Example of changing log level using runtime controls:

Increase the log level of all processes:
shell> zabbix_server -c /usr/local/etc/zabbix_server.conf -R log_level_increase

Increase the log level of the second poller:
shell> zabbix_server -c /usr/local/etc/zabbix_server.conf -R log_level_increase = poller,2

use PID 1234 Increase the log level of the process:
shell> zabbix_server -c /usr/local/etc/zabbix_server.conf -R log_level_increase = 1234

Reduce all http Log level of the poller:
shell> zabbix_server -c /usr/local/etc/zabbix_server.conf -R log_level_decrease =" http poller"

Processing users

The Zabbix server is designed to run as a non root user. It will run as any non root user used at startup. Therefore, you can run the server as any non root user without any problems.

If you try to run it as the "root" user, it will switch to the hard coded "zabbix" user, who must existence In the system. If you modify the "AllowRoot" parameter in the server configuration file accordingly, you can only run the server as "root".

If the Zabbix server and agent The program runs on the same computer. It is recommended to use a user different from the one running the agent to run the server. Otherwise, if both run as the same user, the agent can access the server configuration file and any administrator level user in Zabbix can easily retrieve, for example, the database password.

configuration file

About configuring ZABBIX_ For details of server, see configuration file Options.

Startup script

These scripts are used to automatically start / stop the Zabbix process during system startup / shutdown. The script is located in the directory misc / init D next.

Server process type

  • alert manager - the manager of the alert task
  • Alert - the process of sending notifications
  • availability manager - host availability update process
  • configuration syncer - the process of managing the in memory cache of configuration data
  • discoverer - device discovery process
  • escalator - the process of action upgrade
  • history poller - the process of processing calculations, summaries, and internal checks that require database connections
  • history syncer - historical database author
  • housekeeper - the process of deleting old historical data
  • http poller - network monitoring poller
  • icmp pinger - poller for polling check
  • ipmi manager -IPMI polling Manager
  • ipmi poller - poller for IPMI checks
  • java poller - poller for Java checks
  • lld manager - manager process for low-level discovery tasks
  • lld worker - work process of low-level discovery task
  • Poller - normal poller for passive checking
  • preprocessing manager - preprocessing Task Manager
  • preprocessing worker - data preprocessing process
  • Proxy poller - passive proxy poller
  • report manager - the manager who schedules the report generation task
  • report writer - the process of generating scheduled reports
  • Self monitoring - the process of collecting internal server statistics
  • SNMP trap - SNMP trap
  • task manager - the process of remotely executing tasks requested by other components (for example, closing problems, confirming problems, checking item values immediately, remote command functions)
  • Timer - timer to handle maintenance
  • Trap - trap for active inspection, trap and agent communication
  • unreachable poller - poll unreachable devices
  • vmware collector -VMware data collector, responsible for collecting data from VMware services

Server log files can be used to observe these process types.

You can use zabbix **[process,,] * * internal project Monitor various types of Zabbix server processes.



An example of running Zabbix get under UNIX to get the processor load value from the agent:

shell> cd bin
shell> ./zabbix_get -s -p 10050 -k system.cpu.load[all,avg1]

Another example of running Zabbix get for capturing a string from a website:

shell> yum -y install zabbix-get
shell> ./zabbix_get -s -p 10050 -k "[,,,\"USA: ([a-zA-Z0-9.-]+)\",,\1]"

Note that the item key here contains a space so quotes are used to mark the item key to the shell. The quotes are not part of the item key; they will be trimmed by the shell and will not be passed to Zabbix agent.

Zabbix get accepts the following command line parameters:

  -s --host <host name or IP>      Specify host name or IP address of a host.
  -p --port <port number>          Specify port number of agent running on the host. Default is 10050.
  -I --source-address <IP address> Specify source IP address.
  -k --key <item key>              Specify key of item to retrieve value of.
  -h --help                        Give this help.
  -V --version                     Display version number.

See also Zabbix get manpage for more information.

Zabbix get on Windows can be run similarly:

zabbix_get.exe [options]
[root@localhost yum.repos.d]# egrep -v "(^#|^$)" /etc/zabbix/zabbix_agentd.conf 
Server=			#server address
ServerActive=		#Active mode, server address
Hostname=Zabbix server

Key value of monitoring item

#Custom key value (modify zabbix_agentd.conf file)
	UserParameter=key_name,obtain value command
UserParameter=mysql.questions,mysqladmin -uroot -pxyh,.123 status | cut -f4 -d":" | cut -f1 -d"S",free -h | awk 'NR==2{print $4}'

#Note that when the $1 used is not a bit parameter, two are required$[*],df -h | grep $1 | awk '{print $$2}'

restart zabbix_agent


[root@localhost yum.repos.d]# zabbix_agentd -t mysql.questions
mysql.questions                               [t| 282228]
[root@localhost yum.repos.d]# zabbix_agentd -t                                  [t|549M]

[root@localhost yum.repos.d]# zabbix_get -s -p 10050 -k
[root@localhost yum.repos.d]# zabbix_get -s -p 10050 -k mysql.questions
[root@localhost yum.repos.d]# zabbix_get -s -p 10050 -k['/dev/sda1']

#Manually transfer parameters to key (using position variables)
UserParameter=test[*],echo $1

restart zabbix_agent
[root@localhost yum.repos.d]# systemctl restart zabbix-agent

[root@localhost yum.repos.d]# zabbix_get -s -p 10050 -k test['aa','bb']

Note: user defined parameters can be used for the key value in the monitoring item, but "UnsafeUserParameters=1" must be changed to 1 before they can be used on the server

Otherwise, an error will be reported:

  • Special characters ", ', ", `, *, ?, [, ], {, }, ~, $, !, &, ;, (, ), <, >, |, #, @, 0x0a" are not allowed in the parameters.
The following symbols are required to define the key value, and the parameter needs to be changed to 1

### Option: UnsafeUserParameters
#       Allow all characters to be passed in arguments to user-defined parameters.
#       The following characters are not allowed:
#       \ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @
#       Additionally, newline characters are not allowed.
#       0 - do not allow
#       1 - allow
# Mandatory: no
# Range: 0-1
# Default:
# UnsafeUserParameters=0

trigger expression

{<The server>: <key>.<function>(<parameter>)} <operator> <constant>


sum(600)Data and data acquired in the last 600 seconds
sum(#5)Sum of the five most recently obtained values
last()Latest value
diff()Greater than 0 indicates whether the content is changed
avg(5m)Average value in the last 5 minutes


PriorityOperatorDefinitionNotes for unknown valuesForce cast operand to float 1
1-Unary minus**-**Unknown → UnknownYes
2notLogical NOTnot Unknown → UnknownYes
3*****Multiplication0 ***** Unknown → Unknown (yes, Unknown, not 0 - to not lose Unknown in arithmetic operations) 1.2 ***** Unknown → UnknownYes
/DivisionUnknown / 0 → error Unknown / 1.2 → Unknown 0.0 / Unknown → UnknownYes
4+Arithmetical plus1.2 + Unknown → UnknownYes
-Arithmetical minus1.2 - Unknown → UnknownYes
5<Less than. The operator is defined as: A<B ⇔ (A<B-0.000001)1.2 < Unknown → UnknownYes
<=Less than or equal to. The operator is defined as: A<=B ⇔ (A≤B+0.000001)Unknown <= Unknown → UnknownYes
>More than. The operator is defined as: A>B ⇔ (A>B+0.000001)Yes
>=More than or equal to. The operator is defined as: A>=B ⇔ (A≥B-0.000001)Yes
6=Is equal. The operator is defined as: A=B ⇔ (A≥B-0.000001) and (A≤B+0.000001)No 1
<>Not equal. The operator is defined as: A<>B ⇔ (A<B-0.000001) or (A>B+0.000001)No 1
7andLogical AND0 and Unknown → 0 1 and Unknown → Unknown Unknown and Unknown → UnknownYes
8orLogical OR1 or Unknown → 1 0 or Unknown → Unknown Unknown or Unknown → UnknownYes

an or equal to. The operator is defined as: A>=B ⇔ (A≥B-0.000001) | | Yes |
| 6 | = | Is equal. The operator is defined as: A=B ⇔ (A≥B-0.000001) and (A≤B+0.000001) | | No 1 |
| | <> | Not equal. The operator is defined as: A<>B ⇔ (A<B-0.000001) or (A>B+0.000001) | | No 1 |
| 7 | and | Logical AND | 0 and Unknown → 0 1 and Unknown → Unknown Unknown and Unknown → Unknown | Yes |
| 8 | or | Logical OR | 1 or Unknown → 1 0 or Unknown → Unknown Unknown or Unknown → Unknown | Yes |

1 String operand is still cast to numeric if:

Reprinted to

Topics: MySQL Zabbix