zabbix installation and monitoring

   做运维前前后后也有2年多了,时间不长不短。有些牛逼的可能已经学到很多,收入颇丰。但是自己的成长却很慢。年龄也越来越大。自己有时候想学点东西,但是上班的时候没有时间也没有氛围学习,下班后的时间很少,就不想学习。想学习的时候却感觉自己不懂的东西太多,什么都想学习,却往往都是半途而废,今天思考了一下,还是一件件的慢慢来吧。
         正好目前公司的测试服务器的zabbix服务器需要重新安装并监控。感觉这是 一个系统学习的好机会,以前对于监控,会的可能就是简单的安装、添加主机、添加监控项、添加默认的魔板,像邮件微信报警什么的都是前人写好的,自己只需要添加进去进行。没有自己添加过自定义的监控项啥的。今天这个文章就是督促自己讲zabbix认真的学习下,第一可以回顾下知识点。第二就是多学点zabbix的知识。
         系统环境:ubuntu-server-16.04.6 使用zabbix4.0版本
         官方安装文档链接:https://www.zabbix.com/documentation/4.0/zh/manual/×××tallation/×××tall_from_packages/debian_ubuntu
         wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+xenial_all.deb 下载安装包
         使用ubuntu的安装deb包的命令(ubuntu的命令和centos有不少区别。感觉大家使用centos系统的较多,如有不明白的命令请自行查询。)
         sudo dpkg -i zabbix-release_4.0-2+xenial_all.deb 
       更新软件库,sudo apt-get update ,并升级软件库。sudo  apt dist-upgrade 
      安装 Zabbix server 并使用 MySQL 数据库 
        sudo apt ×××tall zabbix-server-mysql
        安装 Zabbix 前端
         sudo apt ×××tall zabbix-frontend-php
         使用 MySQL 来导入 Zabbix server 的初始数据库 schema 和数据
         sudo  zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix
         配置zabbix-server配置文件,# vi /etc/zabbix/zabbix_server.conf

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=$password

Run the following command to start Zabbix server process, and make it boot from the start:

#sudo service zabbix-server start
#sudo update-rc.d zabbix-server enable

Service apache2 restart
sudo Service apache2 restart
of ZABBIX front of the Apache configuration file is located /etc/apache2/conf-enabled/zabbix.conf. Although some PHP configuration parameters. But it is necessary to cancel the "date.timezone" notes, and set to the correct time zone
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
php_value date.timezone Europe / Riga

Install and start Agent
sudo APT ××× the Tall zabbix-Agent && sudo Service Agent zabbix-Start
The next step is landing https: // ip / zabbix initial setting initial password is Admin, zabbix

More pictures. This step can be omitted.

##########

Before adding a host, create a host group. The actual environment, the server have different uses, depending on the users into different groups, arranged inside the host group, the host group created. Such as databases, server backup service ,, and so on.

Before adding hosts, to be installed on the monitored server zabbix-agent and start,
zabbix client sends data to the server-based passive sub-modes, the active mode is zabbix the client sends data to the server, passive mode passively wait for the server to fetch data.

Active mode process:

Every so often a client initiates a connection request to the server -> server receives the request, item information query client needs to take, and sent to the client -> client sends the server to collect data -> End.

Passive mode process:

The client open a default port 10050, waiting for the server to fetch the data and then collect client data sent to the server, and then end.

I guess the active mode too strenuous, if not thousands of client exhausted. Quickly asked the next degree of your mother.
The following are active and passive acquiescence of default scenarios and the advantages and disadvantages.

Disadvantage of passive mode:
When the host server to monitor a certain number, by the end Server to collect data, Zabbix will appear serious performance problems, mainly as follows:

1, when the monitor is an order of magnitude when the end arrives, Web operation very slow, prone 502
2 layers fracture
3, open process (Pollar) too much, even reducing the number of item, after a certain amount of machines will has a problem

So the following two main optimization direction to consider:

1, a node is added or Proxy Node do distributed monitoring mode
2, to adjust the active mode Agentd

Since the first program need to increase physical machine, so the first try of the second program.

zabbix add a host when the default is to use passive mode, usually hundreds of small business server can use passive mode to monitor.
The following is a passive mode and an active mode profile exemplary agent:
Passive Mode:
grep '^ [aZ]' /etc/zabbix/zabbix_agentd.conf
the PidFile = / var / RUN / ZABBIX / zabbix_agentd.pid
the LogFile = / var / log / ZABBIX / zabbix_agentd.log
the LogFileSize = 0
StartAgents =. 3
Server * =
ServerActive = 127.0.0.1
the Hostname = zabbix_client
HostMetadataItem = system.unam

主动模式
grep '^[a-Z]' /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
StartAgents=0
ServerActive=
Hostname=主机名
Include=/etc/zabbix/zabbix_agentd.d/
.conf

** Note that the same host name when adding a host of needs and configuration files inside the Hostname

Specific steps I do not write, I configured in accordance with the following article, explained in more detail. Active mode also successful, https://blog.51cto.com/liqingbiao/1983851

##############

