Zabbix monitoring that combines all the advantages [based on lnmp environment]

Source: Internet
Author: User
Zabbix Overview
  1. Zabbix is an enterprise-level open-source solution that provides distributed system monitoring and network monitoring functions based on the Web interface.
  2. Zabbix can monitor various network parameters to ensure secure operation of servers. It also provides flexible notification mechanisms and allows administrators to quickly locate and solve problems.
  3. Zabbix consists of two parts: zabbix server and the optional component zabbix agent.
  4. Zabbix server can monitor remote server or network status through SNMP, zabbix agent, ping, port monitoring and other methods to monitor data collection, it can run in Linux, Solaris, HP-UX, aix, Free BSD, OS X, and other platforms.
Build a zabbix Monitoring Environment

To build a zabbix working environment, you need to start from the server and communicate with the server. The administrator needs to use a zabbix front-end interface to communicate with the zabbix server and database. The three keys (interface, server, and database) can be installed on the same server, but if you have a larger and more complex environment, installing them on different hosts is also an option. The zabbix server can directly monitor devices on the same network. If devices on other networks need to be monitored, a zabbix proxy server is required.

Zabbix features:
1. simple installation and configuration, low learning cost; 2. supports multiple languages (including Chinese); 3. free Open Source (this is important); 4. automatically discover servers and network devices; 5. distributed monitoring and centralized web management; 6. you can ignore agent monitoring. 7. user security authentication and soft authorization methods; 8. set and view monitoring results through the web interface; 9. email and other notification functions.

Prepare the zabbix Environment
This deployment belongs to Yum installation, one server and one monitored machine. 1. Install nginx1.142. Install mysql5.73. Install php7.24. zabbix 4.0.

Because zabbix collects data in C/S mode, it displays and configures data on the Web end in B/S mode. Therefore, we need to build a lamp or lnmp architecture. This article adopts the lnmp structure.

Host Operating System IP address Main Software
Zabbix Server Centos 1, 7.4 192.168.154.132 Nginx1.14, mysql5.7, php7.2, zabbix 4.0
Linux Client Centos 1, 7.4 192.168.154.20. Zabbix-agent
Deployment steps

(1) disable the Firewall:

[[email protected] ~]# systemctl stop firewalld.service [[email protected] ~]# setenforce 0

(2) Build lnmp and install nginx.

Configure nginx official sources to install and start nginx

[[email protected] ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm[[email protected] ~]# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm[[email protected] ~]# yum install nginx -y[[email protected] ~]# systemctl start nginx[[email protected] ~]# systemctl enable nginx[[email protected] ~]# netstat -ntap | grep 80

(3) Build lnmp and install MySQL.

[[email protected] ~]# yum install mariadb-server mariadb -y[[email protected] ~]# systemctl start mariadb.service [[email protected] ~]# systemctl enable mariadb.service

(4) simple configuration is required because MySQL is installed on yum.

[[Email protected] ~] # Mysql_secure_installationenter current password for root (enter for none): OK, successfully used password, moving on... setting the root password ensures that nobody can log into the mariadbroot user without the proper authorisation. set root password? [Y/n] y // whether to set the logon password for the root user new password: // enter the password re-enter new password for the first time: // confirm the password updated successfully! Reloading privilege tables... success! By default, a mariadb installation has an anonymous user, allowing anyoneto log into mariadb without having to have a user account created forthem. this is intended only for testing, and to make the installationgo a bit smoother. you shoshould remove them before moving into AProduction environment. remove anonymous users? [Y/n] N // whether to remove Anonymous user... skipping. normally, root shoshould only be allowed to connect from 'localhost '. thisensures that someone cannot guess at the root password from the network. disallow root login remotely? [Y/n] N // remote root login prohibited... skipping. by default, mariadb comes with a database named 'test' that anyone canaccess. this is also intended only for testing, and shocould be removedbefore moving into a production environment. remove test database and access to it? [Y/n] N // Delete the test database and access it?... Skipping. reloading the privilege tables will ensure that all changes made so farwill take effect immediately. Reload privilege tables now? [Y/n] y // is the privileged table reloaded now?... Success!

(5) Establish lnmp and install PHP 7.2

[[email protected] ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm[[email protected] ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm[[email protected] ~]# yum install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql -y

(6) Configure nginx to support PHP.

1) [email protected] ~] # Vim/etc/php-fpm.d/www. conf; start a new pool named 'www '. [www]; UNIX user/Group of processes; note: the user is mandatory. if the group is not set, the default user's group; will be used .; rpm: Apache choosed to be able to access some dir as httpduser = nginx // change Apache to nginx; RPM: Keep a group allowed to write in log dir. group = nginx // change Apache to nginx

2) [[email protected] ~] # Vim/etc/PHP. ini

