安装nagios过程
groupadd nagios
useradd -g nagios -d /usr/local/nagios -s /bin/false nagios
tar zxvf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./configure --prefix=/usr/local/nagios
make install
make install-init
make install-commandmode
make install-config
安装nagios插件
tar zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios/ --enable-redhat-pthread-workaround
make
make install
chown -R nagios:nagios /usr/local/nagios
chmod 755 nagios/usr/local/nagios
验证,将以下内容添加到httpd.conf文件最后:
Alias /nagios/cgi-bin/images/ "/usr/local/nagios/share/images/"
AllowOverride None
Options None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
ScriptAlias /nagios/cgi-bin/ "/usr/local/nagios/sbin/"
AllowOverride None
Options None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
Alias /nagios/ "/usr/local/nagios/share/"
AllowOverride None
Options None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
/usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/htpasswd 登陆账号
提示设置两便密码
检查htpasswd文件权限,改成nagios用户nagios组
/usr/local/apache/bin/apachctl –t检查httpd.conf文件语法是否正确,确认ok重启apache
使用域名方式登录,看到对话框输入用户名和密码即可(使用ip登陆则不会出现验证窗口)
vi nagios.cfg
注意:
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
1、默认是注销掉的,一定要把注销的符号去掉,否则检查nagios的配置文件要报错
2、这里添加每个需要监控的主机,如:cfg_file=/usr/local/nagios/etc/objects/windows.cfg
3、在objects建立windows.cfg才能被监控,两个地方要一一对应
vi resource.cfg
vi cgi.cfg
vi commands.cfg
vi hosts.cfg
vi services.cfg
启动nagios
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
/usr/local/etc/rc.d/nagios start
安装npre
下载:
tar nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
vi /etc/services
加入nrpe 5666/tcp # NRPE
vi /etc/sysconfig/network
HOSTNAME=192.168.0.7改成ip格式
service xinetd restart
netstat -at | grep nrpe
/usr/local/nagios/libexec/check_nrpe -H localhost
显示NRPE v2.12说明安装成功
vi /etc/sysconfig/iptables
插入-I RH-Firewall-1-INPUT -m tcp -p tcp --dport 5666 -j ACCEPT
service iptables save
启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg --daemon
监控windows主机
下载NSClient++-Win32-0.3.5.zip
在windows主机安装NSClient++-Win32-0.3.5.zip
解压并将文件夹改名为NSClient,移到C盘根目录
打开DOS:
nsclient++ /install
nsclient++ SysTray #如果出错不用管!
编辑NES.ini:
在 [modules] 选项里
去掉所有的注释符号; 除了
CheckWMI.dll和RemoteConfiguration.dll
修改allowd_host=210.x.x.x(nagios服务器的ip)
如果这一步要修改passwd,那么nagios服务器里面command.cfg也要修改!
[NSClient] 里面,去掉port=12489的注释!
他靠端口12489侦听,所以防火墙要打开这个端口!
然后启动nsclient
nsclient++ /start
配置nagios.cfg
vi /usr/local/nagios/etc/nagios.cfg
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg 去掉这句话的注释
如果监控多台主机,需要在增加相应的配置文件,如:
#cfg_file=/usr/local/nagios/etc/objects/eastnt14.cfg
配置windows.cfg
vi /usr/local/nagios/etc/objects/windows.cfg
define host{
use windows-server
host_name winserver alias
My Windows Server
address 被监控端的IP
}
修改hostname和address,很重要!!
然后下面的很多定义,都可以不用改,想知道每个定义的意思,去看看官方的文档!!
下面的定义全部修改hostname 都改为自己的!一定要一样!
保存并退出!
重启nagios
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
/usr/local/etc/rc.d/nagios restart
如果这个时候出错!尝试去telnet win服务器的ip 12489端口!!
监控80端口(http服务)
/usr/local/nagios/libexec/check_http -H test.east.net -p 80 -I 192.168.0.17
返回:HTTP OK: HTTP/1.1 200 OK - 2095 bytes in 0.007 second response time |time=0.007139s;;;0.000000 size=2095B;;;0
问题:
1、contacts.cfg里面定义服务的名称一定要和commands.cfg里面定义的一致
2、timeperiods.cfg里定义的hostgroup一定要和hosts.cfg里hostgroup_name定义的一致
阅读(1900) | 评论(0) | 转发(0) |