Home Operation and Maintenance Linux Operation and Maintenance How to configure monitoring alarms on Linux

How to configure monitoring alarms on Linux

Jul 05, 2023 pm 03:37 PM
linux configuration monitoring Alarm Settings Monitoring alarm configuration

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
Copy after login

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%
    }
Copy after login

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
Copy after login
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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% /
Copy after login

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
    }
Copy after login

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
    }
Copy after login

After the configuration is completed, you need Restart the Nagios server.

sudo service nagios3 restart
Copy after login
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tutorial on finding keywords for common Linux commands Tutorial on finding keywords for common Linux commands Mar 05, 2025 am 11:45 AM

Tutorial on finding keywords for common Linux commands

Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do? Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do? Mar 05, 2025 am 11:37 AM

Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do?

How do I configure SELinux or AppArmor to enhance security in Linux? How do I configure SELinux or AppArmor to enhance security in Linux? Mar 12, 2025 pm 06:59 PM

How do I configure SELinux or AppArmor to enhance security in Linux?

How do I back up and restore a Linux system? How do I back up and restore a Linux system? Mar 12, 2025 pm 07:01 PM

How do I back up and restore a Linux system?

Methods for uploading files for common Linux commands Methods for uploading files for common Linux commands Mar 05, 2025 am 11:42 AM

Methods for uploading files for common Linux commands

How do I monitor system performance in Linux using tools like top, htop, and vmstat? How do I monitor system performance in Linux using tools like top, htop, and vmstat? Mar 17, 2025 pm 05:28 PM

How do I monitor system performance in Linux using tools like top, htop, and vmstat?

How do I configure a virtual private network (VPN) in Linux using OpenVPN or WireGuard? How do I configure a virtual private network (VPN) in Linux using OpenVPN or WireGuard? Mar 12, 2025 pm 07:02 PM

How do I configure a virtual private network (VPN) in Linux using OpenVPN or WireGuard?

How do I implement two-factor authentication (2FA) for SSH in Linux? How do I implement two-factor authentication (2FA) for SSH in Linux? Mar 17, 2025 pm 05:31 PM

How do I implement two-factor authentication (2FA) for SSH in Linux?

See all articles