一、Nagios服务端安装
1、yum install –y httpd php mysql mysql-devel
2、服务器端安装nagios程序
wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz/download
http://down1.chinaunix.net/distfiles/nagios-plugins-1.4.14.tar.gz
/usr/sbin/useraddnagios
tar zxvfnagios-3.2.1.tar.gz
cdnagios-3.2.1
./configure--prefix=/usr/local/nagios --with-command-group=nagios
make all
make install;makeinstall-init;make install-config;make install-commandmode ;make install-webconf
makeinstall //来安装主程序,CGI和HTML文件
makeinstall-init //在/etc/rc.d/init.d安装启动脚本
makeinstall-config //来安装示例配置文件,安装的路径是/usr/local/nagios/etc
makeinstall-commandmode //来配置目录权限
makeinstall-webconf // 配置nagios跟apache整合
3、安装Nagios-plugins插件,监控用
tar zxvfnagios-plugins-1.4.14.tar.gz
cdnagios-plugins-1.4.14
./configure--prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make&& make install
4、服务器端安装nrpe,与客户端通信
tar -xzf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure --enable-ssl --with-ssl-lib
make all
make install-plugin && make install-daemon&& make install-daemon-config
chown -R nagios.nagios /usr/local/nagios
5、nagios访问控制设置
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
输入两次密码即可,登录页面的时候会用到这个密码.
6、重启nagios、httpd服务
重启前
/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg 检测是否正确
重启nagios,/etc/init.d/nagios restart ;/etc/init.d/httpd restart ;
7、Nagios测试访问 用户名:nagiosadmin
http://localhost/nagios/ 如下图:
点击左侧的Hosts可以看到右侧默认localhost主机的监控,UP表示主机目前运行正常:
点击左侧的Services可以看到右侧默认localhost监控的各个服务的状态,绿色OK表示正常:
取消大喇叭,
点击大喇叭图标-- Enable notifications forthis service
点commit
Error:Could not opencommand file '/usr/local/nagios/var/rw/nagiosNaNd' for update! 错误提示没有权限,
授权这个文件 chmod 777 /usr/local/nagios/var/rw/nagiosNaNd
出现错误:
HTTP WARNING:HTTP/1.1 403 Forbidden - 5159 bytes in 0.002 second response time(警告:HTTP HTTP / 1.1没有权限访问此网站-0.002秒的响应时间5159个字节)
新建网页index.html并授权
chmod o+w/var/www/html/index.html
二、Nagios监控客户端安装
1、安装nagios-plugins
useradd -s /sbin/nologin nagios
tar -xzf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios
&&make &&make install
2、客户端安装nrpe
tar -xzfnrpe-2.14.tar.gz && cd nrpe-2.14 &&
./configure--enable-ssl --with-ssl-lib &&
make all
makeinstall-plugin && make install-daemon && makeinstall-daemon-config
chown-R nagios:nagios /usr/local/nagios/
启动nrpe客户端命令:
/usr/local/nagios/bin/nrpe-c /usr/local/nagios/etc/nrpe.cfg -d
3、客户端nrpe设置
vi /usr/local/nagios/etc/nrpe.cfg
在allowed_hosts=127.0.0.1 字段后面加上nagios服务器端的IP地址
allowed_hosts=127.0.0.1,192.168.1.151或者allowed_hosts=127.0.0.1,192.168.1.0/24
(责任编辑:IT) |