简单介绍下nagios
开源网络监控
监控的分类:
状态的连续监控:对实时状态进行监控。
状态的变化监控:但某一时刻监控的状态发生变化时,就进行汇报。
nagios是一款遵循GPLV2的开源网络监控软件,可用来监控制定的多种系统的主机、服务,并在它们的工作状态发生变化时通知管理员。
1)监控网络服务(HTTP/POP3/SMTP/PING/MYSQL等)
2)监控主机资源(磁盘利用率、内存利用率、CPU负载等)
3)简洁的插件设计接口,使得用户可以轻松开发所需的检测脚本(运维则可直接找到相关脚本并使用)
4)并行服务模式
5)轻松描述网络结构,并且能够区辨“宕机”和“主机不可达”
6)通过邮件或用户自定义的方式将主机或服务的工作状态变化情况通知给管理员
7)当服务或主机问题产生与解决时将告警发送给联系人(通过EMail/短信、用户定义方式)
8)自动日志滚动
9)可以通过web方式直观的查看当前网络状态、通知和问题历史、日志文件等,此组件为可选
Nagios通常由一个主程序(Nagios)、一个插件程序(Nagios-plugins)和四个可选的ADDON(NRPE/NSCA/NSCLIENT++和NDOUTILS)组成。
NRPE:用来在监控的的远程LINUX/UNIX主机上执行脚本插件以实现对这些主机资源的监控;
试验中用到的版本是NRPE-2.1.2.tar.gz
NSCA:用来让被监控的远程Linux/Unix主机主动将监控信息发送给Nagios服务器(这在冗余监控模式中,特别要用到)
NSCLIENT++:用来监控Windows主机时安装在Windows主机上的组件;
NDOUTILS:则用来将NAGIOS的配置信息和各EVETN产生的数据存入数据库,以实现对这些数据的快速检索和处理;
NAGIOS是通过配置文件来驱动这个监控流程,因为所有的内容都是可配置的,所以也就非常灵活,功能自然也就枪弹,把太多的工作留给使用者。
1、新添加监控主机
要修改localhost.cfg或windows.cfg配置文件
这里的默认路径为/usr/local/nagios/etc/objects/localhost.cfg或者/usr/local/nagios/etc/objects/windows.cfg
2、调整监控的命令
要修改commands.cfg配置文件
/usr/local/nagios/etc/objects/commands.cfg
3、要更改联系人的信息
要修改contacts.cfg配置文件
/usr/local/nagios/etc/objects/contacts.cfg
4、要调整监控时间
要修改timeperiods.cfg配置文件
/usr/local/nagios/etc/objects/contacts.cfg
5、添加具体的监控服务
要修改services.cfg配置文件,这里信息都是来自其他配置文件的
6、存放相关的命令执行脚本
/usr/local/nagios/libexecls
7、/usr/local/nagios/etc/objects/commands.cfg 定义相关命令
yum 源安装配置
vi /etc/yum.repos.d/Centos-Media.repo
[xscl]
baseurl=file:///mnt/cdrom/
gpgcheck=0
enabled=1
:wq
安装nagios必须的基本组件的运行依赖于httpd、gcc和gd.
yum clean all
准备工作:
yum -y install httpd* php
yum -y install gcc glibc glibc-common
yum -y install gd gd-devel
groupadd nagcmd
useradd -m nagios
usermod -a -G nagcmd nagios
# usermod -a -G nagcmd apache
#j将apache用户加入nagcmd组使之工作时具有足够的权限
下载所需要的安装组件:
服务器端所用的安装包:nagios nagios-plugins ndoutils(非必须)
linux客户端:nrpe
windows客户端:NSCLIENT
创建用户:
chkconfig httpd on
useradd nagios
cd /root
上传软件包我这里下载的nagios-3.3.1.tar.gz
tar-xzvf nagios-3.3.1.tar.gz
cd nagios
#./configure --with-command-group=nagcmd
make install
报错解决方法如下:
今天安装nagios3.3.1,不是第一次安装了,之前都很顺利,这次安装的时候,在执行命令make install的时候,报错了。大致如下
[root@magedu nagios]# make install
cd ./base && make install
make[1]: Entering directory `/root/nagios/base'
make install-basic
make[2]: Entering directory `/root/nagios/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagios /var/www/html/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagiostats /var/www/html/nagios/bin
make[2]: Leaving directory `/root/nagios/base'
make strip-post-install
make[2]: Entering directory `/root/nagios/base'
/usr/bin/strip /var/www/html/nagios/bin/nagios
/usr/bin/strip /var/www/html/nagios/bin/nagiostats
make[2]: Leaving directory `/root/nagios/base'
make[1]: Leaving directory `/root/nagios/base'
cd ./cgi && make install
make[1]: Entering directory `/root/nagios/cgi'
make install-basic
make[2]: Entering directory `/root/nagios/cgi'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/sbin
for file in *.cgi; do \
/usr/bin/install -c -m 775 -o nagios -g nagios $file /var/www/html/nagios/sbin; \
done
make[2]: Leaving directory `/root/nagios/cgi'
make strip-post-install
make[2]: Entering directory `/root/nagios/cgi'
for file in *.cgi; do \
/usr/bin/strip /var/www/html/nagios/sbin/$file; \
done
make[2]: Leaving directory `/root/nagios/cgi'
make[1]: Leaving directory `/root/nagios/cgi'
cd ./html && make install
make[1]: Entering directory `/root/nagios/html'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/media
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/stylesheets
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/contexthelp
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/docs
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/docs/p_w_picpaths
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/p_w_picpaths
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/p_w_picpaths/logos
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/includes
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/includes/rss
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/includes/rss/extlib
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/www/html/nagios/share/ssi
/usr/bin/install -c -m 664 -o nagios -g nagios robots.txt /var/www/html/nagios/share
rm -f /var/www/html/nagios/share/index.html
rm -f /var/www/html/nagios/share/main.html
rm -f /var/www/html/nagios/share/side.html
for file in *.php; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share; done
for file in stylesheets/*.css; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/stylesheets; done
for file in contexthelp/*.html; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/contexthelp; done
for file in p_w_picpaths/*.gif; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/p_w_picpaths; done
for file in p_w_picpaths/*.jpg; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/p_w_picpaths; done
for file in p_w_picpaths/*.png; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/p_w_picpaths; done
for file in p_w_picpaths/*.ico; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/p_w_picpaths; done
for file in p_w_picpaths/logos/*.*; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/p_w_picpaths/logos; done
for file in includes/*.*; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/includes; done
for file in includes/rss/*; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /var/www/html/nagios/share/includes/rss; done
/usr/bin/install: omitting directory `includes/rss/extlib'
/usr/bin/install: omitting directory `includes/rss/htdocs'
/usr/bin/install: omitting directory `includes/rss/scripts'
make[1]: *** [install] Error 1
make[1]: Leaving directory `/root/nagios/html'
make: *** [install] Error 2
很纠结啊,google了一下,有解决方案,好像是makefile里有语法错误,具体怎么导致的不清楚,执行完以下命令,就OK了
# sed -i 's:for file in includes/rss/\*;:for file in includes/rss/\*.\*;:g' ./html/Makefile
# sed -i 's:for file in includes/rss/extlib/\*;:for file in includes/rss/extlib/\*.\*;:g' ./html/Makefile
然后,执行以下命令,来完成安装
请注意看最后的提示,如果对以上反馈信息接受的话,则需要继续执行“make all”命令来编译主程序以及CGI。
为email指定您想用来接收nagios警告信息的邮件地址,默认是本机的nagios用户:
# vi /usr/local/nagios/etc/objects/contacts.cfg
email nagios@localhost #这个是默认设置
# make install-webconf
#在/etc/httpd/conf.d/nagios.conf生成web相关配置文件,用于定义nagios使用的CGI选项,web的身份认证等
[root@station71 nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagios
#为nagios的web页面创建账号密码,对访问进行身份认证
service httpd restart
chkconfig httpd on
启动httpd,并设置开机启动
3.预配置Nagios-plugin插件程序的环境以及指定安装路径
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql
[root@ nagios-plugins-1.4.10]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql预配置完成的话将会建立Makefile并反馈检测系统环境的结果。 ----------------------------------------------------- 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 --with-perl: /usr/bin/perl --enable-perl-modules: no --with-cgiurl: /nagios/cgi-bin --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin -----------------------------------------------------
drwxrwxr-x 4 nagios nagios 4096 Oct 5 19:08 var
7/ cd /usr/local/nagios/libexec
ll
[root@localhost libexec]# ll
total 6436
-rwxr-xr-x. 1 root root 376516 Jun 4 19:06 check_apt
-rwxr-xr-x. 1 root root 2254 Jun 4 19:06 check_breeze
-rwxr-xr-x. 1 root root 128392 Jun 4 19:06 check_by_ssh
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_clamd -> check_tcp
-rwxr-xr-x. 1 root root 85678 Jun 4 19:06 check_cluster
-r-sr-xr-x. 1 root root 123723 Jun 4 19:06 check_dhcp
-rwxr-xr-x. 1 root root 121722 Jun 4 19:06 check_dig
-rwxr-xr-x. 1 root root 417871 Jun 4 19:06 check_disk
-rwxr-xr-x. 1 root root 9148 Jun 4 19:06 check_disk_smb
-rwxr-xr-x. 1 root root 129579 Jun 4 19:06 check_dns
-rwxr-xr-x. 1 root root 80681 Jun 4 19:06 check_dummy
-rwxr-xr-x. 1 root root 3056 Jun 4 19:06 check_file_age
-rwxr-xr-x. 1 root root 6318 Jun 4 19:06 check_flexlm
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_ftp -> check_tcp
-rwxr-xr-x. 1 root root 123705 Jun 4 19:06 check_hpjd
-rwxr-xr-x. 1 root root 519173 Jun 4 19:06 check_http
-r-sr-xr-x. 1 root root 133809 Jun 4 19:06 check_icmp
-rwxr-xr-x. 1 root root 93400 Jun 4 19:06 check_ide_smart
-rwxr-xr-x. 1 root root 15137 Jun 4 19:06 check_ifoperstatus
-rwxr-xr-x. 1 root root 12601 Jun 4 19:06 check_ifstatus
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_imap -> check_tcp
-rwxr-xr-x. 1 root root 6890 Jun 4 19:06 check_ircd
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_jabber -> check_tcp
-rwxr-xr-x. 1 root root 106623 Jun 4 19:06 check_ldap
lrwxrwxrwx. 1 root root 10 Jun 4 19:06 check_ldaps -> check_ldap
-rwxr-xr-x. 1 root root 106565 Jun 4 19:06 check_load
-rwxr-xr-x. 1 root root 6020 Jun 4 19:06 check_log
-rwxr-xr-x. 1 root root 20287 Jun 4 19:06 check_mailq
-rwxr-xr-x. 1 root root 93126 Jun 4 19:06 check_mrtg
-rwxr-xr-x. 1 root root 92471 Jun 4 19:06 check_mrtgtraf
-rwxr-xr-x. 1 root root 129508 Jun 4 19:06 check_mysql
-rwxr-xr-x. 1 root root 122490 Jun 4 19:06 check_mysql_query
-rwxr-xr-x. 1 root root 105598 Jun 4 19:06 check_nagios
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_nntp -> check_tcp
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_nntps -> check_tcp
-rwxr-xr-x. 1 root root 127807 Jun 4 19:06 check_nt
-rwxr-xr-x. 1 root root 130198 Jun 4 19:06 check_ntp
-rwxr-xr-x. 1 root root 119287 Jun 4 19:06 check_ntp_peer
-rwxr-xr-x. 1 root root 117856 Jun 4 19:06 check_ntp_time
-rwxr-xr-x. 1 root root 159492 Jun 4 19:06 check_nwstat
-rwxr-xr-x. 1 root root 8324 Jun 4 19:06 check_oracle
-rwxr-xr-x. 1 root root 109022 Jun 4 19:06 check_overcr
-rwxr-xr-x. 1 root root 105553 Jun 4 19:06 check_pgsql
-rwxr-xr-x. 1 root root 132787 Jun 4 19:06 check_ping
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_pop -> check_tcp
-rwxr-xr-x. 1 root root 396825 Jun 4 19:06 check_procs
-rwxr-xr-x. 1 root root 106620 Jun 4 19:06 check_real
-rwxr-xr-x. 1 root root 9584 Jun 4 19:06 check_rpc
-rwxr-xr-x. 1 root root 1412 Jun 4 19:06 check_sensors
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_simap -> check_tcp
-rwxr-xr-x. 1 root root 445174 Jun 4 19:06 check_smtp
-rwxr-xr-x. 1 root root 447023 Jun 4 19:06 check_snmp
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_spop -> check_tcp
-rwxr-xr-x. 1 root root 103128 Jun 4 19:06 check_ssh
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_ssmtp -> check_tcp
-rwxr-xr-x. 1 root root 108201 Jun 4 19:06 check_swap
-rwxr-xr-x. 1 root root 158985 Jun 4 19:06 check_tcp
-rwxr-xr-x. 1 root root 105150 Jun 4 19:06 check_time
lrwxrwxrwx. 1 root root 9 Jun 4 19:06 check_udp -> check_tcp
-rwxr-xr-x. 1 root root 117678 Jun 4 19:06 check_ups
-rwxr-xr-x. 1 root root 83418 Jun 4 19:06 check_users
-rwxr-xr-x. 1 root root 2939 Jun 4 19:06 check_wave
-rwxr-xr-x. 1 root root 109707 Jun 4 19:06 negate
-rwxr-xr-x. 1 root root 103234 Jun 4 19:06 urlize
-rwxr-xr-x. 1 root root 1939 Jun 4 19:06 utils.pm
-rwxr-xr-x. 1 root root 2728 Jun 4 19:06 utils.sh
8、