Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The installation of zabbix and the setting of email alarm are explained in super details.

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Blogger QQ:819594300

Blog address: http://zpf666.blog.51cto.com/

Friends who have any questions can contact the blogger, the blogger will help you answer, thank you for your support!

A brief introduction to zabbix

Zabbix is a completely open source tool that integrates features such as cacti and nagios

Attached: SNMP (udp 161udp 162)

Many network tools support this protocol, such as common route switching, common OS

It can be used as either the management side or the managed side.

There are roughly three versions of snmp protocol, v1 v2 v3.

The security of both v1 and v2 is poor, because the transmission is plaintext, and the authentication password of V3 is encrypted by MD5/SHA digest algorithm.

Many tools support the function of network management, but for non-network devices (operating systems), we can completely put aside the insecure architecture such as snmp to achieve monitoring. So many tools are control side and agent architecture, and they have their own agent.

The main functions of Zabbix are:

① has the functions of common commercial monitoring software (host performance monitoring, network equipment performance monitoring, database, FTP and other general protocol monitoring, multiple alarm methods, detailed report chart drawing).

② supports auto-discovery of network devices and servers (this can be achieved by configuring auto-discovery server rules).

③ supports distributed, centralized display and management of distributed monitoring points, and has strong expansibility.

④ server provides a common interface (api function), you can develop and improve all kinds of monitoring (according to the relevant interfaces to write programs to achieve), easy to write plug-ins, you can customize monitoring items, alarm level settings.

⑤ data collection, support snmp (including trapping and polling), IPMI,JMX,SSH,TELNET.

⑥ custom detection; customize the frequency of data collection

⑦ server / agent and client modes.

⑧ flexible triggers (very flexible problem thresholds can be defined, called triggers).

⑨ highly customizable alarm, send notification, customizable alarm upgrade, recipient, media type.

⑩ CPU load, memory usage, disk usage, network health, port monitoring, log monitoring, and so on.

Hardware monitoring: Zabbix IPMI Interface

System Monitoring: Zabbix Agent Interface

Java monitoring: ZabbixJMX Interface

Network device monitoring: Zabbix SNMP Interface

Application service monitoring: Zabbix Agent UserParameter

MySQL database monitoring: percona-monitoring-plulgins

URL monitoring: ZabbixWeb monitoring

Description of key components of zabbix:

① zabbix server: the core component responsible for receiving report information sent by agent, which organizes all configuration, statistics, and operational data

② database storage: dedicated to storing all configuration information, as well as data collected by zabbix

GUI interface of ③ web interface:zabbix

④ proxy: optional component, often used in distributed environments with many monitoring nodes. Proxy server collects part of the data and forwards it to server, which can reduce the pressure on server.

⑤ agent: deployed on the monitored host, responsible for collecting host local data such as cpu, memory, database, etc., and sending it to server or proxy.

In addition, zabbix server, proxy, and agent all have their own configuration files and log files, and important parameters need to be configured here, which will be explained in more detail later.

The approximate flow of a monitoring system is as follows:

Agentd needs to be installed on the monitored host, which is responsible for collecting data regularly and sending it to zabbix server. Zabbix server stores the data in the database, and zabbix web displays and draws the data at the front end according to the data. Here, agentd collects data in two modes: active and passive:

Initiative: agent requests server to obtain a list of active monitoring items, and actively submits the data to be detected in the monitoring items to server/proxy

Passive: server requests agent to obtain data of monitoring items, and agent returns data.

Monitoring Architecture platform commonly used in zabbix

① server-agentd mode:

This is the simplest architecture and is often used in situations where there are few monitoring hosts.

② server-proxy-agentd mode:

This is commonly used in many machines, using proxy for distributed monitoring, effectively reducing the pressure on the server side.

The system architecture of zabbix:

Description: abbix is an enterprise-level open source solution based on Web interface that provides distributed system monitoring and network monitoring functions. With the help of Zabbix, the heavy server management tasks of operation and maintenance personnel can be easily reduced and the continuous operation of the business system can be realized.

The following is a step-by-step introduction to the deployment and use of Zabbix distributed monitoring system.

Configure IP, DNS, and gateway to ensure that you can connect to the server using the remote connection tool.

2. The process of building the LNMP environment before Zabbix deployment:

Virtual machine environment:

Ip of monitoring side and monitored side:

① zabbix Monitoring Server (i.e. zabbix_server):

192.168.1.8

Description: the server side of zabbix (if you want to monitor this machine, you need to configure zabbix agent on this machine)

② zabbix monitored host (i.e. zabbix_agent):

