Fun Linux to build zabbix monitoring system and troubleshooting

Insert picture description here

Why you need to understand the monitoring architecture

For example: our eight-member team is called "Ghost Eight Immortals"; if we want to fight with others, the 13-member team is called "Thirteen Taibao". According to the name, we can't do it. Even if we have done it, our The loss is definitely greater than others.

Therefore, according to different network environment, monitoring scale and other comprehensive factors, choose a suitable monitoring architecture.

  1. The direct connection architecture is also called the server-client architecture. It is suitable for occasions where the network environment is simple and the scale of monitoring is small. For example, it is like "the peerless double pride", with only two people.
  2. The proxy architecture is suitable for monitoring medium-sized networks.
  3. Node architecture, translate Chinese nodes, each node has its own configuration file and database, when the main server fails, the node can still ensure the integrity of the architecture, suitable for large-scale distributed monitoring environment, Beijing, Tianjin, etc. have many network areas. Monitoring not only ensures that the delay is small, but also does not affect other nodes in the event of a failure.

Case study

Insert picture description here

Reminder: Use zabbix as the monitoring server, and the monitoring objects are Linux servers, Windows servers, and network devices. The switch adopts GNS3 simulator to simulate.

1. Build a network environment to ensure network connectivity

switch configuration

Sw2#en //Enter user mode
Sw2#conf t //Enter privileged mode
Sw2(config)#int ran f0/0 -3 //Enter f0/0 to f0/3 interface
Sw2(config-if-range)# no sh //Open interface
Sw2(config-if-range)#exit //Exit interface configuration mode

Sw2(config)#int vlan 1 //Enter vlan1
Sw2(config-if)# ip add 192.168.2.254 255.255.255.0 //Set vlan1ip address
Sw2(config)# no sh //Open the interface

Test network environment : Test that the router can ping each device Windows, Linux host and zabbix server

2. Configure the Zabbix server 192.168.2.1
Note: In the experimental environment, turn off the firewall and set the setenfoce to permissive mode

E.g:

1. Install MariaDB (the configuration of yum warehouse is omitted)

[[email protected] ~]# mount /dev/cdrom /mnt/ //Mount the system CD
[[email protected] ~]# yum -y install mariadb-server mariadb //install mariadb
[[email protected] ~]# systemctl start mariadb .service //Start mariadb
[[email protected] ~]# systemctl enable mariadb.service //Set self-starting
[[email protected] ~]# mysqladmin -u root password '123456' //Set mysql-root password

2. Install zabbix

[[email protected] ~]# umount /mnt //Uninstall the system disk
[[email protected] ~]# eject
[[email protected] ~]# mount /dev/cdrom /mnt/ //Mount the zabbix installation package and
give it to friends Upload CSDN, the link is the zabbix monitoring system series installation package

[[email protected] ~]# yum clean all //Use another yum warehouse to install in the previous step, you must empty the yum source, otherwise, an error will be reported
[[email protected] ~]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
//Install zabbix and the required software, if you also monitor the zabbix server itself, you need to install an agent

[[email protected] ~]# mysql -u root -p //Log in to the database

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; //Create the database required by zabbix

MariaDB [(none)]> grant all privileges on zabbix.* to [email protected] identified by '123456'; //Create user required by zazbbix

3. Edit the configuration file

[[email protected] ~]# zcat /usr/share/doc/zabbix-server-mysql-3.4.1/create.sql.gz | mysql -uzabbix -p zabbix //Import the database script (input the set zabbix password)
[ [email protected] ~]# cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak //Back up the main zabbix configuration file
[[email protected] ~]# vim /etc/zabbix/zabbix_server.conf // Edit the main configuration file

The reference configuration is as follows:

Insert picture description here

4. Install zabbix web interface

[[email protected] ~]# vim /etc/httpd/conf.d/zabbix.conf //Modify the web time zone file

Insert picture description here


[[email protected] ~]# systemctl start httpd //Restart the httpd service

5. Log in to the zabbix management platform (graphical interface).

Open the browser to visit the URL: http://zabbix IP address/zabbix

Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


login control interface to

Insert picture description here


Insert picture description here


solve the Chinese garbled

[[email protected] ~]# cp /mnt/simkai.ttf /usr/share/zabbix/fonts/ //Copy the font package in the CD to the local
[[email protected] ~]# chmod 755 /usr/share/zabbix/fonts /simkai.ttf //Set permissions
[[email protected] ~]# vim /usr/share/zabbix/include/defines.inc.php //Modify the php configuration file Change the
font name of line 47 to simkai

Insert picture description here

Three, use zabbix to monitor equipment

  1. Monitor the Linux host (install the agent on the Linux host that needs to be monitored)
    Note: Edit the zabbix agent configuration file /etc/zabbix_agentd.conf, you must specify the IP address of the zabbix server, which must be configured on each host where the agent is installed, Here you need to specify the IP address of the zabbix server, if it is on the same server, you don’t need to modify it.

Host configuration of the monitored Linux system
Install the zabbix
agent : rpm -ivh /mnt/zabbix-agent-3.2.6-1.el7.x86_64.rpm Edit the agent configuration file: vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.2.1   // 客户端被动等待指定服务器来查询数据(填zabbix服务器地址)
ServerActive=192.168.2.1 // 客户端主动提交数据到指定的服务器(填zabbix服务器地址)
Hostname=linux-server001  //修改

