一 对比php
Cacti:
收集数据、图形展现
偏重网络流量
SNMP、OID、SNMP Agent
Nagios:
偏重主机、服务的状态
Agent
脚本
二 原理mysql
原理-1linux
监控对象 主机、主机组 服务/资源,服务组 联系人,联系人组 时段 命令
原理-2
ios
原理-3web
原理-4sql
三 操做apache
1. 安装前的准备工做vim
1)解决安装Nagios的依赖关系 yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel #gd先去除 2)所须要安装组件: 服务端所用的安装包为 nagios nagios-plugins ndoutils(非必须) linux客户端 nrpe windows客户端 NSClient++ 3) 进行selinux设置,或者关闭selinux 4)开始搭建 添加nagios运行所须要的用户和组: # groupadd nagcmd # useradd -m nagios # usermod -a -G nagcmd nagios # usermod -a -G nagcmd apache
2. 编译安装nagioswindows
# tar zxf nagios-3.1.2.tar.gz # cd nagios-3.1.2 # ./configure --with-command-group=nagcmd --enable-event-broker # make all # make install # make install-init # make install-config # make install-commandmode # vi /usr/local/nagios/etc/objects/contacts.cfg email nagios@localhost #这个是默认设置 # make install-webconf # htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin # service httpd restart
3. 编译、安装nagios-plugins浏览器
yum -y install openssl openssl-devel # tar -zxf nagios-plugins-1.4.15.tar.gz # cd nagios-plugins-1.4.15 # ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql --enable-perl-modules # make && make install
4. 配置并启动Nagios
# chkconfig --add nagios # chkconfig nagios on # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检测是否有错误 Total Warnings: 0 Total Errors: 0 # service nagios start 浏览器测试: 登陆时须要指定前面设定的web认证账号和密码 http://192.168.10.10/nagios/ user:nagiosadmin pwd: 123
windos端
1.被监控端安装NSClient++-0.3.8-Win32.msi #netstat -an --> tcp 5666 2.安装完成后修改配置文件NSC.ini把须要的库都打开 3.在监控服务器上修改nagios配置文件nagios.cfg 去掉注释cfg_file=/usr/local/nagios/etc/objects/windows.cfg 定义windows.cfg define host{ use windows-server ; Inherit default values from a template host_name winserver ; The name we're giving to this host alias My Windows Server ; A longer name associated with the host address 192.168.0.191 ; 你主机的IP } /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
linux端
被监控端 先添加nagios用户 useradd nagios 为了安装nrpe,先安装nagios-plugins-1.4.15.tar.gz 插件 yum -y install openssl openssl-devel gcc* # tar zxf nagios-plugins-1.4.15.tar.gz # cd nagios-plugins-1.4.15 # ./configure --with-nagios-user=nagios --with-nagios-group=nagios # make all # make install tar -zxvf nrpe-2.12.tar.gz cd nrpe-2.12.tar.gz ./configure --enable-ssl --with-ssl-lib=/usr/lib64/ make all make install-plugin make install-daemon make install-daemon-config 4.配置nrpe信息 vim /usr/local/nagios/etc/nrpe.cfg allowed_hosts=192.168.216.251,127.0.0.1 //容许监控的IP [root@localhost nrpe-2.8.1]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d [root@localhost nrpe-2.8.1]# netstat -an | grep :5666 tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
服务端
3.安装NRPE cd nagios-nrpe_2.8.1 ./configure #默认自动添加了openssl #由于传送过程要加密,若是后面make报错,加以下参数 rpm -qa| grep ssl openssl-devel-0.9.7a-43.17.el4_6.1 rpm -ql openssl-devel-0.9.7a-43.17.el4_6.1 | more ./configure --enable-ssl --with-ssl-lib=/usr/lib64/(固然前提要有openssl) make all make install-plugin ---安装check_nrpe脚本 4.commands.cfg定义外部构件nrpe vi /usr/local/nagios/etc/objects/commands.cfg #添加 #check nrpe define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } 定义 mylinux.cfg define host{ use linux-server #到 vim templates.cfg 里,肯定 host_name mylinux/IP alias mylinux address 192.168.0.27(客户端IP既被监控的IP) } define service{ use generic-service host_name mylinux service_description check-load check_command check_nrpe!check_load } define service{ use generic-service host_name mylinux service_description check-users check_command check_nrpe!check_users } define service{ use generic-service host_name mylinux service_description otal_procs check_command check_nrpe!check_total_procs } [root@localhost etc]# vim nagios.cfg 39 cfg_file=/usr/local/nagios/etc/objects/windows.cfg #网页才会显示 40 cfg_file=/usr/local/nagios/etc/objects/linux.cfg