Deploy zabbix monitoring system and email Alarm Mechanism in lamp Architecture

Source: Internet
Author: User
Tags snmp
A preliminary understanding of zabbix:

Zabbix can monitor various network parameters to ensure secure operation of server systems. It also provides a flexible notification mechanism for system administrators to quickly locate and solve various problems. Is an enterprise-level open-source solution that provides distributed system monitoring and network monitoring functions based on the Web interface. Only the Monitored object supports the SNMP protocol or runs the zabbix_agents agent.
AGENT: the host collects data by installing the agent.
Server: collects data sent by the agent, writes data to the database (MySQL, Oracle, etc.), and displays the data on the Web Front end through PHP + Apache.

SNMP:

SNMP stands for "Simple Network Management Protocol", which means "Simple Network Management Protocol ". SNMP is a Simple Network Management Protocol, which belongs to the application layer protocol in the layer-5 TCP/IP protocol and is used for network management. SNMP is mainly used to manage network devices.

How zabbix works:

The agent is installed on the monitored host. The agent periodically collects local data from the client and sends the data to the zabbix server. The zabbix server receives the data and stores the data in the database, based on zabbix web, users can view data and display images on the front end. When zabbix monitors a specific project, a trigger threshold is set for the project to be changed. When the monitored metric exceeds the threshold set by the trigger, necessary actions are performed, including: send messages (emails, text messages), send commands (shell commands, reboot, restart, install, etc ).

Zabbix has five important components:

1. zabbix server: the core component responsible for receiving the report information sent by the agent. All configuration, statistical data, and operation data are organized by the agent;
2. database storage: used to store all configuration information and data collected by zabbix;
3. Web Interface: GUI interface of zabbix, which is usually run on the same host as the server;
4. Proxy: an optional component. It is often used in a distributed monitoring environment. The proxy server collects monitoring data from the monitored end and sends it to the server in a unified manner;
5. AGENT: deployed on the monitored host, collects local data and sends it to the server or proxy;

Zabbix basic component topology:

The following describes how to deploy zabbix.
Lab environment:

Stkaiti Font File Link: https://pan.baidu.com/s/1EC_jdOhRGjDJewAKueaTUg
Extraction code: zmv4
1. Deploy the lamp Architecture
Download the installation package for lamp

[[Email protected] ~] # Yum install httpd mariadb-server PHP-mysql PHP-Gd libjpeg * PHP-ldap php-odbc php-pear PHP-xml php-xmlrpc php-mhash-y

Configure the Apache main configuration file

[[Email protected] ~] # Vim/etc/httpd/CONF/httpd. conf
Servername www.yun.com: 80 # modify the Domain Name
Directoryindex index.html index. php # make Apache support PHP

To connect zabbix to the Internet, set the China Time Zone

[[Email protected] ~] # Vim/etc/PHP. ini
Date. timezone = PRC

Enable httpd and MySQL

[[Email protected] ~] # Systemctl start httpd. Service [[email protected] ~] # Systemctl start mariadb. Service [[email protected] ~] # Netstat-ntap | egrep '80 | 808080' # view the ports of the two services: TCP 0 0 0.0.0.0: 3306 0.0.0.0: * Listen 3306/mysqld tcp6 0 0 ::: 80 ::: * Listen 38242/httpd

Reconfigure mariadb database Parameters

[[Email protected] ~] # Mysql_secure_installation set root password? [Y/n] y # Do you want to set the password to Remove anonymous users? [Y/n] n # Do you want to delete the Default User disallow root login remotely? [Y/n] n # Do you want to disable root remote logon to remove test database and access to it? [Y/n] n # Do you want to delete the test database reload privilege tables now? [Y/n] y # Whether to initialize the database

Create a zabbix Database

[[Email protected] ~] # Mysql-uroot-pmariadb [(none)]> Create Database zabbix Character Set utf8 collate utf8_bin; # create a zabbix database mariadb [(none)]> grant all on zabbix. * To 'zabbix' @ '%' identified by '000000'; # create a management user for the zabbix database mariadb [(none)]> flush privileges;

