一、
nagios
简介
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
nagios是一款用于系统和网络监控的应用程序,它可以在你的设定的条件下对主机和服务进行监控,在状态变差和变好的时候可以给管理员出告警信息。
nagios所需要的运行条件是机器必须可以运行linux(或是unix变种)并且有c语言编译器。你必须正确地配置tcp/ip协议栈以使大多数的服务检测可以通过网络得以进行。如果需要正确地配置nagios里的cgis程序,必须安装以下这些软件:
web服务(最好是apache)
thomas boutell制作的gd库版本应是<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />1.6.3或更高(在cgis程序模块statusmap和trends这两个模块里需要这个库)
还有一个就是ssl这一个工具,在安装nrpe这一个包时需要,因为在监控其他主机的时候是通过ssl连接来接收数据的;
网络环境:
主机 IP OS 角色
nagios 192.168.0.10 rhel5.1 监控服务器
win2003 192.168.0.100 windows server 2003 被监控主机
linux 192.168.0.102 rhel5.1 被监控主机
准备软件:
apache2.2.14 //下载地址http://httpd.apache.org/download.cgi
nagios3.2.0
nagios plugins1.4.14
nrpe2.12
上面三个都可以在这个网站上找到http://www.nagios.org/download
nsclient++-0.3.6-win32.msi //如果要监控windows的主机,还要下载nsclient这一个客户端工具,下载地址:http://sourceforge.net/projects/nscplus/
确认邮件是否能正常发送,我用的是sendmail,确认服务已经启动,下面发一封测试邮件到指定邮箱:
mail –s “this is test mail” kyhack@vip.qq.com
this is nagios test mail
ok
按ctrl + d 结束输入。
检查一下自大的邮箱,看到邮件之后就可以继续以下的环节了。
把所有的工具都下载到src目录下面:
把所有的工具都下载到src目录下面:
二、开始安装
1、安装apache
tar xvf httpd-2.2.14.tar.gz
cd httpd-2.2.14
./configure --prefix=/usr/local/apache2
make
make install
/usr/local/apache/bin/apachectl start //由于是没有改动的配置文件,可以直接启动
netstat –an |grep 80 //检查80端口是否已经开启了
或者是在别的机子上输入服务器的ip地址,当看到”it works!”时表明apache已经安装成功了
2、安装nagios
先添加一个nagios的账号
useradd nagios –s /sbin/nologin //有的文章说要启用账号,其实不用也可以,因为这个账号不需要登录
tar xvf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./condfigure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
make install‐init //在/etc/rc.d/init.d安装启动脚本
make install‐config //安装示例配置文件,安装的路径是/usr/local/nagios/etc
make install‐commandmode //配置目录权限
安装完成nagios后就可以在/usr/local/nagios下面看到这几个目录:
bin 存放nagios执行程序,nagios文件为主程序
etc 配置文件存放目录
libexec 存放一些脚本程序
sbin
cgi
文件所在目录,也就是执行外部命令所需文件所在的目录
share 网页文件存放位置
var
日志文件、
spid
等文件所在的目录
3、安装nagios插件
tar xvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios //注意了,是放在/usr/local/nagios 里,别搞错了
make
make install
chown –R nagios:nagios /usr/local/nagios //改一下文件的属组
#这样的话那些插件都会扔到nagios/libexec下面去
三、修改配置文件
1、修改apache的配置文件,我只把改的地方贴出来
vi /usr/local/apache2/conf/httpd.conf
User nagios //把apache运行用户改成 nagios
Group nagios //把apache运行组改成 naios
#把下面的内容增加到文件的最后:
Scriptalias /nagios/cgi-bin /usr/local/nagios/sbin
<directory "/usr/local/nagios/sbin">
Authtype basic
Options execcgi
Allowoverride none
Order allow,deny
Allow from all
Authname "nagios access"
Authuserfile /usr/local/nagios/etc/htpasswd //
用于此目录访问身份验证的文件
Require valid-user
</directory>
Alias /nagios /usr/local/nagios/share
<directory "/usr/local/nagios/share">
Authtype basic
Options none
Allowoverride none
Order allow,deny
Allow from all
Authname "nagios access"
Authuserfile /usr/local/nagios/etc/htpasswd //
用于此目录访问身份验证的文件
Require valid-user
</directory>
别忘记了重启apache服务喔。。。。
2、修改cgi脚本控制文件cgi.cfg
vi /usr/local/nagios/etc/cgi.cfg
use_authentication=1 //打开验证
default_user_name=test
authorized_for_system_information=nagiosadmin,test
authorized_for_configuration_information=nagiosadmin,test
authorized_for_system_commands=nagiosadmin,test
authorized_for_all_services=nagiosadmin,test
authorized_for_all_hosts=nagiosadmin,test
authorized_for_all_service_commands=nagiosadmin,test
authorized_for_all_host_commands=nagiosadmin,test
//这里添加的用户”test”可以通过浏览器对nagios服务的关闭、重启等操作,在这里为了安全也可以把nagiosadmin这一个用户给删掉,如果有多个用户用逗号隔开,如:nagiosadmin,test
/usr/local/apache2/bin/htpasswd ‐c /usr/local/nagios/etc/htpasswd test
new password: 输入你的密码
re‐type new password: 再次确认
adding password for user test //这里给前面添加的用户设置密码
测试一下,输入你的http://你的服务器IP/nagios之后会弹出以下界面:
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />
在这里输入你刚刚设置的用户名密码,就可以登录你的监控平台了,如下:
由于我们目前是没有监控任何的主机,所以目前还是看不到什么有用的东西的。
所以说呢,接下来继续配置其他的配置文件;
转载于:https://blog.51cto.com/kyhack/213355