nagios部署+短信和邮件报警
操作系统 CentOS6.6
服务端:10.0.0.20
客户端:10.0.0.50
一.nagios的服务端安装部署
1.nagios安装
[root@manager src]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring nagios-cn-3.2.3.tar.bz2...
100% 9412 KB 9412 KB/sec 00:00:01 0 Errors
tar xf nagios-cn-3.2..tar.bz2
cd nagios-cn-3.2.3
useradd -m -s /bin/bash nagios
groupadd nagcmd
make install; make install-init;make install-commandmode;make install-config;make install-webconf
ll /usr/local/nagios/ #出现以下文件代表成功
drwxrwxr-x 2 nagios nagios 4096 Mar 12 08:08 bin
drwxrwxr-x 3 nagios nagios 4096 Mar 12 08:08 etc
drwxrwxr-x 2 nagios nagios 4096 Mar 12 08:08 libexec
drwxrwxr-x 2 nagios nagios 4096 Mar 12 08:08 sbin
drwxrwxr-x 9 nagios nagios 4096 Mar 12 08:08 share
drwxrwxr-x 6 nagios nagios 4096 Mar 12 08:08 var
chmod o+rwx /usr/local/nagios/var/rw
2.nagios plugin 插件安装
[root@manager src]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring nagios-plugins-1.4..tar.gz...
% KB KB/sec :: Errors
[root@manager src]# tar xf nagios-plugins-1.4..tar.gz
[root@manager src]# cd nagios-plugins-1.4.13
#安装依赖
yum install make apr* autoconf automake curl curl-devel gcc gcc-c++ zlib-devel \
openssl openssl-devel pcre-devel gd gd-devel kernel keyutils patch perl perl-devel \
kernel keyutils kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl \
cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel \
krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch -y
./configure --prefix=/usr/local/nagios --with-mysql=/usr/local/mysql/
make
make install
file /usr/lib64/libxcb-reply.so.1.0.0 from install of compat-xcb-util-0.4.0-2.2.el6.x86_64 conflicts with file from package xcb-util-0.3.6-5.el6.x86_64
有冲突卸载掉这个有冲突的
yum remove -y xcb-util-0.3.-.el6.x86_64
3.nrpe安装
[root@manager src]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring nrpe-2.12.tar.gz...
% KB KB/sec :: Errors
tar xf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
\cp src/check_nrpe /usr/local/nagios/libexec/
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d' >> /etc/rc.local
要重启nrpe进行就先杀掉进行,然后重启
kill `ps aux |grep nrpe |grep -v grep |awk '{print $2}'`
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
本机测试下:
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
加入系统服务
加入系统服务并设为开机自动
chkconfig --add nagios
chkconfig nagios on
chown nagios.nagios /usr/local/nagios/var/rw
# 测试配置文件是否正确
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
添加别名命令,方便测试配置文件
vi ~/.bashrc
在里面用alias 来自定义一个命令来代替,这里我用check
alias check='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'
source ~/.bashrc
此时可以用check命令来检测配置文件了
安装 nginx 的FCGI模块
cd /usr/local/src/
rz
tar xf FCGI-0.74.tar.gz
cd FCGI-0.74
perl Makefile.PL
make && make install
安装IO 和IO-ALL模块
[root@manager src]# tar xf IO-1.25.tar.gz
[root@manager src]# cd IO-1.25
[root@manager IO-1.25]# perl Makefile.PL
[root@manager IO-1.25]# make && make install
[root@manager src]# tar xf IO-All-0.81.tar.gz
[root@manager src]# cd IO-All-0.81
[root@manager IO-All-0.81]# perl Makefile.PL
[root@manager IO-All-0.81]# make && make install
上传fastcgi 的启动脚本。
[root@manager src]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring perl-fcgi.zip...
100% 2 KB 2 KB/sec 00:00:01 0 Errors
[root@manager src]# unzip perl-fcgi.zip
Archive: perl-fcgi.zip
inflating: perl-fcgi.pl
[root@manager src]# cp perl-fcgi.pl /usr/local/nginx/
[root@manager IO-All-0.81]# chmod 755 /usr/local/nginx/perl-fcgi.pl
[root@manager nginx]# ./start_perl_cgi.sh start
start perl-fcgi done
[root@manager ~]# cat /usr/local/nginx/start_perl_cgi.sh
#!/bin/bash
#set -x
dir=/usr/local/nginx/
stop ()
{
#pkill -f $dir/perl-fcgi.pl
kill $(cat $dir/logs/perl-fcgi.pid)
rm $dir/logs/perl-fcgi.pid >/dev/null
rm $dir/logs/perl-fcgi.sock >/dev/null
echo "stop perl-fcgi done"
}
start ()
{
rm $dir/now_start_perl_fcgi.sh >/dev/null
chown nobody.root $dir/logs
echo "$dir/perl-fcgi.pl -l $dir/logs/perl-fcgi.log -pid $dir/logs/perl-fcgi.pid -S $dir/logs/perl-fcgi.sock" >>$dir/now_start_perl_fcgi.sh
chown nobody.nobody $dir/now_start_perl_fcgi.sh
chmod u+x $dir/now_start_perl_fcgi.sh
sudo -u nobody $dir/now_start_perl_fcgi.sh
echo "start perl-fcgi done"
}
case $ in
stop)
stop
;;
start)
start
;;
restart)
stop
start
;;
esac 启动fastcgi
[root@manager nginx]# ./start_perl_cgi.sh start
start perl-fcgi done
# 重复启动会报这样的错 使用行参restart 或者stop 以后再start 就不会报这样的错。
[root@manager nginx]# ./start_perl_cgi.sh start
ERROR PID file /usr/local/nginx/logs/perl-fcgi.pid already exists
start perl-fcgi done
把start_perl_cgi.sh文件中的nobody全部用nagios替换,nginx 目录上的用户
[root@manager ~]# sed -i 's#nobody#nagios#g' /usr/local/nginx/start_perl_cgi.sh
[root@manager ~]# ps -ef |grep nagios
nagios : ? :: /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
nagios : ? :: /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
# 取消用户认证(方便调试)
vi /usr/local/nagios/etc/cgi.cfg
找到use_authentication=1并把值改为0
#修改联系人邮箱,修改为用于报警接收的邮件地址
vi /usr/local/nagios/etc/objects/contacts.cfg email 13311802282@163.com (默认是nagios@localhost换成自己的邮箱)
产生这样一个socket文件表示启动成功了
[root@manager nginx]# /etc/init.d/nagios start
Starting nagios: done.
二,nagios的被监控端安装部署
1.安装nagios插件
[root@master ~]# groupadd nagios
[root@master ~]# useradd nagios -M -s /sbin/nologin -g nagios
[root@master ~]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring nagios-plugins-1.4..tar.gz...
% KB KB/sec :: Errors
[root@master nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql=/usr/local/mysql && make && make install
2.安装nrpe
[root@master nagios-plugins-1.4.]# cd
[root@master ~]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring nrpe-2.12.tar.gz...
% KB KB/sec :: Errors
[root@master nrpe-2.12]# ./configure && make all && make install-plugin && make install-daemon && make install-daemon-config
[root@master nrpe-2.12]# echo $? (0未报错)
0
[root@master nrpe-2.12]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@master nrpe-2.12]# ps -ef |grep nrp
nagios 23592 1 0 09:28 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# 设置开机启动进程
[root@master nrpe-2.12]# echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d' >> /etc/rc.local
监控服务端本机:自己监控自己不需要配置nrpe,服务端的nrpe只用于获取客户端的nrpe传送过来的数据,在这里因为中文版的nagios已经默认有些配置,等会儿修改下直接用了
监控客户端:监控的服务有:mysql、nginx、memory、ip连接数、僵死的进程、磁盘空间、磁盘IO、登录用户数、进程总数、cpu负载、PING、SSH
有两个红色的不知道啥吊情况。
3.操作数据库mysql
mysql> create database nagios;
Query OK, 1 row affected (0.07 sec) mysql> grant select on nagios.* to nagios@'%' identified by '';
Query OK, 0 rows affected (0.05 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> select user,password,host from mysql.user;
+--------+-------------------------------------------+-----------+
| user | password | host |
+--------+-------------------------------------------+-----------+
| root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | localhost |
| root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | master |
| root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | 127.0.0.1 |
| root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | ::1 |
| | | localhost |
| | | master |
| repl | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | 10.0.0.% |
| root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | 10.0.0.% |
| nagios | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | % |
+--------+-------------------------------------------+-----------+
9 rows in set (0.03 sec)
# 添加mysql库到系统搜索库
vim /etc/ld.so.conf
/usr/local/mysql/lib
ldconfig
# 要监控磁盘io,还得安装sysstat这个工具包
yum install sysstat -y
# 配置客户端上面的nrpe
vim /usr/local/nagios/etc/nrpe.cfg allowed_hosts=127.0.0.1,10.0.0.20; #允许server主机获取信息
command[check_users]=/usr/local/nagios/libexec/check_users -w -c
command[check_load]=/usr/local/nagios/libexec/check_load -w ,, -c ,,
#command[check_hda1]=/usr/local/nagios/libexec/check_disk -w % -c % -p /dev/hda1 (由于我的磁盘时scsii的硬盘所以不是hd是sd)
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w -c -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w -c #----------------------------------下面是后加的----------------------------------------------------
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w % -c % -p /dev/sda1
command[check_sda2]=/usr/local/nagios/libexec/check_disk -w % -c % -p /dev/sda2
command[check_swap]=/usr/local/nagios/libexec/check_swap -w % -c %
command[check_iostat]=/usr/local/nagios/libexec/check_iostat.sh -d sda -w -c
command[check_mysql]=/usr/local/nagios/libexec/check_mysql -H 192.168.0.22 -u nagios -p -d nagios
command[check_nginx]=/usr/local/nagios/libexec/check_nginx.sh -u 192.168.0.22 -p /status -w -c
command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -f -w -c
command[check_ip_conn]=/usr/local/nagios/libexec/ip_conn.sh
command[check_ssh]=/usr/local/nagios/libexec/check_tcp -p -w 1.0 -c 10.0
配置完重新启动进程
[root@master ~]# kill `ps aux |grep nrpe |grep -v grep |awk '{print $2}'`
[root@master ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@master ~]# ps -ef |grep nrpe
nagios : ? :: /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
root : pts/ :: grep nrpe
服务端配置:
[root@manager ~]# cp /usr/local/nagios/etc/objects/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg.bak
[root@manager ~]# > /usr/local/nagios/etc/objects/localhost.cfg
[root@manager ~]# vim /usr/local/nagios/etc/objects/localhost.cfg
#这是自己监控自己的配置文件
define host{
use linux-server
host_name localhost
alias localhost
address 127.0.0.1
icon_image server.gif
statusmap_image server.gd2
2d_coords ,
3d_coords ,,
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members * ; Comma separated list of hosts that belong to this group
}
define servicegroup{
servicegroup_name 全部联通性检查
alias 联通性检查
members localhost,PING,nagios-client,PING
}
define service{
use local-service ; Name of service template to use
host_name *
service_description PING
check_command check_ping!100.0,%!500.0,%
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description 根分区
check_command check_local_disk!%!%!/
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description 登录用户数
check_command check_local_users!!
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description 进程总数
check_command check_local_procs!!!RSZDT
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description 系统负荷
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description 交换空间利用率
check_command check_local_swap!!
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_tcp!!1.0!10.0
notifications_enabled
}
服务器端监控被监控主机的配置文件:
cp /usr/local/nagios/etc/objects/localhost.cfg /usr/local/nagios/etc/objects/nagios-client.cfg
vim /usr/local/nagios/etc/objects/nagios-client.cfg 修改完成后的配置如下
define host{
use linux-server
host_name nagios-client
alias nagios-client
address 10.0.0.50
icon_image server.gif
statusmap_image server.gd2
2d_coords ,
3d_coords ,,
}
define service{
use local-service ; Name of service template to use
host_name *
service_description PING
check_command check_ping!100.0,%!500.0,%
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description boot分区
check_command check_nrpe!check_sda1
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description 根分区
check_command check_nrpe!check_sda2
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description 登录用户数
check_command check_nrpe!check_users
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description 进总程数
check_command check_nrpe!check_total_procs
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description CPU平均负载
check_command check_nrpe!check_load
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description 虚拟内存
check_command check_nrpe!check_swap
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description SSH
check_command check_nrpe!check_ssh
notifications_enabled
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description 僵死进程数
check_command check_nrpe!check_zombie_procs
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description iostat
check_command check_nrpe!check_iostat
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description mysql
check_command check_nrpe!check_mysql
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description nginx
check_command check_nrpe!check_nginx
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description memory
check_command check_nrpe!check_mem
}
define service{
use local-service ; Name of service template to use
host_name nagios-client
service_description IP连接数
check_command check_nrpe!check_ip_conn
}
出现问题会自动发送邮件到你设置的邮箱
这个部署的不太成功!网页没有显示。。。。明天重新再来一遍,再好好理解理解,这些安装包都特么好难找,这下我应该算是收集全了,在部署应该很快。
nagios部署+短信和邮件报警的更多相关文章
- zabbix实现电话、短信、邮件报警
该报警方式提前说明:(1)该方式可以实现zabbix免费电话报警以及微信.短信.邮件报警,但有数量限制.详见如下:如数量不能满足需要以及人员需要,可以考虑购买收费版.(2)毕竟是免费版,电话通知要省着 ...
- CentOS 6.2+Nginx+Nagios,手机短信和qq邮箱提醒
http://chenhao6.blog.51cto.com/6228054/1323192 标签:软件包 配置文件 nagios 服务端 监控 原创作品,允许转载,转载时请务必以超链接形式标明文章 ...
- MVC使用ASP.NET Identity 2.0实现用户身份安全相关功能,比如通过短信或邮件发送安全码,账户锁定等
本文体验在MVC中使用ASP.NET Identity 2.0,体验与用户身份安全有关的功能: →install-package Microsoft.AspNet.Identity.Samples - ...
- ios 设置亮度、声音;调用发短信、邮件、打电话
一,设置亮度 [[UIScreen mainScreen] setBrightness:0.5];//0.0~1.0 二,设置声音 1,添加 MediaPlayer.framework 框架 2,在需 ...
- IOS中调用系统的电话、短信、邮件、浏览功能
iOS开发系列--通讯录.蓝牙.内购.GameCenter.iCloud.Passbook系统服务开发汇总 2015-01-13 09:16 by KenshinCui, 26990 阅读, 35 评 ...
- ios开发——实用技术篇Swift篇&地址薄、短信、邮件
//返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(tru ...
- Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)
结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...
- app后端设计(3)--短信,邮件,推送服务(2014.12.05更新)
在app的后端设计中,免不了消息的推送,短信,邮件等服务,下面就个人的开发经验谈谈这方面. (1)最重要的是,各种推送一定要放在队列系统中处理,不然会严重影响api的响应时间. (2)短信方面 以前我 ...
- react-native-communications 电话、短信、邮件、浏览器
第一种方法:Linking:调用系统的电话.短信.邮件.浏览器等功能 Linking.canOpenURL(this.props.url).then(supported => { if (!su ...
随机推荐
- CSS3裁剪与遮罩解析
一.用途 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分而显示另一部分 二.区别 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分 ...
- java 1.7 新io 实践 NIO2
Files 类使用 package com.xinyu.test; import java.io.IOException; import java.nio.ByteBuffer; import jav ...
- 【Java集合源码剖析】Java集合框架
Java集合工具包位于Java.util包下,包含了很多常用的数据结构,如数组.链表.栈.队列.集合.哈希表等.学习Java集合框架下大致可以分为如下五个部分:List列表.Set集合.Map映射.迭 ...
- CC3200模块的内存地址划分和bootloader,启动流程(二)
1. 首先启动内部ROM固化的BOOT,然后这个ROM启动需要使用内存空间0X2000 0000 --- 0X2000 4000共16K的空间.一级BOOT的作用是串口升级和驱动库. 2. 然后是二级 ...
- Android学习记录(3)—Android中ContentProvider的基本原理学习总结
一.ContentProvider简介 当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就可以向其他应用共享其数据.虽然使用其他方法也可以对外共享数据 ...
- iOS 中 AFNetworking HTTPS 的使用
由于我们公司由HTTP转HTTPS,出现了一系列问题特此记录下. 一.HTTPS 二.App Transport Security 三.iOS 中用HTTPS 注意的问题 四.使用 AFNetwork ...
- 《Cracking the Coding Interview》——第6章:智力题——题目2
2014-03-19 06:57 题目:对于8x8的棋盘,如果拿掉对角位置的两个小块儿,能否用1x2的多米诺牌拼成剩下的棋盘? 解法:不可能.且不说8x8,NxN都是不可能的.如果N是奇数,NxN-2 ...
- 《Cracking the Coding Interview》——第4章:树和图——题目2
2014-03-19 03:32 题目:给定一个有向图,判断其中两点是否联通. 解法:DFS搜索解决,如果是无向图的话,就可以用并查集高效解决问题了. 代码: // 4.2 Write a progr ...
- python学习笔记一:数据类型
一.Python文件类型 1.源代码 hello.py: 1 #!/usr/bin/python 2 print "hello world" 2.字节代码:python源文件经编译 ...
- 新兵易学,老兵易用----C++(C++11的学习整理---如何减少代码量,加强代码的可读性)
1.auto类型推导 auto推导最大的优势就是在拥有初始化表达式的复杂类型变量声明时简化代码. auto第二个优势就是免去了程序员在一些类型声明时的麻烦,或者避免一些在类型声明时的错误. auto第 ...