Cacti+Nagios(一):安装环境
系统版本:CentOS-6.5-x86_64
一、系统环境
1、主机名
[root@nagios ~]# hostname nagios.ewin.com
[root@nagios ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=nagios.ewin.com
2、yum源
(1)使用本地源
挂载光盘或ISO文件并配置源:
[root@nagios ~]# mkdir /media/cdrom
[root@nagios ~]# mount /dev/cdrom /media/cdrom/
[root@nagios ~]# cd /etc/yum.repos.d
[root@nagios yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@nagios yum.repos.d]# vi CentOS-Base.repo
[base]
name=Base
baseurl=file:///media/cdrom/
gpgcheck=0
enabled=1
(2)添加163的源
[root@nagios yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
(3)更新列表
[root@nagios yum.repos.d]# yum clean all
[root@nagios yum.repos.d]# yum list
(4)解除锁定状态
使用yum安装时可能会出现锁定状态,报错如下:
Another app is currently holding the yum lock; waiting for it to exit…
解决方法:
[root@nagios ~]# rm -f /var/run/yum.pid
3、X桌面环境
查看是否安装了桌面环境的组件,没有则进行组安装:
[root@nagios ~]# yum grouplist | more
[root@nagios ~]# yum groupinstall -y “Desktop” “Desktop Platform” “Desktop Platform Development” “Fonts” ”General Purpose Desktop” “Graphical Administration Tools” “Graphics Creation Tools” ”Input Methods” ”X Window System” ”Chinese Support [zh]” ”Internet Browser”
修改启动级别为5后重启服务器:
[root@nagios ~]# vi /etc/inittab
id:5:initdefault:
[root@nagios ~]# reboot
4、网卡配置
查看网络配置:
[root@nagios ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:15:5D:01:2C:00
inet addr:10.188.1.103 Bcast:10.188.1.255 Mask:255.255.255.0
inet6 addr: fe80::215:5dff:fe01:2c00/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20570650 errors:0 dropped:0 overruns:0 frame:0
TX packets:23909757 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1997534214 (1.8 GiB) TX bytes:1952904919 (1.8 GiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1691114 errors:0 dropped:0 overruns:0 frame:0
TX packets:1691114 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:96615865 (92.1 MiB) TX bytes:96615865 (92.1 MiB)
手动设置网卡:
[root@nagios ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #接口名称
TYPE=Ethernet #接口类型:以太网
ONBOOT=yes #开机启动
BOOTPROTO=static #静态IP
HWADDR=00:15:5D:01:2C:00 #MAC地址
IPADDR=10.188.1.103 #IP地址
PREFIX=24 #子网掩码位数,或使用NETMASK=255.255.255.0
GATEWAY=10.188.1.1 #网关地址
DNS1=10.188.1.2 #DNS服务器地址,我这是内网的DNS
DNS2=202.101.224.68 #公网DNS服务器地址
重启网卡:
[root@nagios ~]# ifdown eth0 && ifup eth0
5、vnc远程桌面
安装及启动进程1(端口号是5900+1):
[root@nagios ~]# yum install -y tigervnc-server
[root@nagios ~]# vncserver :1
#输入密码123456
配置启动脚本,使用Gnome会话模式:
[root@nagios ~]# vi /root/.vnc/xstartup
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
#twm&
gnome-session
重启vnc进程:
[root@nagios ~]# vncserver -kill :1
[root@nagios ~]# vncserver :1
设置开机自动启动:
[root@nagios ~]# vi /etc/sysconfig/vncservers
VNCSERVERS=“1:root”
VNCSERVERARGS[1]=“-geometry 800×600 -alwaysshared “
[root@nagios ~]# chkconfig vncserver on
6、selinux安全项
[root@nagios ~]# vi /etc/selinux/config
SELINUX=disabled
[root@nagios ~]# setenforce 0
7、ntpupdate时间同步
[root@nagios ~]# crontab -e
0 * * * * /usr/sbin/ntpdate 65.55.56.206 #1小时同步一次
[root@nagios ~]# service crond restart
[root@nagios ~]# ntpdate 65.55.56.206
18 Nov 10:07:49 ntpdate[8567]: step time server 65.55.56.206 offset -0.743765 sec
8、FTP文件传输
[root@nagios ~]# yum install -y vsftpd
[root@nagios ~]# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO #禁止匿名访问
userlist_deny=NO #(手动添加)使用FTP用户表
[root@nagios ~]# useradd ywzhou
[root@nagios ~]# passwd ywzhou
#输入密码123456
[root@nagios ~]# vi /etc/vsftpd/user_list
ywzhou
[root@nagios ~]# /etc/init.d/vsftpd start
[root@nagios ~]# chkconfig vsftpd on
9、防火墙
[root@nagios ~]# iptables -I INPUT -p tcp –dport 80 -j ACCEPT
[root@nagios ~]# iptables -I INPUT -p tcp –dport 21 -j ACCEPT
[root@nagios ~]# iptables -I INPUT -p tcp –dport 5901 -j ACCEPT
[root@nagios ~]# service iptables save
二、LAMP环境
1、安装Apache
[root@nagios ~]# yum install -y httpd
[root@nagios ~]# vi /etc/httpd/conf/httpd.conf
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
[root@nagios ~]# service httpd start
[root@nagios ~]# chkconfig httpd on
2、安装PHP
[root@nagios ~]# yum -y install php php-devel php-snmp php-gd php-mysql
访问测试:
[root@nagios ~]# vi /var/www/html/index.php
<?php phpinfo(); ?>
http://localhost
结论:会显示php的相关信息表示php+apache整合成功
3、安装Mysql
[root@nagios ~]# yum install mysql mysql-server mysql-devel
[root@nagios ~]# service mysqld start
[root@nagios ~]# chkconfig mysqld on
[root@nagios ~]# mysqladmin -u root password ‘123456’
当主机断电重启后zabbix无法连接mysql,报错如下:
Another MySQL daemon already running with the same unix socket
要先删除mysql.sock文件才能启动mysqld,因此在执行下面的命令开机重启mysql:
[root@nagios ~]# echo “rm -f /var/lib/mysql/mysql.sock && service mysqld restart” >> /etc/rc.local
三、编译环境
1、安装gcc
[root@nagios ~]# yum install gcc
2、安装glibc
[root@nagios ~]# yum install glibc glibc-common
3、安装gd
[root@nagios ~]# yum install gd gd-devel
4、安装pcap
[root@nagios ~]# yum install libtool libpcap libpcap-devel gdbm gdbm-devel zlib zlib-devel
Cacti+Nagios(二):安装Cacti
1、设置mysql,创建Cacti数据库和账号
[root@nagios ~]# mysql -u root -p123456
mysql> create database cactidb;
mysql> GRANT ALL ON cactidb.* TO cactier@localhost IDENTIFIED BY ‘123456’;
mysql> flush privileges;
mysql> quit
2、安装rrdtool
[root@nagios ~]# yum -y install rrdtool rrdtool-devel rrdtool-php
3、安装配置snmp
[root@nagios ~]# yum install -y net-snmp net-snmp-utils net-snmp-libs
[root@nagios ~]# vi /etc/snmp/snmpd.conf
可修改community默认密码public
[root@nagios ~]# service snmpd restart
[root@nagios ~]# chkconfig snmpd on
4、下载安装Cacti
[root@nagios ~]# mkdir /home/nagios
[root@nagios ~]# cd /home/nagios
[root@nagios nagios]# wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
[root@nagios nagios]# tar xzf cacti-0.8.8b.tar.gz
[root@nagios nagios]# mv cacti-0.8.8b /var/www/html/cacti
[root@nagios cacti]# cd /var/www/html/cacti
[root@nagios cacti]# mysql -uroot -p cactidb < cacti.sql
5、配置参数
[root@nagios cacti]# vi /var/www/html/cacti/include/config.php
$database_type = “mysql”;
$database_default = “cactidb”;
$database_hostname = “localhost”;
$database_username = “cactier”;
$database_password = “123456”;
$database_port = “3306”;
#$url_path = “/cacti/”;
6、添加用户、修改权限和属主
[root@nagios cacti]# useradd cactier
[root@nagios cacti]# passwd cactier
#输入密码123456
[root@nagios cacti]# usermod -G cactier apache
[root@nagios cacti]# chown -R root:root /var/www/html/cacti/
[root@nagios cacti]# chown -R cactier:cactier rra/ log/
7、Apache设置
[root@nagios cacti]# vi /etc/httpd/conf/httpd.conf
<Directory “/var/www/html/cacti “>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
[root@nagios cacti]# vi /etc/php.ini
date.timezone=Asia/Shanghai
[root@nagios cacti]# service httpd restart
8、添加计划
每5分钟更新RRD图形,poller是单线程程序,可以改用支持多线程和分布式的工具spine
[root@nagios cacti]# crontab -e
*/5 * * * * php /var/www/html/cacti/poller.php &> /dev/null
[root@nagios cacti]# service crond restart
[root@nagios cacti]# ntpdate 65.55.56.206
切换用户,手动执行后在rra目录下生成rrd图形文件
[root@nagios cacti]# su – cactier
[cactier@nagios cacti]# php /var/www/html/cacti/poller.php
也可以不执行手动操作,等待5分钟,观察rra目录下是否自动生成rrd文件
9、WEB页面初始化
http://localhost/cacti
用户名admin 密码admin
10、测试采集数据
(1)查看RRD文件中数据
[cactier@nagios cacti]# cd /var/www/html/cacti/rra
[cactier@nagios rra]# rrdtool fetch -r 300 localhost_mem_buffers_3.rrd AVERAGE
date +%s
– nan表示没有数据,每隔300秒获取一次数据。
(2)查看mysql中的更新时间
[cactier@nagios rra]# mysql -uroot -p123456
mysql>use cactidb;
mysql>select * from poller_time;
mysql>quit
正常的话是每五分钟更新
(3)采集不到数据怎么办
在网页上清除缓存system utilities –>Rebuild poller cache
修改RRA权限#chmod 777 -R /srv/www/htdocs/cacti/rra
同步系统时间#ntpdate 65.55.56.206
(4)测试snmp抓取数据
[root@nagios ~]# snmpwalk -v 2c -c public <目标机器IP> system
Cacti+Nagios(三):安装Nagios
1、添加用户
[root@nagios ~]# groupadd nagcmd
[root@nagios ~]# useradd -G nagcmd nagios
[root@nagios ~]# usermod -a -G nagcmd apache
2、安装nagios
官方下载地址:http://www.nagios.org/download/
[root@nagios ~]# cd /home/nagios
[root@nagios nagios]# wget http://jaist.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.7/nagios-4.0.7.tar.gz
[root@nagios nagios]# tar xzvf nagios-4.0.7.tar.gz
[root@nagios nagios]# cd nagios-4.0.7
[root@nagios nagios-4.0.7]# ./configure –with-command-group=nagcmd –enable-event-broker
[root@nagios nagios-4.0.7]#make all
[root@nagios nagios-4.0.7]#make install
[root@nagios nagios-4.0.7]#make install-init
[root@nagios nagios-4.0.7]#make install-config
[root@nagios nagios-4.0.7]#make install-commandmode
[root@nagios nagios-4.0.7]#make install-webconf
设置登陆web界面时HTTP验证的账号密码
[root@nagios nagios-4.0.7]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
[root@nagios nagios-4.0.7]#service httpd restart
3、安装nagios-plugins
[root@nagios nagios-4.0.7]#cd /home/nagios
[root@nagios nagios]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.2.tar.gz
[root@nagios nagios]# tar xzvf nagios-plugins-2.0.2.tar.gz
[root@nagios nagios]# cd nagios-plugins-2.0.2
[root@nagios nagios-plugins-2.0.2]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-mysql
[root@nagios nagios-plugins-2.0.2]# make
[root@nagios nagios-plugins-2.0.2]# make install
所有插件命令将被安装到/usr/local/nagios/libexec 目录下
4、其他设置
检查nagios的配置:
[root@nagios ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
添加自动动项:
[root@nagios ~]# chkconfig –add nagios
[root@nagios ~]# chkconfig nagios on
[root@nagios ~]# service nagios start
登陆页面:
http://localhost/nagios
账号nagiosadmin密码123456
5、遇到的问题
点击页面左侧的MAP和History报错:
The requested URL /nagios/sbin/statusmap.cgi was not found on this server.
The requested URL /nagios/sbin/histogram.cgi was not found on this server.
原因一:因为gd-devel php-gd没有安装的问题,造成NAGIOS在编译时不生成这statusmap.cgi
原因二:nagios编译在前, gd-devel安装在后,造成不生成这statusmap.cgi
解决方法:yum安装gd-devel php-gd,再重新编译安装nagios
Cacti+Nagios(四):Cacti整合Nagios
一、原理
整合cacti和nagios是利用了cacti的一个插件nagios for cacti,它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios的结果展示出来。
二、安装cacti扩展模块
cacti扩展模块需要下载安装cacti-plugin,cacti-0.8.8a及以后版本已集成此扩展模块不需要再单独安装,如果使用的是老版本cacti,扩展模块安装如下:
[root@nagios ~]# cd /home/nagios
[root@nagios nagios]# wget http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7h-PA-v3.0.tar.gz
[root@nagios nagios]# tar xvf cacti-plugin-0.8.7h-PA-v3.0.tar.gz
[root@nagios nagios]# cp -R cacti-plugin-arch/* /var/www/html/cacti/
[root@nagios nagios]# cd /var/www/html/cacti/
[root@nagios cacti]# mysql -u cactier -p 123456 cactidb < pa.sql
[root@nagios cacti]# patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff
[root@nagios cacti]# vim include/config.php
$url_path = “/cacti/”;
从web进入cacti,启用cacti plugin扩展
三、安装Ndoutils插件
1、安装Ndoutils
[root@nagios cacti]# cd /home/nagios
[root@nagios nagios]# wget http://jaist.dl.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.0.0/ndoutils-2.0.0.tar.gz
[root@nagios nagios]# tar zxvf ndoutils-2.0.0.tar.gz
[root@nagios nagios]# cd ndoutils-2.0.0
[root@nagios ndoutils-2.0.0]# ./configure –prefix=/usr/local/nagios/ –with-mysql-inc=/usr/include/mysql –with-mysql-lib=/usr/lib64/mysql –enable-mysql –disable-pgsql –with-ndo2db-user=nagios –with-ndo2db-group=nagios
[root@nagios ndoutils-2.0.0]# make
2、准备配置文件
[root@nagios ndoutils-2.0.0]# cd db
[root@nagios db]# ./installdb -u cactier -p 123456 -h localhost -d cactidb
[root@nagios ndoutils-2.0.0]# cd ..
[root@nagios ndoutils-2.0.0]# cp src/{ndomod-4x.o,ndo2db-4x,log2ndo,file2sock} /usr/local/nagios/bin
#nagios是4.x版本的就使用ndomod-4x.o和ndo2db-4x,如果是3.x版本就复制对应的3x文件
[root@nagios ndoutils-2.0.0]# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
[root@nagios ndoutils-2.0.0]# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
[root@nagios ndoutils-2.0.0]# cd /usr/local/nagios/etc/
[root@nagios etc]# chown nagios:nagios ndo2db.cfg ndomod.cfg
[root@nagios etc]# chmod 664 ndo2db.cfg ndomod.cfg
[root@nagios etc]# cd /usr/local/nagios/bin
[root@nagios bin]# mv ndo2db-4x ndo2db
[root@nagios bin]# mv ndomod-4x.o ndomod.o
[root@nagios bin]# chown nagios:nagios *
3、修改配置文件
[root@nagios bin]# vi /usr/local/nagios/etc/nagios.cfg
#注意,broker_module和config_file放在一行
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfgevent_broker_options=-1
process_performance_data=1
[root@nagios bin]# vi /usr/local/nagios/etc/ndo2db.cfg
socket_type=tcp
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cactidb
db_prefix=npc_
db_user=cactier
db_pass=123456
[root@nagios bin]# vi /usr/local/nagios/etc/ndomod.cfg
output_type=tcpsocket
output=127.0.0.1
4、启动守护进程
[root@nagios bin]# /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
[root@nagios bin]# cd /home/nagios/ndoutils-2.0.0
[root@nagios ndoutils-2.0.0]# cp ./daemon-init /etc/init.d/ndo2db
[root@nagios ndoutils-2.0.0]# chmod +x /etc/init.d/ndo2db
[root@nagios ndoutils-2.0.0]# service ndo2db status
[root@nagios ndoutils-2.0.0]# chkconfig –add ndo2db
[root@nagios ndoutils-2.0.0]# chkconfig ndo2db on
四、安装NPC插件
介绍:全称Nagios Plugin for Cacti,将nagios的数据通过ndo2db导入到mysql数据库(前面设置的npc_开头的表),然后cacti读取数据库信息将nagios的结果通过NPC展示出来。
1、安装npc
[root@nagios ndoutils-2.0.0]# cd /home/nagios
[root@nagios nagios]# wget http://down.drv5.cn/www.drv5.cn/npc-2.0.4.tar.gz
[root@nagios nagios]# tar zxvf npc-2.0.4.tar.gz
[root@nagios nagios]# mv npc /var/www/html/cacti/plugins/
[root@nagios nagios]# vi /var/www/html/cacti/include/config.php
$plugins[] = ‘npc’;
2、页面设置npc
(1)user management–>admin–>勾上Plugin Management
(2)Plugin Management–>点击install图标、点击enable图标
(3)settings–>NPC–>照下图设置
3、安装json:支持npc
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。
注意:先执行第4步的php -m查看是否加载了json,有则跳过3、4步,
[root@nagios nagios]# wget http://pkgs.fedoraproject.org/repo/pkgs/php-pecl-json/json-1.2.1.tgz/d8904d2f004ceec85eeacf524cd25539/json-1.2.1.tgz
[root@nagios nagios]# tar zxvf json-1.2.1.tgz
[root@nagios nagios]# cd json-1.2.1
[root@nagios json-1.2.1]# vi JSON_parser.c
#define ZVAL_DELREF Z_DELREF_P
[root@nagios json-1.2.1]# phpize
[root@nagios json-1.2.1]# ./configure
[root@nagios json-1.2.1]# make && make install
4、配置php以支持json
[root@nagios json-1.2.1]# vi /etc/php.d/json.ini
extension=json.so
[root@nagios json-1.2.1]# service httpd restart
查看是否有json被加载:
[root@nagios json-1.2.1]# php -m
查看是否有导入信息:
[root@nagios json-1.2.1]# php -i | grep php.ini
5、修改数据库(缺少个别字段)
[root@nagios json-1.2.1]# tail /var/log/messages
ndo2db: mysql_error: ‘Unknown column ‘long_output‘ in ‘field list”
[root@nagios json-1.2.1]# mysql -ucactier -p123456
mysql>use cactidb;
mysql>ALTER TABLE npc_eventhandlers ADD long_output TEXT NOT NULL DEFAULT ” AFTER output;
mysql>ALTER TABLE npc_hostchecks ADD long_output TEXT NOT NULL DEFAULT ” AFTER output;
mysql>ALTER TABLE npc_hoststatus ADD long_output TEXT NOT NULL DEFAULT ” AFTER output;
mysql>ALTER TABLE npc_notifications ADD long_output TEXT NOT NULL DEFAULT ” AFTER output;
mysql>ALTER TABLE npc_servicechecks ADD long_output TEXT NOT NULL DEFAULT ” AFTER output;
mysql>ALTER TABLE npc_servicestatus ADD long_output TEXT NOT NULL DEFAULT ” AFTER output;
mysql>ALTER TABLE npc_statehistory ADD long_output TEXT NOT NULL DEFAULT ” AFTER output;
mysql>ALTER TABLE npc_systemcommands ADD long_output TEXT NOT NULL DEFAULT ” AFTER output;
mysql>ALTER TABLE npc_services ADD importance smallint(6) NOT NULL DEFAULT ‘0’;
mysql>ALTER TABLE npc_hosts ADD importance smallint(6) NOT NULL DEFAULT ‘0’;
mysql>ALTER TABLE npc_contacts ADD minimum_importance smallint(6) NOT NULL DEFAULT ‘0’;
mysql>quit
6、重启服务
[root@nagios ~]# service mysqld restart
[root@nagios ~]# service httpd restart
[root@nagios ~]# service ndo2db restart
[root@nagios ~]# service nagios restart
7、观察日志
[root@nagios ~]# tail /usr/local/nagios/var/nagios.log
[root@nagios ~]# tail /var/www/html/cacti/log/cacti.log
[root@nagios ~]# tail /var/log/mysqld.log
[root@nagios ~]# tail /var/log/messages
五、遇到的问题
1、NPC页面上显示Nagios为Off
错误:
[root@nagios ~]#tail /usr/local/nagios/var/nagios.log
ndomod: Could not open data sink! I’ll keep trying, but some output may get lost…
解决:
[root@nagios ~]# cd /usr/local/nagios/etc/
[root@nagios etc]# chown nagios:nagios ndo2db.cfg ndomod.cfg
[root@nagios etc]# chmod 664 ndo2db.cfg ndomod.cfg
[root@nagios etc]# service ndo2db restart
[root@nagios etc]# service nagios restart
2、ndo2db服务启动失败
错误:Could not bind socket: Address already in use
解决:
[root@nagios ~]# ps aux|grep ndo2db 看到多个ndo2db的进程
[root@nagios ~]# kill-9 进程id 杀掉进程,再重新运行
[root@nagios ~]# sudo /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
3、消息发送失败
错误:
[root@nagios ~]# tail /var/log/message
ndo2db: Warning: queue send error, retrying… ndo2db: Message sent to queue.
解决:
[root@nagios ~]# vi /etc/sysctl.conf
kernel.msgmax = 131072000
kernel.msgmnb = 131072000
kernel.msgmni = 65536000
Cacti+Nagios(五):Cacti安装插件
Cacti插件说明及下载地址:http://docs.cacti.net/plugins
1、Settings插件
[root@nagios ~]# cd /home/nagios
[root@nagios nagios]# wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz
[root@nagios nagios]# mv plugin:settings-v0.7-1.tgz settings-v0.7-1.tgz
[root@nagios nagios]# tar zxvf settings-v0.7-1.tgz -C /var/www/html/cacti/plugins/
2、Thold插件
Cacti阈值报警插件,对某项数据设定一个范围,超过这个范围就会伐alarm,比如说我监控cpu,设定cpu使用率大于90%或者小于10%就发mail给我。
[root@nagios nagios]# wget http://docs.cacti.net/_media/plugin:thold-v0.5.0.tgz
[root@nagios nagios]# mv plugin:thold-v0.5.0.tgz thold-v0.5.0.tgz
[root@nagios nagios]# tar zxvf thold-v0.5.0.tgz -C /var/www/html/cacti/plugins/
在页面上点击Plugin Management中install和enable启用插件
3、WeatherMap插件
网络拓朴图插件,创建网络设备间连接关系图,展现其性能指标
安装:
[root@nagios nagios]# wget http://www.network-weathermap.com/files/php-weathermap-0.97c.zip
[root@nagios nagios]# unzip php-weathermap-0.97c.zip -d /var/www/html/cacti/plugins/
在页面上点击Plugin Management中install和enable启用插件
配置:
[root@nagios nagios]# chmod -R 777 /var/www/html/cacti/plugins/weathermap
[root@nagios nagios]# cd /var/www/html/cacti/plugins/weathermap
[root@nagios weathermap]# chown apache output -R
[root@nagios weathermap]# chown apache configs -R
[root@nagios weathermap]# vi editor.php
ENABLED=true
创建:
页面左侧weathermap–>add–add添加默认的示例simple.conf
页面顶部weathermap–>下方Editor
4、Discovery插件
设备发现插件,自动扫描指定IP段内的设备
[root@nagios weathermap]# cd /home/nagios
[root@nagios nagios]# wget http://docs.cacti.net/_media/plugin:discovery-v1.5-1.tgz
[root@nagios nagios]# tar zxvf discovery-v1.5-1.tgz -C /var/www/html/cacti/plugins/
页面settings–>设置扫描IP段和DNS
手动搜索:
[root@nagios nagios]# php -q /var/www/html/cacti/plugins/discovery/findhosts.php -f -d
5、Monitor插件
设备在线状态监控插件,在cacti页面host中设置了的主机会在monitor页面显示在线状态,可以和thold插件配置报警.
[root@nagios nagios]# wget http://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz
[root@nagios nagios]# tar zxvf monitor-v1.3-1.tgz -C /var/www/html/cacti/plugins/
6、设置Cacti
网上说要在这添加插件,我直接在页面点击install和enable后就出现了,没有刷出来的可以设置下。
[root@nagios nagios]# vi /var/www/html/cacti/include/config.php
$plugins[] = ‘npc’;
$plugins[] = ‘thold’;
$plugins[] = ‘weathermap’;
$plugins[] = ‘discovery’;
$plugins[] = ‘monitor’;
Cacti+Nagios(六):Cacti整合Ntop
Ntop是一种监控网络流量工具
1、安装依赖软件
[root@nagios ~]# cd /home/nagios
[root@nagios nagios]# yum install libtool libpcap libpcap-devel gdbm gdbm-devel zlib zlib-devel
[root@nagios nagios]# wget http://mirror01.idc.hinet.net/EPEL/5Server/x86_64/GeoIP-1.4.8-1.el5.x86_64.rpm
[root@nagios nagios]# wget http://mirror01.idc.hinet.net/EPEL/5Server/x86_64/GeoIP-devel-1.4.8-1.el5.x86_64.rpm
[root@nagios nagios]# yum -y –nogpgcheck localinstall GeoIP-*.el5.x86_64.rpm
[root@nagios nagios]# yum -y –nogpgcheck localinstall ettercap-*.rpm
2、安装Ntop
[root@nagios nagios]# useradd -M -s /sbin/nologin -r ntop
[root@nagios nagios]# wget http://down1.chinaunix.net/distfiles/ntop-4.1.0.tar.gz
[root@nagios nagios]# tar zxvf ntop-4.1.0.tar.gz
[root@nagios nagios]# cd ntop-4.1.0
[root@nagios ntop-4.1.0]# ./autogen.sh
[root@nagios ntop-4.1.0]# make
[root@nagios ntop-4.1.0]# make install
[root@nagios ntop-4.1.0]# chown -R ntop:ntop /usr/local/share/ntop
[root@nagios ntop-4.1.0]# chown -R ntop:root /usr/local/var/ntop
3、配置Ntop
(1)为ntop的admin用户设置密码
[root@nagios ntop-4.1.0]# ntop -A
admin 123456
(2)启动ntop
[root@nagios ntop-4.1.0]# ntop -i eth0 -d -L -u ntop
eth0是你的监控机用于捕获网络流量的网卡
(3)自动启动
[root@nagios ntop-4.1.0]# echo ‘ntop -i eth0 -d -L -u ntop &> /dev/null’ >> /etc/rc.d/rc.local
(4)防火墙添加信任端口3000
[root@nagios ntop-4.1.0]# iptables -I INPUT -p tcp –dport 3000 -j ACCEPT
[root@nagios ntop-4.1.0]# service iptables save
(5)访问页面
http://localhost:3000
4、Cacti整合Ntop
[root@nagios ntop-4.1.0]# cd /home/nagios
[root@nagios nagios]# wget http://docs.cacti.net/_media/plugin:ntop-v0.2-1.tgz
[root@nagios nagios]# mv plugin:ntop-v0.2-1.tgz ntop-v0.2-1.tgz
[root@nagios nagios]# tar zxvf ntop-v0.2-1.tgz -C /var/www/html/cacti/plugins/
[root@nagios nagios]# vi /var/www/html/cacti/include/config.php
$plugins[] = ‘ntop’;
在Plugin Management”中install和enable插件
在User Management中勾上View Ntop
在Settings、Misc中设置URL:http://localhost:3000
Cacti+Nagios(七):Nagios监控windows(基于check_nt)
1、工作原理
Nagios服务器使用check_nt工具与客户端程序通讯,客户端程序NSCP使用命令来获取本地客户端的信息并返回给check_nt。
check_nt只是NSCP其中一项服务,Nagios还可以通过check命令(如check_http检查WEB服务)、check_nrpe、NSCA、WMI来监控windows客户端。
2、下载客户端程序
下载地址: http://nsclient.org/nscp/downloads
64位系统下载:NSCP-0.4.1.105-x64.msi
32位系统下载:NSCP-0.4.1.105-Win32.msi
3、安装NSCP(也叫NSClient++)
设置Nagios服务器IP地址、客户端访问密码(后面Nagios设置check_nt命令时要用到)和启用各种监控服务。
配置文件C:/Program Files/NSClient++/nsclient.ini中可以修改Allowed hosts和Password。
4、检查服务、端口状态
启动服务后netstat -an查看使用的端口,check_nt使用12489、check_nrpe使用5666
5、测试监控命令
(1)获取帮助信息:
[root@nagios ~]# cd /usr/local/nagios/libexec
[root@nagios libexec]# ./check_nt -h
(2)监控运行时间:
[root@nagios libexec]# ./check_nt -H 10.188.1.172 -v UPTIME -p 12489 -s 123456
System Uptime – 0 day(s) 3 hour(s) 16 minute(s) |uptime=196
-p指定端口,-s指定客户端安装时设置的密码,UPTIME是监控工具。
(3)监控CPU负载 -w警告-c紧急 -l监测参数(过去5分钟平均值,80%警告,90%紧急):
[root@nagios libexec]# ./check_nt -H 10.188.1.172 -v CPULOAD -w 80 -c 90 -l 5,80,90 -p 12489 -s 123456
CPU Load 9% (5 min average) | ‘5 min avg Load’=9%;80;90;0;100
(4)监控C盘使用率(-l C指定盘符):
[root@nagios libexec]# ./check_nt -H 10.188.1.172 -v USEDDISKSPACE -w 80 -c 90 -l C -p 12489 -s 123456
C:/ – total: 35.00 Gb – used: 31.68 Gb (91%) – free 3.32 Gb (9%) | ‘C:/ Used Space’=31.68Gb;28.00;31.50;0.00;35.00
6、配置Nagios监控
(1)修改check_nt命令
[root@nagios libexec]# cd /usr/local/nagios/etc/objects/
[root@nagios objects]# vi command.cfg
# ‘check_nt’ command definition
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s 123456 –v $ARG1$ $ARG2$
}
(2)创建windows监控主机配置文件夹
[root@nagios libexec]# mkdir winserver
(3)创建windows监控主机配置文件
配置文件参考/usr/local/nagios/etc/objects/windows.cfg,可以直接复制过来修改,不过太乱了,自己定义吧:
[root@nagios objects]# cd winserver
[root@nagios winserver]# vi winhost_172.cfg
#定义监控主机,设置主机名(不可重复)、别名、IP地址。
define host{
use windows-server
host_name winhost_172
alias ywzhou_pc
address 10.188.1.172
}
#定义主机组,在winserver文件下只需要一个文件定义了主机组,其他文件就不要再定义了。
define hostgroup{
hostgroup_name windows-servers
alias Windows Servers
}
#第一部分:定义基于check_nt命令的监控服务。
#一个配置文件中的service_description不能重复
#监控NSClient++客户端软件版本
define service{
use generic-service
host_name winhost_172
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
#监控在线时长
define service{
use generic-service
host_name winhost_172
service_description Uptime
check_command check_nt!UPTIME
}
#监控CPU负载,超过80%报警,超过90%严重
define service{
use generic-service
host_name winhost_172
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
#监控内存使用情况,超过80%报警,超过90%严重
define service{
use generic-service
host_name winhost_172
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
#监控C盘使用情况,可以复制该组服务来监控其他磁盘
define service{
use generic-service
host_name winhost_172
service_description C:/ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
#监控系统服务状态(是否启动),默认的W3SVC是IIS的服务,可以复制该组服务来监控其他系统服务
#可以在任务管理器中的服务项查看哪些服务器比较重要就监控起来,比如IIS、SQLServer等。
define service{
use generic-service
host_name winhost_172
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}
#监控程序状态(是否运行),默认的Explorer.exe是桌面进程的程序,可以复制该组服务来监控其他系统服务
#可以在任务管理器中的进程项查看哪些服务器比较重要就监控起来。
define service{
use generic-service
host_name winhost_172
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}
#第二部分:定义基于check plugins的监控服务。
#安装NSCP时启用了Enable common check plugins功能
#check plugins是位于/usr/local/nagios/libexec下的Nagios自带的监控插件
#监控ftp服务
define service{
use generic-service
host_name winhost_172
service_description FTP
check_command check_ftp
}
#监控http服务
define service{
use generic-service
host_name winhost_172
service_description HTTP
check_command check_http
}
#监控ssh服务
define service{
use generic-service
host_name winhost_172
service_description SSH
check_command check_ssh
}
#监控dhcp服务
define service{
use generic-service
host_name winhost_172
service_description DHCP
check_command check_dhcp
}
#监控pop3服务
define service{
use generic-service
host_name winhost_172
service_description POP
check_command check_pop
}
#监控imap服务
define service{
use generic-service
host_name winhost_172
service_description IMAP
check_command check_imap
}
#监控smtp服务
define service{
use generic-service
host_name winhost_172
service_description SMTP
check_command check_smtp
}
#监控tcp端口,常用于监控多个网站使用不同端口时,监控端口状态
define service{
use generic-service
host_name winhost_172
service_description TCP
check_command check_tcp!80
}
下面列出所有插件,其中有很多暂时没空去研究,欢迎共同探讨。
(4)载入监控配置并重启nagios
[root@nagios winserver]# vi /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/objects/winserver
[root@nagios winserver]# service nagios restart
7、Nagios页面操作
(1)查看Hosts主机页面:
(2)查看Down主机,有两台PING不通(关机了)
(3)查看主机hv02的信息,可以设置各种开关
(4)查看主机hv02的所有监控服务
(5)查看所有报警的监控服务
(6)查看所有监控服务,观察正常状态的状态值status information
(7)在Cacti中通过NPC插件查看Nagios信息
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/57971.html