Create a PHP test Homepage

[[email protected] ~]# vim /var/www/html/index.php    <?php  phpinfo();?>

Write a test script to test whether PHP can connect to the database

<?php$link=mysql_connect(‘192.168.199.129‘,‘zabbix‘,‘123123‘);if($link) echo "

When using zabbix users to log on to the database, sometimes the logon fails. This is because the local user cannot log on because there are empty users in it, so you need to delete empty users.

[[Email protected] ~] # Mysql-u zabbix-P # logon Failure: Enter Password: Error 1045 (28000): Access denied for user 'zabbix' @ 'localhost' (using password: Yes) [[email protected] ~] # Mysql-u root-pmariadb [(none)]> Select User, host from MySQL. user; # local users cannot log on due to idle user occupation + -------- + --------------------- + | user | host | + -------- + ----------------------- + | zabbix | % | root | 127.0.0.1 | root |:: 1 | localhost | root | localhost. localdomain | root | localhost. localdomain | + -------- + --------------------- + 7 rows in SET (0.00 Sec) mariadb [(none)]> drop user ''@ 'Localhost'; # Delete empty user query OK, 0 rows affected (0.01 Sec) mariadb [(none)]> drop user ''@ 'localhost. localdomain '; # Delete empty user query OK, 0 rows affected (0.00 Sec) [[email protected] ~] # Mysql-u zabbix-P # You can log on again to mariadb [(none)]>

So far, the lamp architecture has been deployed.

2. Deploy zabbix Server

[[Email protected] ~] # Yum install PHP-bcmath PHP-mbstring-y # download two PHP dependency packages [[email protected] ~] # Rpm-IVH http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm # download zabbix Yum source, after the installation is complete, the repo file will automatically generate [email protected] ~] # Yum install zabbix-server-mysql zabbix-web-mysql-y # Install the zabbix package

Modify zabbix configuration file

[[Email protected] ~] # Grep-n' ^ '[A-Z]/etc/zabbix/zabbix_server.conf # The following are the lines to be modified: logfile =/var/log/zabbix/zabbix_server.log49: logfilesize = 072: pidfile =/var/run/zabbix/zabbix_server.pid82: socketdir =/var/run/zabbix101: dbname = zabbix117: dbuser = zabbix125: dbpassword = 123123 # Change Password to zabbix login password 357: snmptrapperfile =/var/log/SNMPTRAP. log475: timeout = 4518: alertscriptspath =/usr/lib/zabbix/alertscripts529: externalscripts =/usr/lib/zabbix/externalscripts565: logslowqueries = 3000
[[Email protected] ~] # Vim/etc/httpd/CONF. d/zabbix. conf # modify the time zone php_value date. timezone Asia/Shanghai [[email protected] ~] # Vim/usr/share/zabbix/include/defines. inc. PHP # corrected Chinese garbled characters in the chart: % S/graphfont/kaiti/G # Replace graphfont in the configuration file with kaiti [[email protected] ~] # Cp stkaiti. TTF/usr/share/zabbix/fonts/# copy the corresponding font file from Microsoft to/usr/share/zabbix/fonts/

Enable zabbix Server

[[Email protected] ~] # Systemctl start zabbix-server.service [[email protected] ~] # Systemctl enable zabbix-server.service [[email protected] ~] # Netstat-ntap | grep 10051 # view port tcp 0 0.0.0.0: 10051 0.0.0.0: * Listen 40703/zabbix_server tcp6 0 0 ::: 10051 ::: * Listen 40703/zabbix_server [[email protected] ~] # Systemctl restart httpd. Service # restart apache service http: // 192.168.199.129/zabbix # log on to the zabbix page in the browser

First, we can see the zabbix version:

All the options here are OK, indicating that the configuration is correct:

The password is the logon password of zabbix:

Enter zabbix as the name:


The default username and password are admin and zabbix:

After logging in, you will be directed to the zabbix monitoring page:

Click the Avatar in the upper-right corner to select a language. Here I select Chinese:

3. Install the monitored end