[[email protected] ~]# systemctl start zabbix-agent.service //Start the agent
[[email protected] ~]# systemctl enable zabbix-agent.service //Set the self-startup

Zabbix server management web page settings

Insert picture description here


Insert picture description here


View monitoring view

Insert picture description here
  1. Monitor network equipment (note: the picture is router monitoring, the switch method is the same)
    switch configuration
    switch(config) # snmp-server community centos RO //Set the read-only community polled by the server
    switch(config) # snmp-server enable traps //Allow the sending of trap messages
    switch(config) # snmp-server host 192.168.2.1 centos //Set the community
    that sends trap messages Note: For individual devices, the red command part will report an error, as shown in the figure below:
Insert picture description here


Solution: Replace the command with switch( config) # snmp-server enable traps config
Zabbix server management page settings

Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here
Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Create graphical view

Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


View monitoring view

Insert picture description here
  1. Monitor the Windows host (take Windows 7 as an example, the method is the same for other Windows versions)
    1) Windows host settings
    decompress the Windows client compressed package zabbix_agents_3.2.0.win.zip, there will be two folders win32 and win64 in the bin directory, according to Windows The version of the system is chosen by itself.
    To facilitate the configuration, create the directory zabbix in the root directory of the c drive, find the /bin directory-select the 32/64 version (depending on your machine)-copy the files in the directory and the conf/Zabbix_agentd.win.conf file to The C:/Zabbix directory of the machine.
Insert picture description here


Note: It must be run as an administrator (system administrator user), it is recommended to open it with WordPad, (notepad, the character format will be messy) modify zabbix——agentd.win.conf file
Server=192.168.2.1 // zabbix server address
ServerActive= 192.168.2.1 //
zabbix server address Hostname=windows-server001 // Keep the same as the following steps, zabbix management page configuration name.

Insert picture description here


Insert picture description here


Reminder:
-i install -s start -c specify configuration -x stop -d uninstall
If an error is reported, it may be created The folder is read-only by default, remove the read-only check; it may also be that the currently logged-in user has insufficient permissions and is not a system administrator. As shown below:

Insert picture description here


choose to run as an administrator

Insert picture description here

2) Zabbix server management page settings

Insert picture description here


Insert picture description here


Insert picture description here


View monitoring view

Insert picture description here


4. Zabbix custom monitoring project (can monitor a certain service, such as: web, FTP, mysql)
1) Operate on the monitored host
Create a directory for storing monitoring scripts
mkdir -p / etc/zabbix/zabbix_scripts/
Create a monitoring script named check_apache.sh
vim /etc/zabbix/zabbix_scripts/check_apache.sh //Note that the name of the process to be monitored does not appear in the script name

#!/bin/bash
result=`ps -ef |grep  httpd | grep -v grep`
if [ -n "$result" ]   //脚本参数 -n判断是否存在
then
        echo "1"
else
        echo "0"
fi  

Modify the configuration to allow special characters in the script
vim /etc/zabbix/zabbix_agentd.conf
line 284, remove the # sign, and change the parameter 0 to 1

Insert picture description here


and create the name userparameter_ apache in the /etc/zabbix/zabbix_agent.d/ directory .conf file
Add custom monitoring items to this file, the format is UserParameter=<key value>,<command>
vim /etc/zabbix/zabbix_agentd.d/userparameter_apache.conf

Insert picture description here


Restart the zabbix agent service: systemctl restart zabbix-agent
Zabbix Server management page settings (first click to add monitoring items, I have added successfully, so the following is "update", the first setting, the lower left corner is "add")

Insert picture description here


Reverse verification: turn off the web service (simulation exception)

Insert picture description here


Insert picture description here


forward verification: Start the web service, the red mark position becomes 1


Common errors

1. Zabbix agent [127.0.0.1] received an empty response

Insert picture description here


Place the mouse in the red English and prompt: Received empty response from Zabbix Agent at [127.0.0.1]. Assuming that agent dropped connection because of access permissions.

Translation: An empty response was received in the Zabbix agent [127.0.0.1]. Suppose the agent is disconnected due to access rights.
Analysis: The interface address must be filled in with the address of the monitored terminal, and the proxy address 127.0.0.1 network device cannot set this address, so filling in the correct address can solve the problem.

Solution: Change to the address of the access port where the agent is installed, that is, the Windows host address 192.168.2.3, refresh it several times

Insert picture description here

2. The route that did not reach the host 192.168.2.3

Insert picture description here


Translated red English prompt: failed to obtain the value from the agent, did not reach the route of the host 192.168.2.3

Analysis: IP address problem, two problems were found after investigation:
1. The Windows host forgot to configure the ip address; 2. The Windows host installs the agent step, and the ip address of the agent configuration file is filled in incorrectly;

Solution: In the virtual machine environment, only Windows snapshots can be restored and redoed.

3. The monitored end of the Linux system cannot start the agent program. It

Insert picture description here


can track system logs, a lot of information, and find key reminders. A local policy is required to allow access and there is no PID file.

Insert picture description here


The previous tip indicates that it is obvious that the firewall or setenfoce has rejected this request for service. The latter one usually has no ip address, a typical composite problem. These two problems can be solved at the same time.

Solution: Turn off the firewall, set setenfoce to permissive mode, and configure ip