--> nagios功能
监控主机和网络服务,在主机或服务出现异常时通过邮件或即时通讯等方式通告指定人员。通过CGI脚本,我们可以访问WEB页面来了解主机和网络服务的运行情况。
安装过程
nagios的网站http://www.nagios.org上有一篇quickstart installation guides
http://nagios.sourceforge.net/docs/3_0/quickstart.html
这篇文章可以指导我们快速的搭建nagios系统,下面是我的安装笔记:
首先创建用户nagios
[root@centerws root]# useradd nagios
锁定用户,因为我根本就不打算使用这个用户登录、本人养成了以root登陆的坏习惯。
[root@centerws root]# usermod -L nagios
解压软件(你可以到http://www.nagios.org/download/下载你准备安装的版本),在此我选用生版本2.10,因为这是最新的稳定版本。
[nagios@centerws download]$ tar zxvf nagios-2.10.tar.gz
[nagios@centerws download]$ tar zxvf nagios-plugins-1.4.10.tar.gz
运行configure脚本(在此我将nagios的安装目录设定在/home/nagios下):
[nagios@centerws nagios-2.10]$ ./configure --prefix=/home/nagios --with-command-group=nagcmd
编译:
[nagios@centerws nagios-2.10]$ make all
安装:
[nagios@centerws nagios-2.10]$ make install
安装init脚本(需要切换到root用户,此步骤将会在/etc/init.d目录下创建nagios脚本):
[root@centerws nagios-2.10]# make install-init
安装配置文件:
[nagios@centerws nagios-2.10]$ make install-config
下面这一步我也不知道是什么意思:
[nagios@centerws nagios-2.10]$ make install-commandmode
更改配置文件,将管理员的email添进去:
[nagios@centerws nagios-2.10]$ cd /home/nagios/etc/
[nagios@centerws etc]$ vi localhost.cfg
可以在97行看到管理员的联系方式定义,将email栏改为管理员的邮件地址(最好设定一个单独的邮箱用于管理):
define contact{
contact_name nagios-admin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email nagios@supersun.biz
}
web的配置部分,如果你的apache是用rpm默认安装的,可以使用以下命令():
[nagios@centerws nagios-2.10]$ make install-webconf
这样/etc/httpd/conf.d目录下会生成nagios.conf
如果apache是自己定制的,我们可以手动将配置文件拷贝过去(注意权限问题):
[nagios@centerws nagios-2.10]$ cp sample-config/httpd.conf /home/httpd/conf/nagios.conf
然后更改httpd.conf,在其中添加:
Include conf/nagios.conf
对nagios的web访问设定用户及口令:
[nagios@centerws nagios]$ /home/httpd/bin/htpasswd -c ~/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
下面来编译nagios-plugins(这些plugins用于检测各种服务和发送邮件等)
[nagios@centerws nagios-plugins-1.4.10]$ ./configure --prefix=/home/nagios --with-nagios-user=nagios --with-nagios-group=nagios
[nagios@centerws nagios-plugins-1.4.10]$ make
[nagios@centerws nagios-plugins-1.4.10]$ make install
使nagios可以自动启用:
[root@centerws conf]# chkconfig --add nagios
[root@centerws conf]# chkconfig nagios on
[root@centerws conf]# chkconfig --list nagios
nagios 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
在当前系统中启动nagios:
[root@centerws conf]# service nagios start
Starting nagios: done.
重启apache:
[root@centerws conf]# /home/httpd/bin/apachectl restart
访问http://ws/nagios得到403错误,查看日志/home/httpd/log/error.log
Permission denied: access to /nagios denied
原来目录/home/nagios权限为700
重新设定权限:
[root@centerws home]# chmod 775 nagios
目录权限如下:
drwxrwxr-x 10 nagios nagcmd 4096 12月 28 15:22 nagios
在次访问http://ws/nagios时跳出认证框,添入之前识定的用户名和密码进入页面:
但此时还不能看到监控的服务,当我点击Service Detail时得到时,系统提示我还没有权限查看服务信息:
更改nagios的主配置文件/home/nagios/etc/cgi.cfg
将以下两行前的注释去掉:
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
这样最基本的nagios就配置好了:
记得在更改完配置文件后要验证其的正确性:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果配置文件有错,可以根据其输出信息更正。

发表评论