安装前准备检查环境

iptables -F

setenforce 0


#gcc环境 lamp环境和其他的一些 nagios 的依赖包

yum -y install gcc* yum -y install httpd mysql mysql-server mysql-devel php php-server glibc glibc-common *gd*


#添加nagios运行所需要的用户和组

groupadd nagcmd 

useradd -G nagcmd nagios

usermod -G nagcmd apache


#编译安装nagios

mkdir /cdrom

cp -a /cdrom/* .

tar -xf nagios-3.3.1..tar.gz


cd nagios

./configure --with-commadn-group=nagcmd --enable-event-broker


make all && make install && make install-init make install-commandmode make install-config && make install-webconf


2.生成密码文件

htpasswd -c /usr/local/nagios/etc/htpasswd.user nagiosadmin



service httpd restart


在浏览器中查看效果输入用户名和密码


安装插件管理器nagios-plugins


解压编译


tar -xf nagios-plugins-1.4.14.tar.gz


cd /root/nagios-plugins-1.4.14


./configure --with-nagios-user=nagios --wtih-nagios-group=nagios --with-mysql --enable-perl-modules


make && make install


配置并启动nagios


chkconfig --add nagios


chkconfig nagios on


/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#此命令用来检测语法


service nagios start



windows 主机的监控

安装 NSCLIENt ++

wKioL1kuvLWgiiQmAAHnwrnGzfg551.png-wh_50

wKiom1kuvM2xUXtxAAFafFzoA8k079.png-wh_50


服务器端设置windows监控

cd /usr/local/nagios


cd etc/


cd objects/

wKioL1kuvRaQPLddAAA6D4TSrZs878.png-wh_50

#进入nagios主目录,启用windows的支持


vim nagios.cf


vim /usr/local/nagios/etc/objects/contacts.cfg


#39  cfg_file=/usr/local/nagios/etc/objects/windows.cfg


vim /usr/local/nagios/etc/objects/contacts.cfg


#35     email    nagios@localhost报警邮箱根据实际改找个软件最好然后用qq邮箱然后跟微信关联qq号然后微信就可以知道报警了


检测,并启动nagios服务


/usr/local/nagios/bin/nagios -v /usr/local/ngios/etc/nagios.cfg


service nagios restart


Linux的监控


安装gcc,openssl openssl-devel

yum -y install openssl openssl-devel



安装插件管理器nagios-plugins


创建个nagios用户,否则会报错


useradd nagios


cd /root

tar -xf nagios-plugins-1.4.14.tar.gz


cd nagios-plugins-1.4.14


./configure --with-nagios-user=nagios --with-nagios-group=nagios


make all && make install


安装nrpe确保openssl,openss-devel已经安装


tar -xf nrpe-2.8.1.tar.gz


cd nrpe-2.8.1


./configure --enable-ssl --with-ssl-lib=/usr/lib


make all  


make install-plugin


make install-daemon


make install-daemon-config


vim /usr/local/nagios/etc/nrpe.cfg


allowed_hosts=192.168.121.1 127.0.0.1


/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d



服务端装

nagios-plugins


./configure --enable-ssl --with-ssl-lib=/usr/lib


make all


make install-plugin


cd /usr/local/nagios/etc/


cd objects/


ls


vim linux.cfg


wKioL1kuv66yyK0gAABpH1pOC84026.png-wh_50


vim cmmands.cfg


wKiom1kuv8-zkdD7AABlpWdUUzQ292.png-wh_50

启用自定义的liunx.cfg文件


vim /usr/local/nagios/etc/nagios.cfg


31# cfg_file=/usr/local/nagios/etc/objects/linux.cfg



检测并启用

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


service nagios restart


服务的监控

客户端


yum -y install mysql mysql-server


service mysqld start


mysqladmin -uroot password '123123'


mysql -uroot -p


create database nagios;


grant selcet on nagios.* to nagios@'%' identifed by '123123';


select user,password,host from mysql.user;


服务端检查一下是否能够连接数据库


/usr/local/nagios/libexec/check_mysql -H 192.168.121.1 -u nagios -d nagios -p 123123


vim mysql.cfgwKioL1kuwQuxjc2_AABKkOQBdEc647.png-wh_50



启动配置

vim /usr/local/nagios/etc/nagios.cfg

wKioL1kuwTyAAWYCAAB272MIMzY711.png-wh_50


vim commadns.cfg

wKiom1kuwV3zwblhAABrBhiWuEo149.png-wh_50

检测启动nagios

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


service nagios restart


在浏览器中查看