#yum –y install httpd php gd gcc gcc-g++ mysql mysql-devel
|
http://www.nagios.org/download php
1. 建用戶和組 html
[root@localhost~]# groupadd nagios
[root@localhost~]# useradd -g nagios -G nagios -m -s /sbin/nologin nagios
|
2.解壓安裝文件 java
[root
@localhost ~]# mkdir /usr/src/nagios/
[root
@localhost ~]# tar zxvf nagios-3.3.1.tar.gz -C /usr/src/nagios/
[root
@localhost ~]# tar zxvf
nagios-plugins-1.4.15.tar.gz -C/usr/src/nagios/
[root
@localhost ~]# tar zxvf nrpe-2.12.tar.gz -C /usr/src/nagios/
|
3安裝 nagios-3.3.1.tar.gz mysql
[root
@localhost nagios]#cd
/usr/src/nagios/nagios
[root
@localhost nagios]# ./configure --prefix=/usr/local/nagios --with-command-group=nagios
[root
@localhost nagios]# make all
[root
@localhost nagios]# make install
[root
@localhost nagios]# make install-init
[root
@localhost nagios]# make install-commandmode
[root
@localhost nagios]# make install-config
|
注意若是報錯: linux
/usr/bin/install: omitting directory `includes/rss/extlib' ios
/usr/bin/install: omitting directory `includes/rss/htdocs' web
/usr/bin/install: omitting directory `includes/rss/scripts' sql
make[1]: *** [install] Error 1 apache
make[1]: Leaving directory `/usr/src/nagios/nagios/html' vim
make: *** [install] Error 2
措施:
[root@localhost nagios]# sed -i 's/for file in includes\/rss\/\*\;/for file in includes\/rss\/\*\.\*\;/g' ./html/Makefile
[root@localhost nagios]# sed -i 's/for file in includes\/rss\/extlib\/\*\;/for file in includes\/rss\/extlib\/\*\.\*\;/g' ./html/Makefile
執行這兩句代碼。
從新make install
[root@localhost nagios]# make install
4.安裝nagios-plugins-1.4.15.tar.gz
[root
@localhost nagios]# cd/usr/src/nagios/nagios-plugins-1.4.15/
[root
@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios--with-nagios-group=nagios --prefix=/usr/local/nagios/
[root
@localhost nagios-plugins-1.4.15]#make && make install
|
5.安裝nrpe-2.12.tar.gz
[root
@localhost nagios-plugins-1.4.15]# cd /usr/src/nagios/nrpe-2.12/
[root
@localhost nrpe-2.12]# ./configure --prefix=/usr/local/nagios/
[root
@localhost nrpe-2.12]# make all
[root
@localhost nrpe-2.12]# make install-plugin
|
6.設置Apache開機啓動
[root
@localhost nrpe-2.12]# vi /etc/httpd/conf/httpd.conf
#修改apache 運行用戶
User nagios
Group nagios
#支持PHP 添加 index.php
DirectoryIndex index.php index.html index.html.var
#在最後加入nagios web訪問部分
ScriptAlias/nagios/cgi-bin
"/usr/local/nagios/sbin/"
Alias/nagios
"/usr/local/nagios/share/"
<Directory
"/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
Require valid-user
</Directory>
<Directory
"/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
Require valid-user
</Directory>
|
配置web訪問用戶密碼
[root@localhostnrpe-2.12]# htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin #密碼輸入
[root
@localhost nrpe-2.12]# service httpd start
|
在瀏覽器輸入http://IP/nagios 出現如圖
出現web訪問配置正確.
說明:服務器分三個組,linuxserver,windowsserver,networkserver(如交換機,路由器)。
配置實驗說明.
IP |
服務器OS |
監控服務 |
192.168.20.194 |
監控機LINUX |
Mysql,squid,ssh,ping |
192.168.20.184 |
LINUX |
Mysql,httpd,ssh,ping |
192.168.20.187 |
windows |
3389,21,ping |
192.168.20.1 |
switch |
ping |
A. 配置聯繫人
先備份原配置文件
[root
@localhost objects]# cd /usr/local/nagios/etc/objects/
[root
@localhost objects]# tar zcvf back.tar.gz ./*
[root
@localhost objects]# vi contacts.cfg
#清空裏面的內容添加下配置
define contact{
contact_name nagiosadmin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email chunjian.feng@jrj.com.cn
#pager 13800138000
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
|
B. 配置命令文件
[root
@localhost objects]# vi commands.cfg
添加下面兩個命令
definecommand{
command_name check_nrpe
command_line $USER1$/check_nrpe-H $HOSTADDRESS$ -c $ARG1$
}
definecommand{
command_name check_mysql
command_line $USER1$/check_mysql-u $ARG1$ -p $ARG2$ -H $HOSTADDRESS$ -P $ARG3$ -d $ARG4$ $ARG5$
}
|
C.配置templates.cfg
[root
@localhost objects]# vi templates.cfg
#清空裏面的內容添加下配置
define host{
name generic-host
contact_groups admins
check_command check-host-alive
max_check_attempts 5
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
define service{
name generic-service
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
}
|
D.配置linux服務器組
咱們把只帶的localhost.cfg改成LINUX server的定義文件。
[root
@localhost objects]# vi localhost.cfg
#清空
define hostgroup{
hostgroup_name linux-servers
alias Linux Servers
members localhost,192.168.20.184
}
define host{
use generic-host
host_name localhost
alias localhost
address 127.0.0.1
}
################localhost server
define service{
host_name localhost
service_description load average
check_command check_nrpe!check_load
use generic-service
}
define service{
host_name localhost
service_description total-procs
check_command check_nrpe!check_total_procs
use generic-service
}
define service{
host_name localhost
service_description freespace
check_command check_nrpe!check_disk
use generic-service
}
define service{
host_name localhost
service_description mysql
check_command check_mysql!root!123456
use generic-service
}
define service{
use generic-service
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use generic-service ; Name ofservice template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
define service{
host_name localhost
service_description squid
check_command check_tcp!80
use generic-service
}
###################################192.168.20.184
definehost{
use generic-host
host_name 192.168.20.184
alias 192.168.20.184
address 192.168.20.184
}
define service{
host_name 192.168.20.184
service_description load average
check_command check_nrpe!check_load
use generic-service
}
define service{
host_name 192.168.20.184
service_description total-procs
check_command check_nrpe!check_total_procs
use generic-service
}
define service{
host_name 192.168.20.184
service_description freespace
check_command check_nrpe!check_disk
use generic-service
}
define service{
host_name 192.168.20.184
service_description mysql
check_command check_mysql!root!123456
use generic-service
}
define service{
use generic-service
host_name 192.168.20.184
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use generic-service ; Name ofservice template to use
host_name 192.168.20.184
service_description SSH
check_command check_ssh
notifications_enabled 0
}
define service{
use generic-service
host_name 192.168.20.184
service_description HTTP
check_command check_http
notifications_enabled 0
}
|
注:windows 和switch相似的定義。咱們分別用自帶的windows.cfg,switch.cfg文件配置。
E.開啓nagios進程
[root
@monitor ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
[root
@monitor ~]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
[root
@monitor ~]#echo "/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg" >> /etc/rc.d/rc.local
|
A.創建用戶和安裝客戶端。
[root@LNMP4 ~]# yum install bc
Useradd nagios
tar-zxvf nagios-plugins-1.4.14.tar.gz
cdnagios-plugins-1.4.14
./configure--with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
make&&makeinstall
tar-zxvf nrpe-2.12.tar.gz
cdnrpe-2.12
./configure--prefix=/usr/local/nagios
makeall
makeinstall-plugin
makeinstall-daemon
makeinstall-daemon-config
chown-R nagios.nagios/usr/local/nagios
|
B.配置被監控機
vim/usr/local/pmediasrv/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.20.194 #監控機的IP和本機IP
command[check_load]=/usr/local/pmediasrv/nagios/libexec/check_load-w 15,10,5 -c 30,25,20
command[check_total_procs]=/usr/local/pmediasrv/nagios/libexec/check_procs-w 150 -c 200
command[check_disk]=/usr/local/nagios/libexec/check_disk-w 20% -c 10%
|
啓動客戶端進程:
/usr/local/pmediasrv/nagios/bin/nrpe-c/usr/local/pmediasrv/nagios/etc/nrpe.cfg –d
|
下載客戶端地址:
http://files.nsclient.org/x-0.3.x_STABLE/NSClient%2B%2B-0.3.7-Win32.msi 32位
http://files.nsclient.org/x-0.3.x_STABLE/NSClient%2B%2B-0.3.7-x64.msi 64位
下載安裝好。配置,在安裝目錄下編輯NSC.ini
[modules]
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
NRPEListener.dll
SysTray.dll
CheckEventLog.dll
CheckHelpers.dll
;CheckWMI.dll
; RemoteConfiguration IS AN EXTREM EARLY IDEA
SO DONT USE FOR PRODUCTION ENVIROMNEMTS!
;RemoteConfiguration.dll
; NSCA Agent is anewbeta module use with care!
NSCAAgent.dll
; LUA script module used to write your own
"check deamon"(sort of) early beta.
LUAScript.dll
; Script to check external scripts and/or
internal aliases, early beta.
CheckExternalScripts.dll
; Check other hosts through NRPE extreme beta
and probably a bit dangerous! :)
NRPEClient.dll
; Extreamly early beta of a task-schedule
checker
CheckTaskSched.dll
最後配置
allowed_hosts=127.0.0.1/32,192.168.20.194 容許192.168.20.194
port=12489 監聽端口
|
注:從新啓動客戶端