Home > Article > Operation and Maintenance > How to configure monitoring alarms on Linux
How to configure monitoring alarms on Linux
In Linux systems, configuring monitoring alarms is very important. By monitoring the operating status of the system, we can discover and solve problems in time, thereby ensuring the stability and security of the system. This article will introduce how to configure monitoring alarms on Linux and provide corresponding code examples.
1. Install monitoring tools
In Linux systems, there are many monitoring tools available, such as Nagios, Zabbix, etc. These tools can monitor the server's CPU, memory, disk, network and other indicators, and send alarm messages when abnormalities occur.
Taking Nagios as an example, you first need to install Nagios server and client software. In Debian/Ubuntu systems, you can use the following command to install:
sudo apt-get install nagios3 nagios-nrpe-plugin
After the installation is complete, you still need to configure the Nagios server and client.
2. Configure the Nagios server
Before configuring the Nagios server, you need to create a monitoring configuration file to define the hosts and services that need to be monitored. In the Nagios server's configuration folder, find the /etc/nagios3/conf.d
directory and create a new configuration file hosts.cfg
and add the following content in it:
define host { use linux-server host_name server1 alias My Server address 192.168.1.100 } define service{ host_name server1 service_description PING check_command check_ping!100.0,20%!500.0,60% }
The above configuration file defines a host named server1
, its IP address is 192.168.1.100
, and monitors the PING status of the host.
After the configuration is completed, restart the Nagios server.
sudo service nagios3 restart
3. Configure Nagios client
On the Linux server to be monitored, Nagios client software needs to be installed and configured. In Debian/Ubuntu systems, you can use the following command to install:
sudo apt-get install nagios-nrpe-server
After the installation is complete, you also need to configure the Nagios client to allow the Nagios server to remotely monitor the host.
First edit the Nagios client configuration file /etc/nagios/nrpe.cfg
, and modify the following parameters:
allowed_hosts=127.0.0.1,192.168.1.1
Among the above parameters, 192.168.1.1
is the IP address of the Nagios server, which can be modified according to the actual situation.
Next, create a new configuration file linux.cfg
in the /etc/nagios/nrpe.d
directory and add the following content to it:
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% / command[check_load]=/usr/lib/nagios/plugins/check_load -w 5,4,3 -c 10,8,6
The above configuration file defines two commands check_disk
and check_load
, which are used to monitor disk space and system load.
After the configuration is completed, restart the Nagios client.
sudo service nagios-nrpe-server restart
4. Test monitoring alarms
After the configuration is completed, you can test it through the Nagios Web interface or use the commands in the nagios-plugins
software package.
On the Nagios server, you can use the check_nrpe
command to test the running status of the client. For example, check whether the client can run the check_disk
command:
/usr/lib/nagios/plugins/check_nrpe -H 192.168.1.100 -c check_disk
If the command returns normal, the monitoring configuration is successful.
On the Nagios client, you can use the commands in the nagios-plugins
package to test the health of the system. For example, check the disk space:
/usr/lib/nagios/plugins/check_disk -w 20% -c 10% /
If the disk space is less than 20% or less than 10%, an alarm will be triggered.
5. Configure alarms
When configuring monitoring alarms, you often need to specify the alarm method and receiver. In Nagios, you can configure the alarm contact by editing the /etc/nagios3/conf.d/contacts.cfg
file.
For example, you can add the following content to define an alarm contact:
define contact{ contact_name admin alias Nagios Administrator email admin@example.com }
The above configuration defines an alarm contact named admin, whose email is admin@example.com.
Next, in the /etc/nagios3/conf.d/hosts.cfg
file, add an alarm contact for the host:
define host{ ... contacts admin }
After the configuration is completed, you need Restart the Nagios server.
sudo service nagios3 restart
6. Summary
Through the above steps, we can configure monitoring alarms on the Linux system. With the help of monitoring tools, we can discover and solve problems in the system in time to ensure the stability and reliability of the system. Of course, in practical applications, monitoring indicators and alarm methods need to be adjusted according to specific conditions to meet actual needs.
The above is the detailed content of How to configure monitoring alarms on Linux. For more information, please follow other related articles on the PHP Chinese website!