nagios监控安装及设置案例
[root@server1nagios]#1安装yuminstallgd-devel-y
[root@server1nagios]#2部署lamp环境yuminstallhttpdmysqlmysql-serverphpphp-mysqlgccgcc-c++-y
[root@server1nagios]#3安装主程序nagios
[root@server1nagios]#tarfvxznagios.tar.gz
[root@server1nagios]#./configure--prefix=/usr/local/nagios
[root@server1nagios]#useraddnagios
[root@server1nagios]#makeall
[root@server1nagios]#makeinstall
makeinstall
-Thisinstallsthemainprogram,CGIs,andHTMLfiles
makeinstall-init
-Thisinstallstheinitscriptin/etc/rc.d/init.d
makeinstall-commandmode
-Thisinstallsandconfigurespermissionsonthe
directoryforholdingtheexternalcommandfile
makeinstall-config
-Thisinstalls*SAMPLE*configfilesin/usr/local/nagios/etc
You'llhavetomodifythesesamplefilesbeforeyoucan
useNagios.ReadtheHTMLdocumentationformoreinfo
ondoingthis.Payparticularattentiontothedocson
objectconfigurationfiles,astheydeterminewhat/how
thingsgetmonitored!
makeinstall-webconf
-ThisinstallstheApacheconfigfilefortheNagios
webinterface
vim/etc/httpd/conf/httpd.conf
Usernagios
Groupnagios
重新启动apache
servicehttpdrestart
servicenagiosstart
生成用户
[root@server1nagios-3.2.0]#htpasswd-c/usr/local/nagios/etc/htpasswd.usersnagiosm
Newpassword:
Re-typenewpassword:
Addingpasswordforusernagios
给nagios用户开权限,让他能够查看信息!
[root@server1nagios-3.2.0]#vim/usr/local/nagios/etc/cgi.cfg
在所有的nagiosadmin后面添加nagios
本机为什么是down的状态???
监控分析控制台---------------主程序
插件
--------------被监控主机
nagios报错无权查看任何主机的信息解决方法
解决办法:
vi/usr/local/nagios/etc/cgi.cfg
将use_authentication的值改为0.
use_authentication=0
然后重启nagios服务
servicenagiosrestart
[root@server1libexec]#pwd
/usr/local/nagios/libexec
[root@server1libexec]#ls
[root@server1libexec]#
插件目录下什么没有有阿!
安装插件
[root@server1nagios-plugins-1.4.13]#./configure--prefix=/usr/local/nagios/-
可选的选项--with-gnutls--with-openssl--enable-extra-opts--enable-perl-modules
make
makeinstall
怎样监控的更多!
[root@server1etc]#pwd
/usr/local/nagios/etc
[root@server1etc]#vimnagios.cfg
编辑主配置文件
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
通过上面的语句来调用那些配置文件
[root@server1objects]#pwd
/usr/local/nagios/etc/objects
时间timeperiods.cfg
definetimeperiod{
timeperiod_name24x7
alias24HoursADay,7DaysAWeek
sunday00:00-24:00
monday00:00-24:00
tuesday00:00-24:00
wednesday00:00-24:00
thursday00:00-24:00
friday00:00-24:00
saturday00:00-24:00
}
插件commands.cfg
definecommand{
command_namecheck-host-alive
command_line$USER1$/check_ping-H$HOSTADDRESS$-w3000.0,80%-c5000.0,100%-p5
}
监控谁localhost.cfg
definehost{
host_namefudong
aliastest
address192.168.18.50
check_commandcheck-host-alive
notification_optionsd,u,r
check_interval1
max_check_attempts2
contact_groupsadmins
notification_interval10
notification_period24x7
}
联系人contacts.cfg
definecontact{
contact_namekyo
aliaskyo
host_notification_period24x7
host_notification_optionsd,u,r
service_notification_period24x7
service_notification_optionsw,u,c,r
service_notification_commandsnotify-service-by-email
host_notification_commandsnotify-host-by-email
emailroot@163.com
#通过飞信机器人发信报警!
}
definecontactgroup{
contactgroup_nameadmins
aliasNagiosAdministrators
membersnagiosadmin,kyo
}
检查错误
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
定义服务
defineservice{
host_namefudong
service_descriptionapache
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_http
}
关于插件的返回状态
[root@server1objects]#echo$?
2
[root@server1objects]#/usr/local/nagios/libexec/check_http-I192.168.18.50
HTTPOKHTTP/1.1200OK-43306bytesin0.026seconds|time=0.026288s;;;0.000000size=43306B;;;0
[root@server1objects]#echo$?
0
[root@server1objects]#/usr/local/nagios/libexec/check_http-I192.168.18.50-u/a.html-shello
HTTPWARNING:HTTP/1.1404NotFound
[root@server1objects]#echo$?
1
0成功1警告2严重错误3未知
自己编写插件!!!!!!!!!!!!!!!!
#!/bin/bash
curl-Ihttp://192.168.18.155&>/dev/null
if[$?-eq0];then
(curl-Ihttp://192.168.18.155|grep'HTTP/1.1200')&>/dev/null
if[$?-eq0];then
echo"OK!"
exit0
else
echo"warning!"
exit1
fi
else
echo"down!"
exit2
fi
自定义命令
definecommand{
command_namecheck_url
command_line$USER1$/check_http-I$HOSTADDRESS$-u$ARG1$-s$ARG2$
}
使用新定义的命令
defineservice{
host_namefudong
service_descriptionapache
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
#check_commandcheck_http
check_commandcheck_url!/index.html!hello
}
########################################################################
check_mysql
vim/usr/local/nagios/libexec/check_mysql
#!/bin/bash
#check_mysqlstatus
IP=$1
mysql-utest-h$IP-p123-e'showdatabases;'&>/dev/null
if[$?-eq0];then
echo"mysqlOK!"
exit0;
else
echo"mysqlerr!"
exit2;
fi
vim/usr/local/nagios/etc/objects/commands.cfg
definecommand{
command_namecheck_mysql
command_line$USER1$/check_mysql$ARG1$
}
vim/usr/local/nagios/etc/objects/localhost.cfg
defineservice{
host_namemail.vfast.com
service_descriptionmysql
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts2
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_mysql!192.168.18.69
}
servicenagiosrestart
###################################################################################
yuminstallexpect-y
definecommand{
command_namenotify-host-by-sms
command_line/usr/local/nagios/libexec/nagios-mail"$(/usr/bin/printf"%b""*****Nagios*****\n\nNotificationType:$NOTIFICATIONTYPE$\nHost:$HOSTNAME$\nState:$HOSTSTATE$\nAddress:$HOSTADDRESS$\nInfo:$HOSTOUTPUT$\n\nDate/Time:$LONGDATETIME$\n")"smtp.163.comY29vbHdhbmdjaG9uZ0AxNjMuY29tUVE4MTBXQU5HODIwMCFAcoolwangchong@163.com$CONTACTEMAIL$"**$NOTIFICATIONTYPE$HostAlert:$HOSTNAME$is$HOSTSTATE$**"
}
如果遇到host条目一会有,一会消失的问题,可以killallnagios再重新启动nagios!
监控远程主机的系统信息
被监控主机
安装nrpe的server端
tarfvxznrpe*.tar.gz
./configure--prefix=/usr/local/nagios
useraddnagios
make
makeinstall-daemon
makeinstall-daemon-config
makeinstall-xinetd
安装插件2
makeinstall(这步不是必须的!)
把插件拷贝给监控主机nagios
scp/usr/local/nagios/libexec/check_nrperoot@监控主机的ip:/usr/local/nagios/libexec
在被监控主机开启nrpe服务
vim/etc/xinetd.d/nrpe
#default:on
#description:NRPE(NagiosRemotePluginExecutor)
servicenrpe
{
flags=REUSE
socket_type=stream
port=5666
wait=no
user=nagios
group=nagios
server=/usr/local/nagios/bin/nrpe
server_args=-c/usr/local/nagios/etc/nrpe.cfg--inetd
log_on_failure+=USERID
disable=no
only_from=192.168.18.254#监控主机的ip,保证他可以连接进来!
}
vim/etc/services
nrpe5666/tcp
servicexinetdrestart
[root@server1objects]#/usr/local/nagios/libexec/check_nrpe-H192.168.18.188
NRPEv2.12
#注意关闭防火墙!
在被监控主机安装插件
vimnrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users-w5-c10
command[check_u]=/usr/local/nagios/libexec/check_users-w5-c10
command[check_load]=/usr/local/nagios/libexec/check_load-w15,10,5-c30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk-w20%-c10%-p/dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs-w5-c10-sZ
command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w150-c200
通过以上字段来定义命令,以及接收命令后执行的插件
如果想不明白
定义服务,来检测一下
definehost{
host_namezcg
aliasnrpe-server
address192.168.18.188
check_commandcheck-host-alive
notification_optionsd,u,r
check_interval1
max_check_attempts2
contact_groupsadmins
notification_interval10
notification_period24x7
}
defineservice{
host_namezcg
service_descriptionnrpe
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_users
#这里定义的check_nrpe需要在command.cfg里面定义
}
别忘了,先定义好zcg这台主机!!
定义命令
definecommand{
command_namecheck_nrpe
command_line/usr/local/nagios/libexec/check_nrpe-H$HOSTADDRESS$-c$ARG1$
}
重启nagios服务!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。