redhat 4 nagios搭建演练
系统:redhat 4
软件:nagios-3.0.3.tar.tar,nagios-plugins-1.4.13.tar.gz,httpd为系统自带的
一、创建相关账号和目录
[root@web ~]# groupadd nagios
[root@web ~]# groupadd nagcmd
[root@web ~]# useradd nagios -g nagcmd -d /usr/local/nagios
[root@web ~]# passwd nagios
Changing password for user nagios.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@web ~]# mkdir -p /usr/local/nagios
[root@web ~]# chown -R nagios.nagios /usr/local/nagios/
[root@web ~]# chmod 755 /usr/local/nagios
二、安装nagios
[root@web ~]# tar -zxvf nagios-3.0.3.tar.tar
[root@web nagios-3.0.3]# ./configure --with-command-group=nagcmd
..........
Web Interface Options:
------------------------
HTML URL:
CGI URL:
Traceroute (used by WAP): /bin/traceroute
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.
[root@web nagios-3.0.3]# make all
........
- What version of Nagios you are using
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
For more information on obtaining support for Nagios, visit:
*************************************************************
Enjoy.
[root@web nagios-3.0.3]# make install
.........
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs sample config files in /usr/local/nagios/etc
make[1]: Leaving directory `/root/nagios-3.0.3'
[root@web nagios-3.0.3]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
*** Init script installed ***
[root@web nagios-3.0.3]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***
Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
[root@web nagios-3.0.3]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
三、配置nagiso
[root@web ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[root@web ~]# cd /var/www/html/
[root@web html]# mkdir nagios
[root@web ~]# vi /etc/httpd/conf/httpd.conf
添加如下内容
#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
#Setting for nagios
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
Alias /nagios /usr/local/nagios/share
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
四、安装nagios插件
[root@web ~]# tar -zxvf nagios-plugins-1.4.13.tar.gz
[root@web ~]# cd nagios-plugins-1.4.13
[root@web nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --enable
-redhat-pthread-workaround
config.status: creating po/Makefile
--with-apt-get-command:
--with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
--with-ping-command: /bin/ping -n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql: no
--with-openssl: yes
--with-gnutls: no
--enable-extra-opts: no
--with-perl: /usr/bin/perl
--enable-perl-modules: yes
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
[root@web nagios-plugins-1.4.13]# make
make[3]: Leaving directory `/root/nagios-plugins-1.4.13/perlmods/Nagios-Plugin-0.27'
make[2]: Leaving directory `/root/nagios-plugins-1.4.13/perlmods'
make[2]: Entering directory `/root/nagios-plugins-1.4.13'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/root/nagios-plugins-1.4.13'
make[1]: Leaving directory `/root/nagios-plugins-1.4.13'
[root@web nagios-plugins-1.4.13]# make install
make[2]: Leaving directory `/root/nagios-plugins-1.4.13/perlmods'
make[1]: Leaving directory `/root/nagios-plugins-1.4.13/perlmods'
make[1]: Entering directory `/root/nagios-plugins-1.4.13'
make[2]: Entering directory `/root/nagios-plugins-1.4.13'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/nagios-plugins-1.4.13'
make[1]: Leaving directory `/root/nagios-plugins-1.4.13'
[root@web ~]# chkconfig --add nagios
[root@web ~]# chkconfig --list|grep nagios
nagios 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@web ~]# cd /usr/local/nagios/bin
[root@web bin]# ./nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios 3.0.3
Copyright (c) 1999-2008 Ethan Galstad ()
Last Modified: 06-25-2008
License: GPL
..............
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
[root@web bin]# service nagios start
Starting nagios: done.
[root@web bin]# ps -ef|grep nagios
nagios 3566 1 0 00:24 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
root 3574 6660 0 00:24 pts/1 00:00:00 grep nagios
[root@web etc]# cd /usr/local/nagios/etc/objects/
[root@web objects]# vi hosts.cfg 添加文件内容
define host{
use linux-server
host_name web
alias web
address 172.16.12.178
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options d,u,r
contact_groups admins
}
define service{
use generic-service
host_name web
service_description HTTP
check_command check_http
}
define service{
use generic-service
host_name web
service_description SSH
check_command check_ssh
}
define service{
use local-service
host_name web
service_description PING
check_command check-host-alive
}
[root@web objects]# vi contacts.cfg 编辑该文件
define contact{
contact_name nagios ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagios
}
[root@web ~]# cd /usr/local/nagios/etc
[root@web etc]# vi nagios.cfg
添加如下行
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
[root@web etc]# service nagios restart
Running configuration check...done.
Stopping nagios: .done.
Starting nagios: done.
[root@web etc]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
通过访问,输入用户nagiosadmin,密码123456即可访问