zabbix5.0 installation documentation

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

https://www.zabbix.com/documentation/current/manual/concepts/server

server installation

#Download configuration using yum

# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# yum clean all

# vim  /etc/yum.repos.d/zabbix.repo
    [zabbix-frontend]
    ...
    enabled=1
    ... 

#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
password
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=192.168.112.21			#Specify the address of the ZABBIX server
	ServerActive=192.168.112.21		#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"
UserParameter=sys.mem.free,free -h | awk 'NR==2{print $4}'

#Note that when the $1 used is not a bit parameter, two are required$
UserParameter=disk.space[*],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 192.168.112.22 -p 10050 -k tcp_conn
2


[root@localhost yum.repos.d]# zabbix_get -s 127.0.0.1 -p 10050 -k sys.mem.free
549M
[root@localhost yum.repos.d]# zabbix_get -s 127.0.0.1 -p 10050 -k mysql.questions
 287254
[root@localhost yum.repos.d]# zabbix_get -s 127.0.0.1 -p 10050 -k disk.space['/dev/sda1']
1014M

Configure monitoring items on the web side

View and define monitoring items

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

Script

vi /etc/zabbix/get_tcp.sh
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}'
} 
$1

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

ZABBIX get test

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

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')


corpid='ww7cc01b78a88e8a46'
appsecret='Kba8A5Ok_N3RAXTYq0Uyy30A1zepyuGKjhBDVjRECXY'
agentid=1000002
#Get accesstoken
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']

#send message
msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken

touser=sys.argv[1]
subject=sys.argv[2]
#toparty='3|4|5|6'
message=sys.argv[2] + "\n\n" +sys.argv[3]

params={
        "touser": touser,
#       "toparty": toparty,
        "msgtype": "text",
        "agentid": agentid,
        "text": {
                "content": message
        },
        "safe":0
}

req=requests.post(msgsend_url, data=json.dumps(params))

logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message)
# test

python weixin.py '$own ID' '$Message title' '$Message content'

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


web side configuration

{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}

Message sending failed

zabbix common options

[root@localhost yum.repos.d]# zabbix_server -h
usage:
  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.

Options:
  -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.

zabbix_get

RUNNING ZABBIX GET

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

shell> cd bin
shell> ./zabbix_get -s 127.0.0.1 -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 192.168.1.1 -p 10050 -k "web.page.regexp[www.zabbix.com,,,\"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 
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=127.0.0.1			#server address
ServerActive=127.0.0.1		#Active mode, server address
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf

Key value of monitoring item

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

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

restart zabbix_agent

test

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

[root@localhost yum.repos.d]# zabbix_get -s 127.0.0.1 -p 10050 -k sys.mem.free
549M
[root@localhost yum.repos.d]# zabbix_get -s 127.0.0.1 -p 10050 -k mysql.questions
 287254
[root@localhost yum.repos.d]# zabbix_get -s 127.0.0.1 -p 10050 -k disk.space['/dev/sda1']
1014M


#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 127.0.0.1 -p 10050 -k test['aa','bb']
aa

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

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

FUNCTION PARAMETERS

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

OPERATORS

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 https://blog.csdn.net/weixin_47677347/article/details/121736803

Topics: MySQL Zabbix