192.168.1.9

Description: the client of zabbix (the monitored end, zabbix agent must be configured)

System environment:

Centos7.2x86_64

1) install compilation tools and library files

The content in the figure is as follows:

Yum-y install make apr* autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel gd kernel keyutilspatch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-develkeyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-develzlib-devel libXpm* freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-develfreetype-devel

2) install mysql5.7.13

The steps for ① to install mysql here are omitted. Friends who will not install mysql5.7.13 can browse my blog at the following address:

Http://zpf666.blog.51cto.com/11248677/1908988

After ② mysql is installed, take a look at mysql's services:

③ firewall open port 3306 exception

④ mysql database password

My database password is: 123456

3) install nginx1.10.2

① decompresses zlib and pcre

Description: there is no need to compile, just decompress it.

② creates group and user accounts

③ download and install nginx

Download the source code package of nginx: http://nginx.org/download

The content in the figure is as follows:

. / configure--prefix=/usr/local/nginx1.10-with-http_dav_module--with-http_stub_status_module-- with-http_addition_module--with-http_sub_module-- with-http_flv_module-- with-http_mp4_module--with-pcre=/root/pcre-8.39-- with-zlib=/root/zlib-1.2.8-- with-http_ssl_module--with-http_gzip_static_module-- user=www-- group=www & & make&& make install

④ makes soft links.

⑤ nginx syntax detection, start nginx services, and view services

⑥ firewall open port 80 exception

⑦ access testing on a client

4) install php5.6.27

① install libmcrypt

② makes soft links.

③ install php

The content in the figure is as follows:

/ configure--prefix=/usr/local/php5.6-- with-config-file-path=/etc-- with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-mysql-sock=/usr/local/mysql/mysql.sock-- with-gd-- with-iconv--with-libxml-dir=/usr-- with-mhash-- with-mcrypt--with-config-file-scan-dir=/etc/php.d-- with- Bz2-with-zlib--with-freetype-dir-with-png-dir-with-jpeg-dir-enable-xml-enable-bcmath--enable-shmop-enable-sysvsem-enable-inline-optimization-enable-mbregex--enable-fpm-enable-mbstring-enable-ftp-enable-gd-native-ttf--with-openssl-enable-pcntl enable-sockets with-xmlrpc enable-zip--enable-soap without-pear With-gettext-enable-session-with-mcrypt--with-curl & & make & & make install

④ copies the sample configuration file and modifies

/ / set time zone

/ / suppress the display of php version information

/ / support php short tags

/ / upload file size

/ / maximum execution time of php script

/ / limit the time of receiving data by POST, GET and PUT in seconds

⑤ creates a php-fpm service startup script

⑥ provides php-fpm configuration files and edits

⑦ starts the php-fpm service and views the

5) configure nginx to support php

User www www

Worker_processes 4

# error_log logs/error.log

# error_log logs/error.log notice

# error_log logs/error.log info

# pid logs/nginx.pid

Events {

Use epoll

Worker_connections 1024

}

Http {

Include mime.types

Default_type application/octet-stream

# log_format main'$remote_addr-$remote_user [$time_local] "$request"'

#'$status $body_bytes_sent "$http_referer"'

#'"$http_user_agent"$http_x_forwarded_for"'

# access_log logs/access.log main

Sendfile on

# tcp_nopush on

# keepalive_timeout 0

Keepalive_timeout 65

# gzip on

Server {

Listen 80

Server_name localhost

Charset utf-8

# access_log logs/host.access.log main

Location / {

Root html

Index index.phpindex.html index.htm

}

Location ~\ .php$ {

Root html

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

Include fastcgi.conf

}

# error_page 404 / 404.html

# redirectserver error pages to the static page / 50x.html

#

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

Root html

}

Location / status {

Stub_status on

}

}

}

6) Test LNMP

Go to the default web page root of nginx and create a test page for .php:

Access on the client:

At this point, the LNMP is deployed.

Third, the installation of the monitoring system Zabbix-3.2.1

1) Operation on the zabbix-server side

Note: the zabbix server should install the LNMP environment in advance (the installation directory of mysql,nginx,php5 is / usr/local)

① creates users for zabbix to run

② installs dependent packages such as libcurl and net-snmp

The content in the figure is as follows:

Yum-y install net-snmp net-snmp-devel curl-devel java-1.8.0-openjdkjava-1.8.0-openjdk-devel OpenIPMI-devel libssh3-devel

Note: the OpenIPMI-devel and libssh3-devel packages must be installed using the centos online yum software source.

