cacti:
监控工具
收集数据,根据数据绘图
cpu load:0.8 1.2
thold
nagios
监控工具
主机,服务/资源
ok,warnging,critical,unknown
cpu:90%{critical},80%(warning),ok
unknown
报警系统
nagios core:
本身不做任何监控工作
都是由插件(plugins)来做监控的
plugins(scripts),check_nginx
N种对象实现监控工作:
主机,主机组
服务/资源,服务组
联系人,联系人组
时段
命令(模板--》应用到某个被监控对象,以实现具体的监控)
N主机
Linux
多个被监控对象,如果有很多属相同的时候
template
插件:check_by_ssh,check_nrpe,snmp,NSCA
安装nagios:
yum install httpd php mysql-devel php-mysql
groupadd nagcmd
useradd -G nagcmd nagios
usermod -a -G nagcmd apache
tar -zxvf nagios-3.3.1.tar.gz
cd nagios
./configure --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
service httpd start
安装插件
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
service nagios start
http://172.16.100.1/nagios/
cd /etc/nagios
cd objects
vim nagios.cfg
vim resource.cfg
cd /usr/local/nagios/libexec/
vim command.cfg
vim contact.cfg
vim timeperiods.cfg
vim localhost.cfg:其中有!后面跟一些字符,表示是一个参数,向command.cfg中的命令传递(传到$ARER$,这样的字符)
宏:变量:$USER1$
resource.cfg用来定义宏文件
基于NSClinet++远程监控windows主机(172.16.100.66)
首先在windows上面安装NSClinet++,然后填写监控主机的ip地址(172.16.100.1),密码不要写,其中modules to load中全部勾选,监听端口为12489,5666
在172.16.100.1上面:cd
在命令行执行监控
/usr/local/nagios/libexec/
./check_nt -H 172.16.100.66 -p 12489 -v UPTIME
./check_nt -H 172.16.100.66 -p 12489 -v CPULOAD -w 80 -c 90 -l 5,80,90
./check_nt -H 172.16.100.66 -p 12489 -v USEDDISKSAPCE -w 80 -c 90 -l 90 C
在配置文件中配置
cd objects
定义命令:vim commands.cfg
define command {
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
}
定义主机:vim windows.cfg
define host {
use windows-server
host_name winhost
alias my windows host
address 172.168.100.66
}
define service{
use generic-service
host_name winhost
service_description Uptime
check_command check_nt!UPTIME
}
define service{
use generic-service
host_name winhost
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
所有的host_name都要改成winhost
定义启用上述的配置文件:vim nagios.cfg
cfg_file=/etc/nagios/objects/windows.cfg
/usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg
service nagios restart
基于nrpe监控远程Linux主机:
安装配置被监控端(172.16.100.11):
yum -y groupinstall "Development Tools" "Development Libraries"
tar -zxvf nagios-plugins-1.4.15.tar.gz
useradd -s /sbin/nologin nagios
cd nagios-plugins
./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 --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
make all
make install-plugin
make install-daemon
make install-daemon-config
vim /usr/local/nagios/nrpe.cfg
allowed_hosts=172.16.100.1
command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2
启动脚本:vim /etc/init.d/nrped
#! /bin/bash
chkconfig: 2345 88 12
description: NRPE DAEMON
NRPE=/usr/nagios/bin/nrpe
NRPECONF=/usr/local/nagios/etc/nrpe.cfg
case "$1" in
start)
echo -n "starting NRPE daemon"
$NRPE -c $NRPECONF -d
echo "done"
;;
stop)
echo -n "stopping NRPE daemon"
pkill -u nagios nrpe
echo "done"
;;
restart)
$0 stop
sleep 2
$0 start
*)
echo "usage:$0 start|stop|restart"
;;
esac
exit 0
service nrped start
在监控端(172.16.100.1):
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
make all
make install-plugin
cd /sur/local/nagios/libexec
./check_nrpe -H 172.16.100.11
cd /etc/nagios/objects
vim command.cfg
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
vim linhost.cfg
define host{
use linux-server
host_name linhost
alias my linux host
address 172.16.100.11
}
define service{
use generic-service
host_name linhost
service_description CHECK USERS
check_command check_nrpe!check_users(这里填的是被监控端所命的名)
}
define service{
use generic-service
host_name linhost
service_description LOAD
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name linhost
service_description SDA1
check_command check_nrpe!check_sda1
}
define service{
use generic-service
host_name linhost
service_description SDA2
check_command check_nrpe!check_sda2
}
define service{
use generic-service
host_name linhost
service_description ZOMBIE PROCS
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name linhost
service_description TOTAL PROCS
check_command check_nrpe!check_total_procs
}
vim nagios.cfg
cfg_file=/etc/nagios/objects/linhost.cfg
service nagios restart
基于nrpe实现监控windows被监控端:
在安装NSClien++目录中找到NSC,并用记事本或者写字板打开
在cmd中启动服务:
先切换到NSClien++目录下执行nsclient++.exe /start
在监控端:
./check_nrpe -H 172.16.100.66 -c checkCPU -a warn=80 crit=90 time=20 time=10 time=5
监控windows端http服务状态
cd /usr/local/nagios/libexec
./check_http -H 172.16.100.66
cd /etc/nagios
cd objects
vim command.cfg
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $RAG1$
define cmmand{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p$ARG2$
vim windows.cfg
define service{
use generic-service
host_name winhost
service_description web server
check_cmmand check_http
}
define service{
use generic-service
host_name winhost
service_description mysql server
check_cmmand check_http!root!magedu
}
service nagios restart
Fetion:飞信用来接收报警信息的
在飞信机器人网站中下载
mv linuxso_20101113 /usr/local/fetion
vim /etc/ld.so.conf.d/fetion.conf
/usr/local/fetion
ldconfig
vim /etc/ld.so.conf.d/fetion.conf:此目录下是定义要加载的各种模块
使用ldconfig 立即生效
使用飞信发信息
/usr/local/fention/fetion --mobile=18827018530 --pwd=chenjiao --to=13607693077 --msg-utif8=“fetion test message”
将飞信整合到nagios中的联系人中
vim command.cfg
define command {
command_name notify-host-by-fetion
command_line fetion --mobile=18827018530 --pwd=chenjiao --msg-utif8=“$NOTIFICATIONTYPE$ Host:$HOSTNAME$ State:$HOSTSTATE$ Address:$HOSTADDRESS$ ” --to=$CONTACTPAGER$
define command {
command_name notify-service-by-fetion
command_line fetion --mobile=18827018530 --pwd=chenjiao --msg-utif8=“$NOTIFICATIONTYPE$ Host:$HOSTNAME$ State:$HOSTSTATE$ Address:$HOSTADDRESS$ ” --to=$CONTACTPAGER$
vim contact.cfg
define contact{
contact_name nagiosadmin
use generic-contact
alias nagios admin
email mage@localhost
pager 13080610944
}
vim templates.cfg
define contact{
name generic-contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options
service_notification_commands notify-service-by-fetion,notify-service-by-email
host-notification-commands notify-host-by-fetion,notify-host-by-email
register 0
}
service nagios restart