Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure and use nagios

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to configure and use nagios. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

First, install nagios

Yum install-y epel-release

Yum install-y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

(where httpd is the web end interface of nagios)

You can also use httpd's tool to generate a login password for nagios:

Htpasswd-c / etc/nagios/passwd nagiosadmin

Detect if there is a problem with the configuration file:

Nagios-v / etc/nagios/nagios.cfg

Start the service:

Service httpd start

Service nagios start

Browser access:

Httpd://ip/nagios

II. Nagios monitoring client

The nagios service needs to be installed on the client machine:

Yum install-y epel-release

Yum install-y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

Open the configuration file / etc/nagios/nrpe.cfg

After finding "allowed_hosts=127.0.0.1" and changing it to "allowed_hosts=127.0.0.1192.168.1.11", ip is the server ip.

Find "dont_blame_nrpe=0" and change it to "dont_blame_nrpe=1"

Start the service:

Service nrpe start

3. Nagios server configuration

Open the file / etc/nagios/nagios.cfg and find "cfg_dir". This is the directory where the monitoring files are defined. We can define many directories and put all the newly added host information files here later.

Under the directory we defined, create a subprofile and add the information of the monitored host:

Cd / etc/nagios/conf.d/

Vim 192.168.1.12.cfg

Define host {

Use linux-server

Host_name 192.168.1.12

Alias 192.168.1.12

Address 192.168.1.12

}

Define service {

Use generic-service

Host_name 192.168.1.12

Service_description check_ping

Check_command checklists pingling 100.01.20% check 200.050%

Max_check_attempts 5

Normal_check_interval 1

}

Define service {

Use generic-service

Host_name 192.168.1.12

Service_description check_ssh

Check_command check_ssh

Max_check_attempts 5

Normal_check_interval 1

}

Define service {

Use generic-service

Host_name 192.168.1.12

Service_description check_http

Check_command check_http

Max_check_attempts 5

Normal_check_interval 1

}

# # Note: the IP here is the IP on the client side, and there are three ping, ssh, and http monitoring projects. In fact, the scripts used by these three projects are local scripts, that is, they can be monitored even if the remote host does not have nagios and nrpe installed. But if you want to monitor load,disk, and so on, you need to do it through nrpe services. The reason is very simple. Both load and disk need to log in to the remote host to get information, while ping,ssh,http does not need it. The process of getting relevant information from a remote host is done by nrpe. If the nrpe service is not started on your client, we will not be able to get the load and disk information of the remote host. Below, the author configures the related projects that use nrpe to monitor remote hosts.

Edit / etc/nagios/objects/commands.cfg on the server side

Add a line at the end of the file:

Define command {

Command_name check_nrpe

Command_line $USER1 $/ check_nrpe-H $HOSTADDRESS$-c $ARG1 $

}

Continue to modify the subprofile

Cd / etc/nagios/conf.d/

Vim 192.168.1.12.cfg # add the following

Define service {

Use generic-service

Host_name 192.168.1.12

Service_description check_load

Check_command check_nrpe!check_load

Max_check_attempts 5

Normal_check_interval 1

}

Define service {

Use generic-service

Host_name 192.168.1.12

Service_description check_disk_hda1

Check_command check_nrpe!check_hda1

Max_check_attempts 5

Normal_check_interval 1

}

Define service {

Use generic-service

Host_name 192.168.1.12

Service_description check_disk_hda2

Check_command check_nrpe!check_hda2

Max_check_attempts 5

Normal_check_interval 1

}

# # here we need to explain the relevant "check_command". First, take a look at this "checkchecknrpeaked checkload" where the check_nrpe is just defined in the above / usr/local/nagios/etc/objects/commands.cfg, and the following check_load is a command script defined on the remote host. Exactly where to define it will be described later. Why add a "!" in the middle, this is a unique form of nagios, do not care. Next, you need to go to the remote host to define the script used above.

The server restarts the service:

Service nagios restart

Client restart service:

Service nrpe restart

4. Customize script monitoring in nagios client

After writing the monitoring script, copy it to the / usr/lib64/nagios/plugins/ directory, which of course is defined in the configuration file / etc/nrpe.d/check_log2s3.cfg.

Vim / etc/nrpe.d/check_log2s3.cfg

Commanded [check _ log2S3] = sudo / usr/lib64/nagios/plugins/logmonitoring.sh

# # of course, these contents can be written directly into / etc/nagios/nrpe.cfg, but it is not easy to manage, so we can separate the service of each monitoring script in the / etc/nrpe.d/ directory.

Restart the client service:

Service nrpe restart

Add the appropriate service to the server:

Vim 192.168.1.12.cfg

# # add the following

Define service {

Use generic-service

Host_name 192.168.1.12

Service_description check_logs3

Check_command check_nrpe!check_logs3

Max_check_attempts 5

Normal_check_interval 1

}

Restart the server service:

Service nagios restart

The above is all the contents of the article "how to configure and use nagios". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report