(一) Nagios installation guide
0. Prerequisites
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-fedora.html
During portions of the installation you'll need to have root access to your machine.
Make sure you've installed the following packages before continuing.
-Apache
-PHP
-GCC compiler
-GD development libraries
-Apache
yum install httpd
-PHP
yum install php
-GCC compiler
yum install gcc glibc glibc-common
-GD development libraries
yum install gd gd-devel
1. Download Nagios
1) Create Account Information
Become the root user.
su -l
Create a new nagios user account and give it a password.
/usr/sbin/useradd -m nagios
passwd nagios
Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
2) Download Nagios and the Plugins
wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.1.1/nagios-4.1.1.tar.gz
wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
3) Compile and Install Nagios
Extract the Nagios source code tarball.
tar xzvf nagios-4.1.1.tar.gz
cd nagios-4.1.1
./configure
make all
Install binaries, init script, sample config files and set permissions on the external command directory.
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode
Don't start Nagios yet - there's still more that needs to be done...
4) Customize Configuration
Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You'll need to make just one change before you proceed...
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you'd like to use for receiving alerts.
vi /usr/local/nagios/etc/objects/contacts.cfg
5) Configure the Web Interface
Install the Nagios web config file in the Apache conf.d directory.
make install-webconf
Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Restart Apache to make the new settings take effect.
service httpd restart
Note Note: Consider implementing the ehanced CGI security measures described here to ensure that your web authentication credentials are not compromised.
6) Compile and Install the Nagios Plugins
Extract the Nagios plugins source code tarball.
tar xzvf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
Compile and install the plugins.
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install
7) Start Nagios
Add Nagios to the list of system services and have it automatically start when the system boots.
chkconfig --add nagios
chkconfig nagios on
Verify the sample Nagios configuration files.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, start Nagios.
service nagios start
8) Modify SELinux Settings
Fedora ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by default. This can result in "Internal Server Error" messages when you attempt to access the Nagios CGIs.
See if SELinux is in Enforcing mode.
getenforce
Put SELinux into Permissive mode.
setenforce 0
To make this change permanent, you'll have to modify the settings in /etc/selinux/config and reboot.
Instead of disabling SELinux or setting it to permissive mode, you can use the following command to run the CGIs under SELinux enforcing/targeted mode:
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
For information on running the Nagios CGIs under Enforcing mode with a targeted policy, visit the Nagios Support Portal or Nagios Community Wiki.
9) Login to the Web Interface
You should now be able to access the Nagios web interface at the URL below. You'll be prompted for the username (nagiosadmin) and password you specified earlier.
http://localhost/nagios/
Click on the "Service Detail" navbar link to see details of what's being monitored on your local machine. It will take a few minutes for Nagios to check all the services associated with your machine, as the checks are spread out over time.
10) Other Modifications
Make sure your machine's firewall rules are configured to allow access to the web server if you want to access the Nagios interface remotely.
Configuring email notifications is out of the scope of this documentation. While Nagios is currently configured to send you email notifications, your system may not yet have a mail program properly installed or configured. Refer to your system documentation, search the web, or look to the Nagios Support Portal or Nagios Community Wiki for specific instructions on configuring your system to send email messages to external addresses. More information on notifications can be found here.
11) You're Done
Congratulations! You sucessfully installed Nagios. Your journey into monitoring is just beginning. You'll no doubt want to monitor more than just your local machine, so check out the following docs...
(二)Nagios and NSCA (Network topology)
Remote Host:Monitored Client with send_nsca
Monitoring Host: Monitor Server with nsca
Nagios : central server on Monitoring Host
Nsca: server side of NSCA on Mointoring Host
Send_nsca: client side to send information to NSCA
_____________________ ____________________________________
| | | |
| Nagios <--- Nsca| <------ | Send_nsca <--- program/script |
|_____________________| |____________________________________|
Monitoring Host Remote Host
(三) NSCA plugin
--NSCA plugin should be downloaded and compiled on both Monitoring Host and Remote Host
1)download NSCA
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nsca-2.7.2.tar.gz
2)Compile and Install NSCA
tar xzvf nsca-2.7.2.tar.gz
cd nsca-2.7.2
./configure
make all
--generated executable binary(nsca and send_nsca) can be found under src directory
------------------
$ ls
aclocal.m4 config.guess config.status configure include init-script.in LEGAL Makefile.in nsca_tests sample-config src subst.in
Changelog config.log config.sub configure.in init-script install-sh Makefile nsca.spec README SECURITY subst update-version
$ ls src
Makefile Makefile.in netutils.c nsca nsca.c send_nsca send_nsca.c utils.c
-------------------
(四)Nagios and NSCA (Server Side)
0)Copy NSCA to Nagios bin directory and modify configurations
cd nsca-2.7.2
sudo cp src/nsca /usr/local/nagios/bin
sudo cp sample-config/nsca.cfg /usr/local/nagios/etc
--modify NSCA configuration
vi /usr/local/nagios/et/nsca.cfg
...
server_address=192.168.200.100
password=hello123
debug=1
...
--change the owner of nsca and nsca.cfg
sudo chown nagios:nagcmd /usr/local/nagios/etc/nsca
sudo chown nagios:nagcmd /usr/local/nagios/bin/nsca.cfg
--add as service
cd nsca-2.7.2
sudo cp init-script /etc/init.d/nsca
sudo chmod a+x /etc/init.d/nsca
1)Modify Nagios configuration
cd /usr/local/nagios/etc
--make sure the following options are set to nagios.cfg:
check_external_commands=1
accept_passive_service_checks=1
...
2)Modify Nagios templates
cd /usr/local/nagios/etc/objects
--add the following service to templates.cfg:
define service{
name passive_service
use generic-service
max_check_attempts 1
active_checks_enabled 0
passive_checks_enabled 1
normal_check_interval 5
retry_check_interval 1
notifications_enabled 1
notification_interval 5
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
register 0
}
--notification_options
----------------------------------------------
host_notification_options:
d = notify on DOWN host states,
u = notify on UNREACHABLE host states
r = notify on host recoveries (UP states)
f = notify when the host starts and stops flapping
s = send notifications when host or service scheduled downtime starts and ends
n (none) as an option, the contact will not receive any type of host notifications.
service_notification_options:
w = notify on WARNING service states
u = notify on UNKNOWN service states
c = notify on CRITICAL service states
r = notify on service recoveries (OK states)
f = notify when the service starts and stops flapping
n (none) as an option, the contact will not receive any type of service notifications.
常用的设置
host_notification_options:d,u,r
service_notification_options:w,u,c,r
--contact_groups
-----------------------------------------------
contact_groups should be defined in /usr/local/nagios/etc/objects/contacts.cfg
3)Add Nagios command
cd /usr/local/nagios/etc/objects
--add the following command to commands.cfg:
define command{
command_name check_dummy
command_line /usr/local/nagios/libexec/check_dummy $ARG1$
}
--about check_dummy
-- check_dummy can only support 4 parameters
$ sudo /usr/local/nagios/libexec/check_dummy 0
OK
$ sudo /usr/local/nagios/libexec/check_dummy 1
WARNING
$ sudo /usr/local/nagios/libexec/check_dummy 2
CRITICAL
$ sudo /usr/local/nagios/libexec/check_dummy 3
UNKNOWN
$ sudo /usr/local/nagios/libexec/check_dummy 4
UNKNOWN: Status 4 is not a supported error state
$ sudo /usr/local/nagios/libexec/check_dummy 5
UNKNOWN: Status 5 is not a supported error state
$
4) define a local passive service:
cd /usr/local/nagios/etc/objects
--add the following service to templates.cfg:
define service{
use passive_service
host_name localhost
service_description CheckDummy
check_command check_dummy!0
notifications_enabled 1
}
5) validate Nagios configuration
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
6) start Nagios and NSCA
--if Nagios or NSCA started before ,stop them first and then start
sudo service nagios start
sudo service nsca start
(五)Nagios and NSCA (Client Side)
1)download NSCA
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nsca-2.7.2.tar.gz
2)Compile and Install NSCA
tar xzvf nsca-2.7.2.tar.gz
cd nsca-2.7.2
./configure
make all
--generated executable binary(nsca and send_nsca) can be found under src directory
------------------
$ ls
aclocal.m4 config.guess config.status configure include init-script.in LEGAL Makefile.in nsca_tests sample-config src subst.in
Changelog config.log config.sub configure.in init-script install-sh Makefile nsca.spec README SECURITY subst update-version
$ ls src
Makefile Makefile.in netutils.c nsca nsca.c send_nsca send_nsca.c utils.c
-------------------
1)setup send_nsca and modify configurations
cd nsca-2.7.2
--modify send_nsca configuration
vi /usr/local/nagios/et/send_nsca.cfg
...
password=hello123
...
2) test Nagios passive monitor
cd nsca-2.7.2
--execute following command
echo "localhost;CheckDummy;0;testOK"|./src/send_nsca -H 192.168.110.233 -d ";" -c /tmp/nsca-2.7.2/sample-config/send_nsca.cfg
while:
localhost: host name configured for NSCA daemon
CheckDummy: service name for NSCA passive mode
0: state. 0 means OK
testOK: additonal information
-H: server_address in NSCA configuration
-d: seperator character. default is TAB key
-c: configuration file name used by send_nsca
--alternative test:
you can edit a file, for example test.txt, has one line text with the format as below:
localhost[TAB]CheckDummy[TAB]0[TAB]testOK
./src/send_nsca -H 192.168.110.233 -d ";" -c /tmp/nsca-2.7.2/sample-config/send_nsca.cfg < test.txt
Reference:
(1)https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-fedora.html
(2)https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/passivechecks.html
(3)http://www.ibm.com/developerworks/cn/linux/1309_luojun_nagios/index.html
(4)http://blog.csdn.net/heianemo/article/details/8289840
(5)http://blog.csdn.net/u012375924/article/details/44851773