③ install Fping

④ install zabbix Server

The content in the figure is as follows:

. / configure--prefix=/usr/local/zabbix-- enable-server-- enable-agent-- enable-java--with-mysql=/usr/local/mysql/bin/mysql_config-- with-net-snmp-- with-libcurl--with-openipmi & & make & & make install

Note:

⑴ is best compiled with the parameter-- enable-java, which is convenient for subsequent monitoring of the use of tomcat programs.

⑵-with-ssh3 does not need to install Zabbix agent on the client server. If you need to use ssh check, you need to add this at the time of compilation. You need at least version 1.0.0 of libssh3, and you need to install the ssh development package.

⑶-with-openipmi users can use IPMI to monitor the physical characteristics of the server, such as temperature, voltage, fan operation, power supply, etc.

If ⑷ adds-- enable-proxy, it generates two commands, get and sender. As follows, it is used to receive the information from agent and send it to server at the same time.

⑤ add system soft connection

2) zabbix server configuration and startup

① creates zabbix databases and mysql users

② imports zabbix initial data

Change to the decompressed directory of zabbix:

Perform the initial data import of zabbix:

③ Editor / usr/local/zabbix/etc/zabbix_server.conf

④ starts zabbix server

You can see from the figure above that it failed to start the zabbix server service.

Let's first analyze the reasons for the failure:

As can be seen from the picture, it is said that the library file libmysqlclient.so.20 was not found. Let's use the find command to search to see if this file is available:

The library file libmysqlclient.so.20 does exist. Now let's take a look at the ld.so.conf file to see if there is a path to libmysqlclient.so.20.

You can see that there is no libmysqlclient.so.20 path in it, so we can add the libmysqlclient.so.20 path to the ld.so.conf.

Note: the ld.so.conf file is the directory setting for the system to search for dynamic link libraries. The address written in this file will automatically go to these directories to find the dynamic library files you need when running the program.

The solution is as follows:

⑴ enters the ld.so.conf file

⑵ adds two new lines at the end

⑶ allows its changes to take effect

Try to start again:

From the figure above, we can see that there is no error after startup, and the startup is successful. To confirm whether the service is really enabled, we can see that the default port number for zabbix_server listening is 10051.

⑤ add boot startup script

⑥ modifies the zabbix installation directory in the zabbix boot script

Edit the server profile:

/ / zabbix installation directory

/ / pid file path

Edit the client profile:

⑥ reloads systemctl and restarts the zabbix_server service

⑦ opens port 10051 exception on the firewall

3) configure the zabbix web page

① copies frontends to the specified web root in the installation directory:

Note 1:/usr/local/nginx/html is the default site directory for Nginx

Note 2:www is the Nginx running account

Note 3:PHP requires at least the extension to be enabled:

Gd,bcmath,ctype,libXML,xmlreader,xmlwriter,session,sockets,mbstring,gettext,mysql

② to see if all the expansion modules mentioned above are included

Comparing the extension seen in the above picture with note 3, you can't do without one, and you don't need to continue to do it without one.

I can compare here that all the extension modules exist.

③ installs zabbix_server on the page

Description: visit the Web interface http://192.168.1.8/zabbix, for related web configuration. After the configuration is completed, log in using the default user admin (password: zabbix).

⑴ enters the ZABBIX WEB installation screen

⑵ enters the ZABBIX detection screen

⑶ sets up the database, where the port can use 0 if the database is local

⑷, click Next step, and then set the details of zabbix server step by step. This step is available by default.

Click to install ⑸. After the installation is completed, if there are no errors, you will enter the completion screen.

⑹ uses the account: admin, and logs in with the default password: zabbix

The picture after logging in with ⑺ is as follows

At this point, the basic installation of ZABBIX is complete.

④ what you see at this time is the English page, we now let it display the simplified Chinese page

⑴ because the zabbix library has already set the utf-8 character when installing the database

First of all, make sure that Chinese support is enabled for zabbix:

Description: log in to the data directory of the zabbix server (the previously deployed zabbix data directory is / usr/local/nginx1.10/html/zabbix/), and open the locales.inc.php file.

We can see from line 55 that zabbix supports simplified Chinese.

After ⑵ logs in to zabbix, click the "user" icon in the upper right corner and set the language to "Chinese"

⑤ solves the problem of Chinese garbled in zabbix drawing

⑴ select a Chinese font from Control Panel-> Font-> under windows.

For example, "italics"

⑵ copies it to the fonts directory on the web side of zabbix

⑶ moved the original font file DejaVuSans.ttf to another location

