zabbix+grafana deploy distributed monitoring system

Preface:

Zabbix is an excellent distributed monitoring server, which consists of two parts:

1. "ZABBIX server" is used to collect and display data on the web

2. "ZABBIX agent" is used to collect data and send it to the server

 

When Zabbix was installed, three virtual machines were used to test whether the monitored data was collected and displayed normally:

Server:

ZabbixServer --- IP : 192.168.246.133

Client:

ZabbixClient_1 --- IP : 192.168.246.134

ZabbixClient_2 --- IP : 192.168.246.135

 

1. Turn off the firewall

Linux firewall is our novice's nightmare. In many cases, we can ping, but we can't access Web pages. So get rid of it in the first place!

//Turn off firewall
[root@localhost ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
//Turn on and off the firewall
[root@localhost ~]# chkconfig iptables off

 

2. Install Zabbix download source

zabbix officially provides a download source. Directly execute the following command and download and install it

# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

 

After the installation is successful, check whether the Linux download source is installed correctly. If the installation is successful, there will be zabbix.repo source file

 
[root@localhost Desktop]# ll /etc/yum.repos.d/
total 28
-rw-r--r--. 1 root root 1991 Aug  4 00:13 CentOS-Base.repo
-rw-r--r--. 1 root root  647 Aug  4 00:13 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  289 Aug  4 00:13 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Aug  4 00:13 CentOS-Media.repo
-rw-r--r--. 1 root root 6259 Aug  4 00:13 CentOS-Vault.repo
-rw-r--r--. 1 root root  401 Sep 11  2014 zabbix.repo
 

3. ZabbixClient - install ZABBIX agent

ZabbixClient_1 and ZabbixClient_2 install and configure the following settings:

Turn off firewall

[root@localhost Desktop]# /etc/init.d/iptables stop
[root@localhost Desktop]# chkconfig iptables off

 

Install Zabbix official download source

[root@localhost Desktop]# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

 

Install ZABBIX agent. When downloading, the basic dependency package of ZABBIX agent will be installed automatically

[root@localhost Desktop]# yum install zabbix-agent

 

Enter the Config file of ZABBIX agent

[root@localhost Desktop]# vim /etc/zabbix/zabbix_agentd.conf

 

Configure parameters of ZABBIX agent, mainly modify IP and Hostname of Server,

Server=192.168.246.133
Hostname=localhost

 

Start ZABBIX agent

[root@localhost Desktop]# /etc/init.d/zabbix-agent start

 

4. ZABBIX server - install ZABBIX server service

Turn off firewall

[root@localhost Desktop]# /etc/init.d/iptables stop
[root@localhost Desktop]# chkconfig iptables off

 

Install Zabbix official download source

[root@localhost Desktop]# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

 

Through the download source provided by ZABBIX, download and install ZABBIX server MySQL and ZABBIX web mysql. These two MySQL databases are used to store the collected data. The web end of ZABBIX will display the drawing through these data. ZABBIX get is the instruction to collect data.

# yum install zabbix-server-mysql zabbix-web-mysql zabbix-get

 

When downloading these two packages, you will be prompted to install the basic dependency package. Among these basic packages, there are also packages on the server side of ZABBIX server. Select "y" to continue.

//The following are the basic dependency packages that need to be installed
================================================================================
 Package               Arch     Version            Repository              Size
================================================================================
Installing:
 zabbix-server-mysql   x86_64   2.4.6-1.el6        zabbix                 1.5 M
 zabbix-web-mysql      noarch   2.4.6-1.el6        zabbix                  14 k
Installing for dependencies:
 OpenIPMI-libs         x86_64   2.0.16-14.el6      base                   473 k
 fping                 x86_64   2.4b2-16.el6       zabbix-non-supported    31 k
 iksemel               x86_64   1.4-2.el6          zabbix-non-supported    47 k
 net-snmp              x86_64   1:5.5-54.el6_7.1   updates                308 k
 php-bcmath            x86_64   5.3.3-46.el6_6     updates                 39 k
 php-mbstring          x86_64   5.3.3-46.el6_6     updates                459 k
 php-mysql             x86_64   5.3.3-46.el6_6     updates                 86 k
 zabbix                x86_64   2.4.6-1.el6        zabbix                 161 k
 zabbix-server         x86_64   2.4.6-1.el6        zabbix                  22 k
 zabbix-web            noarch   2.4.6-1.el6        zabbix                 4.5 M
Updating for dependencies:
 net-snmp-libs         x86_64   1:5.5-54.el6_7.1   updates                1.5 M
 php                   x86_64   5.3.3-46.el6_6     updates                1.1 M
 php-cli               x86_64   5.3.3-46.el6_6     updates                2.2 M
 php-common            x86_64   5.3.3-46.el6_6     updates                529 k
 php-gd                x86_64   5.3.3-46.el6_6     updates                111 k
 php-pdo               x86_64   5.3.3-46.el6_6     updates                 79 k
 php-xml               x86_64   5.3.3-46.el6_6     updates                107 k

Transaction Summary
================================================================================

 

5. ZABBIX server - configure the database of ZABBIX server

Start mysql. When my CentOS is installed, it will install the MySQL software. If there is no mysql, you need to install mysql. I will start MySQL directly here

# /etc/init.d/mysqld start

 

If you start MySQL successfully, you can enter the command line of MySQL by typing mysql. Go to the command line and create the zabbix database

[root@localhost ~]# mysql
mysql> create database zabbix;
Query OK, 1 row affected (0.00 sec)

 

In mysql, check whether the zabbix you just created is created successfully. As shown in the following figure, a zabbix represents that it has been created successfully

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| zabbix             |
+--------------------+
4 rows in set (0.00 sec)

 

The next step is to execute the official zabbix provided sql statement. When installing the basic dependency package, it is already in the file. Now it can be executed directly

[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-2.4.6/create/
[root@localhost create]# mysql -uroot zabbix < schema.sql
[root@localhost create]# mysql -uroot zabbix < images.sql 
[root@localhost create]# mysql -uroot zabbix < data.sql

 

6. ZABBIX server - configure the service parameters of ZABBIX server

The configuration is in the following path:

# vim /etc/zabbix/zabbix_server.conf

 

If there is no special need, use the default configuration. My mysql account is root, so I need to modify DBuser

LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBName=zabbix
DBUser=root
DBSocket=/var/lib/mysql/mysql.sock
StartPollers=5
CacheSize=256M
SNMPTrapperFile=/var/log/snmptt/snmptt.log
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts

 

Modify zabbix's time zone. Some systems are not Beijing time. If they are foreign time, the time shown in the chart is wrong. To be conservative, set zabbix's time zone

# vim /etc/httpd/conf.d/zabbix.conf

 

Modify the following fields

php_value date.timezone Asia/Shanghai

 

Modify the time zone of zabbix's php

# vim /etc/php.ini

 

Modify the following fields

date.timezone = Asia/Shanghai

 

Start the Zabbix service and httpd:

[root@localhost create]# /etc/init.d/zabbix-server start
[root@localhost create]# /etc/init.d/httpd start

 

7. Use ZABBIX get

ZABBIX agent and ZABBIX Server are installed. On the Server side, try whether you can receive the data from the agent side. You can use ZABBIX get. When mysql was installed, ZABBIX get was already installed. ZABBIX can be used_ Get - help command to see how to use this command

[root@localhost create]# zabbix_get -help
Zabbix get v2.4.6 (revision 54796) (10 August 2015)

usage: zabbix_get [-hV] -s <host name or IP> [-p <port>] [-I <IP address>] -k <key>

Options:
  -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 <key of metric>             Specify key of item to retrieve value for

  -h --help                            Display help information
  -V --version                         Display version number

Example: zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]"

 

Test whether the data can be received. Use the following command to find that it can be received.

//Test whether the system information can be received
[root@localhost create]# zabbix_get -s 192.168.246.134 -p 10050 -k "system.uname"
Linux localhost.localdomain 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64
//Test whether CPU data can be received
[root@localhost create]# zabbix_get -s 192.168.246.134 -p 10050 -k "system.cpu.load"
0.020000

 

8. Log in to the Web side of Zabbix

On the Server side, start the Zabbix service and httpd:

[root@localhost create]# /etc/init.d/zabbix-server start
[root@localhost create]# /etc/init.d/httpd start

 

Log in to Zabbix's Web client and enter“ http://192.168.246.133/zabbix/index.php ”, by default, it will jump to the setup boot page of Zabbix:

Click Next

Click Next

Click Test connection, otherwise you cannot click Next. After the Test connection is successful, click Next

Set the port, you can directly use the default port 10051

Click Next

Click Next

Click Finish to complete the initialization boot

Enter the default account password, account: admin, password zabbix

9. Configure zabbix monitoring agent on the Web

Click Create host below

Configure according to the figure below, and input the IP and port of the agent. The default port is 10050

Click Select, select the Linux OS and zabbix Server templates, and click Select - > Add - > add, as shown in the following figure

It has been automatically started after adding. You can click Graphs to check whether there is any data coming

Click CPU jumps

Click preview

You can see that there's data coming from the agent

 

10. Install Grafana

On the ZabbixServer server, install Grafana

yum install https://grafanarel.s3.amazonaws.com/builds/grafana-2.1.1-1.x86_64.rpm

 

Download the Zabbix plug-in of Grafana, and download it on GIT. If you can't run the following command, you can first install the command "yum install git"

[root@localhost ~]# git clone https://github.com/linglong0820/grafana-zabbix

 

Copy the plug-in to the Grafana file

[root@localhost ~]# cp -r grafana-zabbix/zabbix/  /usr/share/grafana/public/app/plugins/datasource/

 

Start Grafana

[root@localhost ~]# service grafana-server start
[root@localhost ~]# chkconfig grafana-server on

 

11. Log in to Grafana and configure

After starting Grafana, enter“ http://192.168.246.133:3000/login ”You can see the page.

Enter the default user name and password, user name: admin, password: admin, click login

Configure as follows

[idea 1] Zabbix's API address is“ http://192.168.246.133/zabbix/api_jsonrpc.php ”, where IP is the server IP of ZABBIX server

[idea 2] ZABBIX's API account password is ZABBIX's Web login account and password. Account: admin, password: ZABBIX

After clicking Add, click Test Connection to test whether you can connect. Prompt "Success" to indicate successful connection, click Save

Click Dashboard, go to Home directory settings, click new, and create a new Home

Create a new Graph

Click the following red box - > select Edit - > select database ZabbixClient

Then configure it to display gorgeous data. The following figures are official diagrams:

Tags: Zabbix MySQL PHP iptables

Posted on Wed, 27 May 2020 01:54:43 -0700 by apocryia