[[Email protected] ~] # Systemctl stop firewalld. Service # disable firewall [[email protected] ~] # Setenforce 0
[[Email protected] ~] # Rpm-IVH http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm # download Yum source [[email protected] ~] # Yum install zabbix-agent-y # The agent package needs to be installed on the monitored end. If you want to monitor this machine, you can install the package on the monitoring server.

Change configuration file

[[Email protected] ~] # Grep-n' ^ '[A-Z]/etc/zabbix/zabbix_agentd.conf # modify the configuration file option 13: pidfile =/var/run/zabbix/zabbix_agentd.pid32: logfile =/var/log/zabbix/zabbix_agentd.log43: logfilesize = 098: Server = 192.168.199.129 # point the address to server 139: serveractive = 192.168.199.129 # point the address to server 150: hostname = test # The name can be customized to 268: Include =/etc/zabbix/zabbix_agentd.d /*. conf

Enable Service

[[Email protected] ~] # Systemctl start zabbix-agent.service [[email protected] ~] # Systemctl enable zabbix-agent.service created symlink from/etc/systemd/system/multi-user.target.wants/zabbix-agent.service to/usr/lib/systemd/system/zabbix-agent.service. [[email protected] ~] # Netstat-ntap | grep zabbix # view port tcp 0 0.0.0.0: 10050 0.0.0.0: * Listen 40351/zabbix_agentd tcp6 0 0 ::: 10050 ::: * Listen 40351/zabbix_agentd

After the configuration is complete on the server, you can go to the zabbix monitoring page to configure
First, add the monitored server to the monitoring page.

Configure basic host item information

Configure the template option to add the module to be monitored

View added host information

Return to the main interface, click Refresh, and the monitoring information will be displayed later.

4. Configure the mail alarm function-configure it on the Monitoring Server

[[Email protected] ~] # Yum install mailx-y # download the email service [[email protected] ~] # Vim/etc/mail. RC # Add the following configuration at the end of the file: Set From = mailbox address set SMTP = SMTP. QQ. comset SMTP-auth-user = Email address set SMTP-auth-Password = *********** # If you enter QQ mail, set SMTP-auth = Login

[[Email protected] ~] # Systemctl restart Postfix. Service # restart the mailbox service [[email protected] ~] # Echo "Hello World" | mail-s "testmail" email address # Send a test email

You can see that I received an email in my QQ mailbox.

[[Email protected] ~] # Vim/usr/lib/zabbix/alertscripts/mail. Sh # write an email script. The script path must be correct #! /Bin/bash # Send mailmessages = 'echo $3 | tr' \ r \ n' subject = 'echo $2 | tr' \ r \ N'' \ n' echo "$ {messages}" | mail-s "$ {subject}" $1>/tmp/mail. log 2> & 1
[[Email protected] ~] # Chmod + x/usr/lib/zabbix/alertscripts/mail. Sh # grant the script execution permission [email protected] ~] # Touch/tmp/mail. log # create an email log file [[email protected] ~] # Chown-r zabbix. zabbix/tmp/mail. log # grant permissions to zabbix users [[email protected] ~] # Chown-r zabbix. zabbix/usr/lib/zabbix/

Send another test email and run it in script.

[[Email protected] ~] # Cd/usr/lib/zabbix/alertscripts/[[email protected] alertscripts] #. /mail. sh email address "Yun" "hahahahaha" # The sending format is "Address", "title", and "content"

6. Configure zabbix email Alarm Mechanism
1. Select the alarm media type


2. Select Manage user



3. Define the sending form of the alarm email in the action configuration item




4. Configure the mail sending form after the recovery operation

7. Test: If I disable the monitored service to simulate a service fault, one zabbix will send an email reminding me that the service has been repaired when I open the service again, one zabbix will also send a recovery email.

[[Email protected] ~] # Systemctl stop sshd. Service # disable the SSH service on the monitored end


Then you will receive the email:

[[Email protected] ~] # Systemctl start sshd. Service # enable the SSH service on the monitored end again


So far, the zabbix monitoring system has been set up.

Deploy zabbix monitoring system and email Alarm Mechanism in lamp Architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.