Note: if the suffix TTF of your simkai file is uppercase, be sure to change it to lowercase ttf.

⑷ then modifies the font configuration in the code include/defines.inc.php file to replace the font setting from DejaVuSans to simkai

In this way, after modification, the Chinese text in the zabbix monitoring drawing will not appear garbled.

IV. Installation of zabbix client

Note: since we want to monitor, we need to add the host to be monitored. Before adding the host, we first need to install agent on the tested host. It is relatively easy to install agent. We also follow the process of installing server and download the software package. When compiling, we can only select agent.

192.168.1.9 as the monitored end of zabbix, it provides web and mysql application services.

1) install zabbix and configure zabbix agent

① install zabbix agent

② configuration Boot Auto Boot

③ modifies the zabbix installation directory in the zabbix boot script

Edit the client profile:

④ overload systemctl

⑤ Editing zabbix_agentd.conf Fil

Note: both Server and ServerActive specify the IP address of zabbixserver, but the difference is that the former is passive and the latter is active. In other words, the configuration of Server is used to allow the 192.168.1.8 ip to come to me to get data. ServerActive's 192.168.1.8 means that the client actively submits data to him.

Hostname=XXX, the name of this definition must be the same as the name of host in the web page.

⑥ starts zabbix_agentd

⑦ firewall open port 10050 exception

At this point, the basic environment of the zabbix3.2.1 monitoring system has been installed.

2) add monitoring items to zabbix and add monitoring to Linux hosts

Note: first add host monitoring to "configuration"-"Host" to monitor os resources: memory, cpu,io, load, bandwidth, etc.

When ① logs in to zabbix, click "create Host" in "configuration"-"Host":

② in the "host" label, fill in the relevant information

Other options are available by default.

③ in the "template" tab, fill in the relevant information

At this point, the configuration of Zabbix monitoring Linux host is complete, as shown in the following figure:

After a period of time, ④ can come and see if the monitoring chart has come out.

3) add monitoring to the mysql of Linux hosts

Note: zabbix3.0 server already has its own mysql template, just configure the agent client, and then add a template to the host on the web side.

① first adds permissions to the client's mysql, that is, the local machine uses the zabbix account to connect to the local mysql (operate on the zabbix_agent client)

② creates the. my.cnf connection file under the zabbix_agent service directory (note that there is a ".")

Description: the zabbix installation directory is / usr/local/zabbix

Note:

If ⑴ is authorized for localhost in the database grant, there is no need to add the host parameter in this .my.cnf [as configured above]

⑵ if the grant is authorized against the native ip (such as 192.168.1.9), then the host parameter should be added to the .my.cnf file to specify it.

That is, in the .my.cnf file, add:

Host=192.168.1.9

Socket=/usr/local/mysql/mysql.sock

User=zabbix

Password=123456

③ configures the key file of mysql

Description: this can be copied from the unzipped package when zabbix3.2 is installed

Extract the directory / root/zabbix-3.2.1/conf/zabbix_agentd/userparameter_mysql.conf copy to the / usr/local/zabbix/etc/zabbix_agentd.conf.d/ directory on the zabbix_agent client during installation from the zabbix_server server.

④ looks at the userparameter_mysql.conf file and sees a path setting similar to HOME=/var/lib/zabbix, replacing all the paths with / usr/local/zabbix/etc/, the same directory path as the .my.cnf file above.

In addition, pay attention to the mysql command path in the userparameter_mysql.conf file (make the system environment variable of mysql in advance in case the mysql command is not recognized by the system).

⑤ restarts the zabbix_agent service

Note: if stop cannot shut down the service, you can use the "pkill-9 zabbix_agent" command to forcibly kill the process.

You can also use "/ usr/local/zabbix/sbin/zabbix_agentd" to start the service.

⑥ then performs a command line test on the zabbix_server server

The solution is as follows:

⑴ adds an absolute path before the mysql command in userparameter_mysql.conf (operates on zabbix_agent)

⑵ modifies three places

⑶ restart service

Go back to the zabbix_server server again for command line testing:

Note 1: if there is a number like this string of key, it means that if you configure ok, the server can monitor the mysql data of the client!

After success, add the MySQL template corresponding to the host in the monitoring interface and ok it.

Note 2:

Introduction to zabbix_get command

Parameter description:

-s--host: specify the client hostname or IP

-p--port: client port. Default is 10050.

-I--source-address: specify the source IP and write the ip address of the zabbix server. Generally leave it blank. If the server has more than one ip, you can specify one.

-k--key: the key you want to get

