Install Nagios Server
Install Nagios Server
Install Nagios Server
[root@dlp ~]#
dnf --enablerepo=epel -y install nagios nagios-plugins-{ping,disk,users,procs,load,swap,ssh,h
[5] Configure Nagios.
[root@dlp ~]#
vi /etc/httpd/conf.d/nagios.conf
# line 16-17 : change access permission if you need ( also change line 47-48 )
#
Require all granted
#Require host 127.0.0.1
Require ip 127.0.0.1 10.0.0.0/24
# add nagios admin user
[root@dlp ~]#
htpasswd /etc/nagios/passwd nagiosadmin
New password:
# set any password
[root@dlp ~]#
systemctl restart httpd
[root@dlp ~]#
dnf --enablerepo=epel -y install nagios-selinux
[root@dlp ~]#
vi nagios-php.te
# create new
require {
type httpd_t;
type nagios_spool_t;
type ping_exec_t;
type nagios_unconfined_plugin_t;
class file { execute execute_no_trans map getattr open read };
class process setcap;
class icmp_socket { create getopt setopt };
class udp_socket { connect create getattr };
}
[root@dlp ~]#
checkmodule -m -M -o nagios-php.mod nagios-php.te
[root@dlp ~]#
semodule_package --outfile nagios-php.pp --module nagios-php.mod
[root@dlp ~]#
semodule -i nagios-php.pp
success
[root@dlp ~]#
firewall-cmd --runtime-to-permanent
success
[8] Access to [http://(Nagios server's hostname or IP address)/nagios/] from a client which is in the
by Nagios server and authenticate to login with the Nagios administration user [nagiosadmin] yo
[9] After successing authentication, Nagios admin site is displayed.
[10] It's possible to see system status to click [Tactical Overview] and so on.
Notification Setting
This is the Email Notification Settings section.
It is enabled on some items by default but if you change it, configure like follows.
[1] Install and start SMTP Server, refer to here .
[2] Set notification recipients. And aldo Nagios sends notifications with [mail] command, so install i
[root@dlp ~]#
dnf -y install s-nail
[root@dlp ~]#
vi /etc/nagios/objects/contacts.cfg
# line 32 : set recipient email address
email
root@localhost
[root@dlp ~]#
systemctl restart nagios
Service: SSH
Host: localhost
Address: 127.0.0.1
State: CRITICAL
Date/Time: Wed Aug 10 13:04:47 JST 2022
Additional Info:
Set Thresholds
[1] The thresholds are set in configuration file by default. For example, the item for monitoring disk
partition is set like follows.
[root@dlp ~]#
vi /etc/nagios/objects/localhost.cfg
.....
.....
# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
# the thresholds are set as Warning if > 20% free, critical if 10% > 10% free
# change these values if you'd like to change them
define service {
[root@dlp ~]#
systemctl restart nagios
[2] For the case you add a new plugin and configure it, set like follows.
(example below is for [check_ntp_time] plugin)
[root@dlp ~]#
dnf --enablerepo=epel -y install nagios-plugins-ntp
# display options for a plugin to confirm usage
[root@dlp ~]#
/usr/lib64/nagios/plugins/check_ntp_time -h
.....
.....
-w, --warning=THRESHOLD
Offset to result in warning status (seconds)
-c, --critical=THRESHOLD
Offset to result in critical status (seconds)
.....
.....
[root@dlp ~]#
vi /etc/nagios/objects/commands.cfg
# add to the end
define command {
command_name check_ntp_time
command_line $USER1$/check_ntp_time -H $ARG1$ -w $ARG2$ -c $ARG3$
}
[root@dlp ~]#
vi /etc/nagios/objects/localhost.cfg
# add to the end
# Warning with 1 sec time difference, Critical with 2 sec difference
define service {
use local-service
host_name localhost
service_description NTP_TIME
check_command check_ntp_time!ntp.nict.jp!1!2
notifications_enabled 1
}
[root@dlp ~]#
systemctl restart nagios
Service: NTP_TIME
Host: localhost
Address: 127.0.0.1
State: CRITICAL
Additional Info:
[root@dlp ~]#
dnf --enablerepo=epel search nagios-plugins-
[2] For example, add [check_ntp] plugin to monitor time difference between the System time and N
[root@dlp ~]#
dnf --enablerepo=epel -y install nagios-plugins-ntp
[root@dlp ~]#
vi /etc/nagios/objects/commands.cfg
# add follows to the end
define command {
command_name check_ntp_time
command_line $USER1$/check_ntp_time -H $ARG1$ -w $ARG2$ -c $ARG3$
}
[root@dlp ~]#
vi /etc/nagios/objects/localhost.cfg
# add to the end
# Warning with 1 sec time difference, Critical with 2 sec difference
define service {
use local-service
host_name localhost
service_description NTP_TIME
check_command check_ntp_time!ntp.nict.jp!1!2
notifications_enabled 1
}
[root@dlp ~]#
systemctl restart nagios
[3] It's possible to view the status for a new plugin on the admin site.
Add Target Host (Ping)
[1] For exmaple, add a Host as monitoring target with simply Ping command.
[root@dlp ~]#
vi /etc/nagios/nagios.cfg
# line 51 : uncomment
cfg_dir=/etc/nagios/servers
[root@dlp ~]#
mkdir /etc/nagios/servers
[root@dlp ~]#
chgrp nagios /etc/nagios/servers
[root@dlp ~]#
chmod 750 /etc/nagios/servers
[root@dlp ~]#
vi /etc/nagios/servers/node01.cfg
# create new
define host {
use linux-server
host_name node01
alias node01
address 10.0.0.51
}
define service {
use generic-service
host_name node01
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
[root@dlp ~]#
systemctl restart nagios
[2] It's possible to see the status for a new server on the admin site.
M a t c h e d C o n t e n t
[root@node01 ~]#
dnf --enablerepo=epel -y install nrpe nagios-plugins-{ping,disk,users,procs,load,swap,ssh}
[root@node01 ~]#
vi /etc/nagios/nrpe.cfg
# line 106 : add access permission (specify Nagios server)
allowed_hosts=127.0.0.1,::1
,10.0.0.30
# line 122 : permit arguments of commands on here
dont_blame_nrpe=
1
# line 300 : comment out all
#
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
#
command[check_load]=/usr/lib64/nagios/plugins/check_load -r -w .15,.10,.05 -c .30,.25,.20
#
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
#
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -sZ
#
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
# line 305 : add follows
success
[root@node01 ~]#
firewall-cmd --runtime-to-permanent
success
[3] Configure Nagios server.
[root@dlp ~]#
dnf --enablerepo=epel -y install nagios-plugins-nrpe
[root@dlp ~]#
vi /etc/nagios/nagios.cfg
# line 51 : uncomment
cfg_dir=/etc/nagios/servers
[root@dlp ~]#
mkdir /etc/nagios/servers
[root@dlp ~]#
chgrp nagios /etc/nagios/servers
[root@dlp ~]#
chmod 750 /etc/nagios/servers
[root@dlp ~]#
vi /etc/nagios/objects/commands.cfg
# add to the end
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
[root@dlp ~]#
vi /etc/nagios/servers/node01.cfg
# create new
define host {
use linux-server
host_name node01
alias node01
address 10.0.0.51
}
# for ping
define service {
use generic-service
host_name node01
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
[root@dlp ~]#
systemctl restart nagios
[4] It's possible to see the status for a new server on the admin site.