Row 359 expose_php = off # Hide PHP version 368 line max_execution_time = 300 # execution time 378 line max_input_time = 300 # receiving data wait time 389 line memory_limit = 128 M # Each script occupies 656 lines of memory post_max_size = 16 m # post data size 799 rows upload_max_filesize = 2 m # download file size 800 rows always_populate_raw_post_data =-1 # You can use $ http_raw_post_data to receive post raw data877 row date. timezone = Asia/Shanghai # change the time zone to Asia/Shanghai

(7) Configure nginx to allow PHP to process dynamic requests.

[[Email protected] ~] # Vim/etc/nginx/CONF. d/Default. conf10 row index. php index.html index.htm; // The page format index. php30 Line Location ~ is supported ~ \. PHP $ {// Delete 31 lines of root/usr/share/nginx/html; 32 lines of fastcgi_pass 127.0.0.1: 9000; 33 lines of fastcgi_index index. PHP; 34 rows fastcgi_param script_filename $ document_root $ fastcgi_script_name; // change/scripts in fastcgi_param to $ document_root35 rows include fastcgi_params; 36 rows}

(8) Compile the PHP test page to test whether PHP is successfully built!

[[email protected] ~]# vim /usr/share/nginx/html/info.php<?php  phpinfo();?>[[email protected] ~]# systemctl start php-fpm.service[[email protected] ~]# systemctl enable php-fpm.service[[email protected] ~]# systemctl restart nginx[[email protected] ~]# netstat -ntap | grep 9000

(9) test whether PHP is successfully built by accessing the Web interface.

(10) Compile the MySQL test page.

[[Email protected] ~] # Vim/usr/share/nginx/html/info. php <? PHP $ link = mysqli_connect ('2017. 0.0.1 ', 'root', '123'); if ($ link) echo "true"; // true else echo "false" is returned successfully; // if a failure occurs, false is returned.?>

(11) test, access the Web interface, and test whether the MySQL link is successful.

(12) Create and authorize the database zabbix.

[[email protected] ~]# mysql -u root -p123123MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;MariaDB [(none)]> grant all privileges on *.* to ‘zabbix‘@‘%‘ identified by ‘123123‘;MariaDB [(none)]> flush privileges;

(13) delete empty users; otherwise, zabbix users cannot log on to the database.

Mariadb [(none)]> Select User, host from MySQL. user; + -------- + --------------------- + | user | host | + -------- + ----------------------- + | zabbix | % | root | 127.0.0.1 | root | :: 1 | localhost | root | localhost. localdomain | root | localhost. localdomain | + -------- + --------------------- + Delete all empty user names, so that you can use the zabbix user to log on to mysqlmariadb [(none)]> drop user ''@ 'localhost '; mariadb [(none)]> drop user ''@ localhost. localdomain;

(14) write code to test whether zabbix can connect to PhP.

[[email protected] ~]# vim /usr/share/nginx/html/info.php<?php $link=mysqli_connect(‘127.0.0.1‘,‘zabbix‘,‘123123‘); if ($link) echo "true"; else echo "false";?>