Zabbix_get acquires data:

⑴ acquires load

⑵ gets the hostname

⑦ logs in to the zabbix monitoring interface, and you can see the built-in mysql monitoring template in "configuration"-"template".

⑧ can add the monitoring template of mysql (included with zabbix) to the corresponding CVM monitoring configuration:

Below the ⑨ is the effect diagram of the mysql monitoring item.

⑴ monitors the bandwidth of mysql: the number of bytes sent and received by mysql can be viewed in real time at the front end of zabbix. Where bytes received represents the number of bytes received from all clients and bytes sent represents the number of bytes sent to all clients.

⑵ monitors the operation status of mysql: in the front end of zabbix, you can view the number of operations per second of various SQL statements in real time.

Fifth, zabbix3.2.1 mail alarm setting

Description: zabbix monitoring server and client have been deployed, monitored hosts have been added, and zabiix monitoring is running normally.

An email alarm is set on the zabbix server. When the monitored host goes down or reaches the trigger preset value, it will automatically send an alarm email to the specified mailbox.

The specific operations are as follows (the operation is performed on the Zabbix monitoring server):

1) install two dependent packages of sendmail

2) extract sendmail, then copy sendemail to / usr/local/bin/ directory, add executable permissions, and then modify users and groups

3) execute # / usr/local/bin/sendEmail-h to view sendEmail's help

4) Let's start the email test.

① first apply for a mailbox. I will take NetEase's 163mailbox as an example.

Log in to ② mailbox and apply for authorization code

Note: here I set my authorization code to 123abc

③ officially starts testing

From the picture above, we can see that the email was not sent successfully and there was an error.

The reason is: the incompatibility between the sendemail software and the ssl version in perl5, which can be solved by modifying the contents of sendemail.

The solution is as follows:

Line 1906 is changed to read as follows:

Retry the test again:

Let's go to the mailbox to check:

The main options for the command are described:

/ usr/local/bin/sendEmail # command main program

-f from@126.com # Sender mailbox

-tto@126.com # recipient mailbox

-ssmtp.126.com # smtp server for the sender's mailbox

-u "I am the subject of the message" # the title of the message

-omessage-content-type=html # the format of the message content. Html indicates that it is in html format

-omessage-charset=utf8 # email content coding

-xufrom@126.com # user name of the sender's mailbox

-xp123abc # Sender email password or authorization code

-m "I am the content of the email" # the specific content of the email

5) if the test is successful, we can also create an alarm script and send us an email automatically

① enters the / usr/local/zabbix/share/zabbix/alertscripts/ directory

② creation script

The content in the figure is as follows:

#! / bin/bash

To=$1

Subject=$2

Body=$3

/ usr/local/bin/sendEmail-o tls=auto-f dabiaoge999@126.com-t "$to"-s smtp.126.com-u "$subject"-o message-content-type=html-o message-charset=utf8-xu dabiaoge999@126.com-xp 123abc-m "$body"

③ gives script executable permission

④ executes script test and sends email.

⑤, check the mailbox again.

6) zabbix web side configuration

After the email script above ① is configured, you need to add the alarm media on the web side. On the web page Management, alarm Media types page, click create Media Type on the right.

② goes to the creation page, then enter the name "email alarm script", type select script, name select mail.sh, click the add button, add three script parameters, namely {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE}, for to, subject and body in mail.sh. After adding, click the add button below, and our alarm medium will be created.

After ③ has created the alarm medium, we need to associate the alarm medium with our users. Click manage, user, and then select our user admin can also create a new user, click the user name to enter the user configuration interface. Click the alarm media, then click add, select the email alarm script we created in the previous step, enter the recipient, select the alarm time and type, and then click add to associate the created alarm media with our users.

What ④ needs to do now is to create a trigger action, that is, if the system fails, trigger this action, and then send an alarm email to our mailbox. Click configure, select actions, and then click create Action on the right.

Write the action name and trigger condition we defined in the name of the action page.

Description: the step is 1-3, that is, from 1 to 3. Once the failure occurs, the Email.sh script is executed to send an alarm email to the zabbix user.

If the failure lasts for 1 hour, it will only be sent 3 times, and the first 3 mailboxes will be sent to zabbix users with an interval of 0 seconds.

If you change it to 1-0, it means there is no limit. Infinite transmission

Then set the restore operation:

⑤ alarm test

Shut down the zabbix_agent process on the 192.168.1.9 server and wait for the mail.

Finally, click "report"-> "Action Log" to see the number of times the action was triggered (see also on the right to see the email sent status "sent").

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report