Templates are core zabbix because template integrates all the content you want to monitor and graphics display, and so, after zabbix installation deployment is complete, comes with a lot template (template network devices, operating system templates, common application software templates), these template able to meet about 80% of the applications we need, so under normal circumstances we do not need to separately create a template.
General create host, add a template, if linux server, be sure to add tempalte OS linux template, if there are other services, such as nginx, databases and so on. Further added to the corresponding mode. A host can have multiple templates.

There are several categories of templates, application set, monitor items, triggers, graphs, graphics polymerization, auto-discovery rules, web scene and so on.
The more important is to monitor common items, triggers, graphs.
Equivalent to the monitoring application set Items, click Templates Templates can find tempalte OS linux kan see a set of 10 applications, there are cpu, filesystem, memory and so on. You can speak it into an application focus in the creation of monitored items. You can also create your own custom set of applications.
Term monitoring is more important, is the basis for monitoring. Or in tempalte OS linux example, click to select the template tempalte OS linux, click on the monitored item, you can see from left to each monitoring item name were monitored items, triggers, key values
created using a template in different keys monitoring entries to tcp port monitoring as an example, check tcp port is in listening state, the key is net.tcp.listen [port], where grammar is not too much to explain the key details, see the official documentation explains. https://www.zabbix.com/documentation/4.2/manual/config/triggers/trigger
If there is a project in a production environment since the port is 3456, you can monitor when creating the item
key to select net.tcp. listen [3456], as well as monitoring key common catalog,
monitoring items can be added to an existing template, you can also add monitoring items in a newly created template, you can also create a host entry under surveillance, the recommended practice is to create a new template, and then add the set of applications required in this template, monitored item, then add the host in the back when this template to create a link to the next host. The reason is not recommended to create a monitored item at the host, if there are multiple hosts, each monitor has the same content, you will need to monitor all create the same item in each host.
Once you have created monitoring items, the next step is to add items to their monitoring triggers, this is optional.
In the web interface you can see there are five monitoring items list, namely the severity of the value of the name expression, status, click on the upper right corner to create a trigger,

    这里面重点的是创建监控项的表达式,根据zabbix自带的监控项修改下参数就行,可以满足中小企业80% 的需求。
    这里我找到一个很简单的例子,键值是vfs.file.exists[$file],监控系统会不会出现这个文件,返回值为1就是找到,返回值为0就是没找到
    找到一个主机,点击这个主机的监控项,点击创建监控项   ,![](https://s1.51cto.com/images/blog/201906/28/876076d170 c871914e89f6691ddcfc9e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

    要想学会写触发器表达式,首先需知道触发器表达式的几种常见函数。
    常见的有diff,last,avg,change,nodata等等。具体的用法我这不做具体介绍,因为我自己也不太清楚,等到用的时候再查。

We've already done a flip-flop, the next step is to trigger an alarm issued to micro-letters by mail or sent, I am here to send by mail. Sendemail tool is used to send.

Without sendemail function, you can install sudo apt-get install sendemail online server
sendemail commands specific usage friends can not themselves access to information.

Installed after the tests issued messages. By default mailbox pop3, smtp and other services have opened
$ sendemail -f -t sender recipient -s smtp server, -u "message subject" -o message-content-type = html -o message-charset = utf8 -xu sender mailbox -xp Outbox password -m "text file"

Modify zabbix-server configuration file,
the script AlertScriptPath = / usr / lib / zabbix / alertscripts E-mail or stored in this micro-channel
and restart zabbix-server service

The second part shell send the script editor

! # / bin / the bash
RECIPIENT = $. 1
Subject 2 $ =
Message $ =. 3
SendEmail -q -f "??? = UTF. 8-B echo **公司监控|base64? = <Outbox>" -t "$ recipient" -u "$ subject" - m "message" -o message-content -type = html -o message-charset = utf8 -xu sender mail outbox password -xp

After adding scripts, alarms management the following media types, create media type, see below
zabbix installation and monitoring
script is the name of the script above created under / usr / lib / zabbix / alertscriptsl path.

Zabbix web mail interface to add recipients
in the main administration web interface - Users - Add User

zabbix installation and monitoring

Alias, users can customize the family name, select the group administrator.
Then click on the alarm medium, add the recipient or recipient group
zabbix installation and monitoring

Add and update to take effect.

The configuration of the operation, a new operation.
Bell script parameters can be passed to the action, the specific see below.zabbix installation and monitoringzabbix installation and monitoringzabbix installation and monitoringzabbix installation and monitoring

The figure above variables being I do not know, is a reference to the company's test environment. If you want to know about your own query data. Or in my subsequent blog, I will slowly learn. Today's task is the result, give yourself a little sense of accomplishment, then slowly and optimize digestion.

Remember earlier we customized a key vfs.file.exists [$ file], it is whether there is a directory under the supervision of the host to produce a document, we create a path to this file. Zabbix test
whether the monitor to generate files in the host.

zabbix installation and monitoring

Currently trigger trigger key changes according to zabbix comes parameters can send messages to specified users. But the content of the document is not very attractive and user-friendly. It needs to be optimized.
Well, today busy take a break to do a little experiment monitored items and triggers and alarm messages sent.
Next we will study together and auto-discovery, auto registration, and automated monitoring.

Guess you like

Origin blog.51cto.com/12809205/2415144