(15) Now that lnmp has been set up, deploy zabbix server.
[[Email protected] ~] # Rpm-I https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[[Email protected] ~] # Yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent-y

(16) import the zabbix script file to the zabbix database.

[[Email protected] ~] # Zcat/usr/share/doc/zabbix-server-mysql */create. SQL .gz | mysql-uzabbix-P zabbix // import it to the zabbix database [email protected] ~] # Mysql-uzabbix-p123123 mariadb [(none)]> Use zabbix; mariadb [zabbix]> show tables; // check whether the import is successful

(17) modify the zabbix configuration file

[[Email protected] ~] # Vim/etc/zabbix/zabbix_server.conf91 line: dbhost = localhost # Remove comment 125 line: dbpassword = 123123 # Change Password> complete configuration file: [[email protected] ~] # Grep-n' ^ '[A-Z]/etc/zabbix/zabbix_server.conf38: logfile =/var/log/zabbix/zabbix_server.log49: logfilesize = 072: pidfile =/var/run/zabbix/zabbix_server.pid82: socketdir =/var/run/zabbix91: dbhost = localhost101: dbname = zabbix117: dbuser = zabbix125: dbpassword = 123123357: snmptrapperfile =/var/log/SNMPTRAP. log475: timeout = 4518: alertscriptspath =/usr/lib/zabbix/alertscripts529: externalscripts =/usr/lib/zabbix/externalscripts565: logslowqueries = 3000

(18) Move all zabbix files to the nginx homepage.

[[email protected] ~]# cp -r /usr/share/zabbix/ /usr/share/nginx/html[[email protected] ~]# chown -R zabbix.zabbix /etc/zabbix/[[email protected] ~]# chown -R zabbix.zabbix /usr/share/nginx/[[email protected] ~]# chown -R zabbix.zabbix /usr/lib/zabbix/[[email protected] ~]# chmod -R 755 /etc/zabbix/web/[[email protected] ~]# chmod -R 777 /var/lib/php/session/

(19) Start the zabbix service, because it is monitored by itself, so the monitored service is enabled by the way.

[[Email protected] ~] # Systemctl start zabbix-server.service [[email protected] ~] # Systemctl enable zabbix-server.service [[email protected] ~] # Systemctl start zabbix-agent.service [[email protected] ~] # Systemctl enable zabbix-agent.service [[email protected] ~] # Netstat-ntap | grep 10051 // default monitoring port number


(20) restart the service.

[[email protected] ~]# systemctl restart php-fpm.service [[email protected] ~]# systemctl restart nginx[[email protected] ~]# systemctl restart zabbix-server.service

(21) Start web interface installation and access.





Note: The user name is admin and the password is zabbix.

(22) now the monitoring server is complete, and now you need to configure the monitored Server

[[email protected] ~]# systemctl stop firewalld.service[[email protected] ~]# setenforce 0
[[Email protected] ~] # Rpm-I have protected] ~] # Yum install zabbix-agent-y [[email protected] ~] # Vim/etc/zabbix/zabbix_agentd.conf13: pidfile =/var/run/zabbix/empty: logfile =/var/log/zabbix/zabbix_agentd.log43: logfilesize = 098: server = 192.168.199.129 // specify the monitoring end 139: serveractive = 192.168.199.129 // specify the monitoring end 150: Hostname = test268: Include =/etc/zabbix/zabbix_agentd.d /*. conf

(23) start the service.

[[email protected] ~]# systemctl start zabbix-agent.service[[email protected] ~]# systemctl enable zabbix-agent.service[[email protected] ~]# netstat -ntap | grep 10050

(24) after being set up by the monitoring end, you need to add it to the monitoring scope. This is configured on the Web interface.

Summary: After all the configurations are completed, the next article will explain how to monitor and how to send an email alert!

Zabbix monitoring that combines all the advantages [based on lnmp environment]

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.