- 浏览: 2509690 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (676)
- linux运维 (157)
- php (65)
- mysql (78)
- nginx (27)
- apche (18)
- framework (6)
- windows (9)
- IDE工具 (23)
- struts2 (7)
- java (13)
- 移动互联网 (14)
- memcache redis (23)
- shell基础/命令/语法 (37)
- shell (50)
- puppet (4)
- C (11)
- python (9)
- 产品经理 (27)
- Sphinx (4)
- svn (12)
- 设计构建 (12)
- 项目管理 (44)
- SEO (1)
- 网站架构 (26)
- 审时度势 (42)
- 网络 (14)
- 激发事业[书&视频] (81)
- 其它 (12)
- 摄影 (8)
- android (21)
最新评论
-
zhongmin2012:
原文的书在哪里
数据库水平切分的实现原理解析---分库,分表,主从,集群,负载均衡器 -
renzhengzhi:
你好,请问个问题,从master同步数据到slave的时候,s ...
数据库水平切分的实现原理解析---分库,分表,主从,集群,负载均衡器 -
ibc789:
你好,看了你的文章,我想请教个问题, 我在用 redis的时候 ...
redis 的两种持久化方式及原理 -
iijjll:
写得非常好
数据库水平切分的实现原理解析---分库,分表,主从,集群,负载均衡器 -
iijjll:
写得非常好
数据库水平切分的实现原理解析---分库,分表,主从,集群,负载均衡器
自定义ip_conn.sh :http://zhumeng8337797.blog.163.com/blog/static/100768914201171664928247/
用php自定义 nagios监控插件
http://blog.csdn.net/sudoers/article/details/6913368
Writing a Nagios plugin with PHP
http://benedmunds.com/2012/04/25/writing-a-nagios-plugin-with-php/
/etc/init.d/nagios stop
/etc/init.d/nagios start
============== 1
增加nginx和php的监控
-----------1.1 主
基本配置 /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg 图3定义commands
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg 联系人 图4
cfg_file=/usr/local/nagios/etc/objects/templates.cfg 模板 图5
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg localhost.cfg中有类似的主机组设置
cfg_file=/usr/local/nagios/etc/objects/services.cfg
#vim /usr/local/nagios/etc/objects/commands.cfg
#check_php_test
define command{
command_name check_php_test
command_line
$USER1$/check_php_test.sh -H $HOSTADDRESS$ -c $ARG1$ -t 30
#
-t 30 # 加上一个 -t 30 指定限定时间为 30 秒
}
#vim /usr/local/nagios/etc/objects/services.cfg
define service{
use generic-service
host_name R620_web67,R620_web68
service_description check_php_test
contact_groups admins-ts
check_command
check_nrpe!check_php_test
notifications_enabled 1
normal_check_interval 3
retry_check_interval 2
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
}
編輯完主Nagios後可以用這一行检查配置
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
检查配置:
#/etc/init.d/nagios checkconfig
reload服务:
#/etc/init.d/nagios reload
-----------1.2 从:
客户机基本配置/usr/local/nrpe/etc/nrpe.cfg
或者 /usr/local/nagios/etc/nrpe.cfg
#vim /var/www/t.php
1
#vim /usr/local/nagios/libexec/check_php_test.sh
#!/bin/bash
#!/bin/bash
r=`/usr/bin/curl -s http://localhost/t.php`
if [ $r ] ;then
if [ $r == "1" ] ;then
echo "ok"
exit 0
else
echo "Please confirm the content of the file(t.php)!"
exit 1
fi
fi
echo "Service exception,May be the file(t.php) does not exist!"
exit 2
----------------------------------------- nagios检测并重启服务完整脚本 check_php_test.sh
#!/bin/bash
#nagios默认state
nagstate=0
#nagios默认描述
nagrs="ok"
#检测服务
function checkService () {
r=`/usr/bin/curl -s http://localhost/t.php`
echo "curl content:$r"
if [ $r ] ;then
if [ $r -eq 1 ] ;then
nagstate=0
nagrs="OK"
return 1
else
nagstate=1
nagrs="Please confirm the content of the file(t.php)!"
return 1
fi
fi
nagstate=2
nagrs="Service exception,attempts to restart services,please pay attention to the following message!"
return 1
}
#重新拉起ngin, php服务
function restartService () {
#pid /dev/shm/pid/nginx.pid;
nginxPath="/usr/local/nginx/conf/nginx.conf"
#pid = /dev/shm/pid/php-fpm.pid
phpPath="/usr/local/php/etc/php-fpm.conf"
`sudo chmod +x $nginxPath`
`sudo chmod +x $phpPath`
nginxPid=`cat $nginxPath | grep "pid" | tr -d ";" |awk 'BEGIN {FS=" "}{print $2}' | awk '{gsub(/ /,"")}1'`
phpPid=`cat $phpPath | grep "pid" | awk 'BEGIN {FS="="}{print $2}' | awk '{gsub(/ /,"")}1'`
if [ -f $nginxPid ] ;then
echo "restart nginx"
sudo /bin/kill -HUP `sudo cat $nginxPid`
else
echo "start nginx"
`sudo chmod +x /usr/local/nginx/sbin/nginx`
`sudo /usr/local/nginx/sbin/nginx`
fi
if [ -f $phpPid ] ;then
echo "retart php"
sudo /bin/kill -USR2 `sudo cat $phpPid`
else
echo "starg php-fpm"
`sudo chmod +x /usr/local/php/sbin/php-fpm`
`sudo /usr/local/php/sbin/php-fpm`
fi
return 1
}
#创建t.php文件
function toucthTphp () {
wwwTphp="/var/www/ssc/www/t.php"
htmlTphp="/var/www/html/t.php"
[ -d "/var/www/ssc/www" ] && `sudo chmod -R 777 /var/www/ssc/www/`;echo 1 > $wwwTphp
[ -d "/var/www/html" ] && `sudo chmod -R 777 /var/www/html/`;echo 1 > $htmlTphp
return 1
}
### 主程序###
function main () {
toucthTphp
checkService
[ $nagstate -ne 0 ] && restartService
checkService
return 1
}
main
echo $nagrs
exit $nagstate
------------------------ nagios的sudo需要手动输入密码问题
su - nagios
sudo /etc/init.d/sshd restart
需要输入密码
修改:
su -
#visudo
(或者sudo vi /etc/sudoers
)
#添加nagios 请求sudo,允许特定指令时(可跟参数),不需要密码
。
nagios ALL=(ALL) NOPASSWD: /etc/init.d/sshd restart
#找到 #Defaults requiretty 并取消注释,另外新增一行。表示nagios用户不需要登陆终端就可以调用命令 。
Defaults requiretty
Defaults:nagios !requiretty
su - nagios
sudo /etc/init.d/sshd restart
就不需要输入密码了
---------------------------------------END 检测并重启服务脚本
nrpe.cfg定义command:
check_php_test (如果缺少此步骤,在服务器端执行会提示NRPE: Command 'check_php_test' not defined)
#vim /usr/local/nagios/etc/nrpe.cfg
command[check_php_test]=/usr/local/nagios/libexec/check_php_test.sh
重启nrpe:
#/etc/init.d/xinetd restart
报错:NRPE: Unable to read output (页面上nagios的文字描述就是通过echo获取到的)
客户端脚本要有输出内容
echo "ok"
exit 0
****修改sh文件不需要重启任何服务
-----------1.3 主:
配置邮件联系人
#vim /usr/local/nagios/etc/objects/contacts.cfg
define contactgroup
{
contactgroup_name admins-ts
alias Nagios Administrators
members it-ts
}
define contact
{
contact_name it-ts
; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined abov
e)
alias sy.zed ; Full name of user
email idc.it@test.com ;#最终的邮件组
pager 1
}
host_name设置
#vim /usr/local/nagios/etc/objects/localhost.cfg
define host {
host_name R620_web67
alias Linux R620_web67
address 192.168.102.67
contact_groups admins-ts
check_command check-host-alive
notifications_enabled 1
process_perf_data 1
max_check_attempts 5
notification_interval 10
notification_period 24x7
notification_options d,u,r
action_url /nagios/pnp/index.php?host=$HOSTNAME$
parents TW_TS
}
-----------
1.4验证
在监控机上运行check_nrpe -H IP
可以查看到客户端的nrpe信息,说明监控机与被监控机的nrpedaemon通信是正常。
在服务器端:验证
/usr/local/nagios/libexec/check_nrpe -H 192.168.102.67 -c check_php_test
nagios页面查看 :
Hostgroup Overview -> R620_web67 -> check-php-test
----------其他:php方式简述
#check_php_test
define command{
command_name check_php_test
command_line
php
$USER1$/check_php_test.php
-H $HOSTADDRESS$ -c $ARG1$ -t 60
}
#vim /usr/local/nagios/libexec/check_php_test.php
<?php
error_reporting(0);
#fwrite(STDOUT, 'This check passed');
try{
$r = url_get_contents("http://localhost/t.php");
if ( false === $r || '1' != $r) {
exit(2);
}
} catch(Exception $e) {
exit(3);
}
exit(0);
function url_get_contents($strUrl, $boolUseCookie=false)
{
$ch = curl_init($strUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_REFERER']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
if ($boolUseCookie && is_array($_COOKIE) && count($_COOKIE) > 0) {
$cookie_str = '';
foreach($_COOKIE as $key => $value) {
$cookie_str .= "$key=$value; ";
}
curl_setopt($ch, CURLOPT_COOKIE, $cookie_str);
}
$response = curl_exec($ch);
if (curl_errno($ch) != 0) {
return false;
}
curl_close($ch);
return $response;
}
==============2 ip_conn.sh
客户端/usr/local/nrpe/etc/nrpe.cfg
或者 /usr/local/nagios/etc/nrpe.cfg
command[check_ips]=/usr/local/nrpe/libexec/ip_conn.sh 8000 10000
vim /usr/local/nrpe/libexec/ip_conn.sh
#!/bin/sh
#if [ $# -ne 2 ]
# echo "Usage:$0 -w num1 -c num2"
#exit 3
#fi
ip_conns=`nestat -an | grep tcp |grep EST |wc -l`
if [ $ip_conns -lt $1 ]
then
echo "OK -connect counts is $ip_conns"
exit 0
fi
if [ $ip_conns -gt $1 -a $ip_conns -lt $2 ]
then
echo "Warning -connect counts is $ip_conns"
exit 1
fi
if [ $ip_conns -gt $2 ]
then
echo "Critical -connect counts is $ip_conns"
exit 2
fi
#指定2个连接数,当连接数大于指定的第一个数的时候,给予warning警报,当连接数大于指定的第二个数的时候,给予Critical警报。
各客户端测试nrpe服务中各个插件的功能
[root@nagios-server libexec]# /usr/local/nrpe/libexec/ip_conn.sh 8000 10000
/usr/local/nrpe/libexec/ip_conn.sh: line 6: nestat: command not found
OK -connect counts is 0
服务端测试check_nrpe功能
[root@nagios-server libexec]# ./check_nrpe -H nagios-server -c check_ips
OK -connect counts is 0
各机器以独立守护进程启动nrpe服务
/usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
服务器端启动nagios监控服务
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
启动apache服务器
/usr/local/apache/bin/apachectl -k start
发表评论
-
设置sudo为不需要密码
2015-04-17 09:04 10456有时候我们只需要执 ... -
haproxy 安装配置和负载实例
2015-03-27 11:49 11487一、环境说明实验环境 OS CentOS5.4 192.1 ... -
/dev/mapper/VolGroup00-LogVol00 100% 如何处理
2015-03-03 10:51 8094服务器磁盘跑满了, 命令查看 如下 [root@lo ... -
Tsar开源:淘宝内部大量使用的系统监控工具
2014-08-07 09:51 919Tsar是淘宝的一个用来收集服务器系统和应用信息的采集报告 ... -
Linux运维常用命令 (转载)
2013-01-31 10:23 24821 删除0字节文件find-type f - ... -
linux恢复 rm -rf 删除的文件:extundelete
2013-01-24 15:47 8858http://blog.csdn.net/pang6013 ... -
网站排障分析常用的命令
2013-01-21 18:17 1342------------------------------- ... -
迁移vmware服务器后Device eth0 does not seem to be present
2013-01-21 10:58 2198用VMware 安装 linux 6.0 ... -
LoadRunner如何监控Linux系统资源 : rpc.rstatd
2012-12-17 14:49 10213一 简述:LoadRunner监控Linux资源时弹出如下错误 ... -
僵尸Z进程和D进程
2012-12-10 16:47 13067-------------- 1 关于ZOMBIE进 ... -
Unix操作系统硬链接与符号链接的区别
2012-12-10 16:08 1963Unix操作系统有很多值得 ... -
nagios配置参数详解
2012-12-04 14:12 9377# Nagios return codes#定 ... -
【汇总】shell show收藏
2012-11-29 14:03 1220================== shell从文本取对应的 ... -
Kickstart+PXE+DHCP+TFTP+NFS自动安装Centos5
2012-11-29 11:34 1556http://5ydycm.blog.51cto.com/11 ... -
haproxy+keepalived高可用负载均衡(七层)
2012-11-29 10:36 3954HAproxy是一款基于TCP( ... -
LVS+Keepalived
2012-11-29 10:10 1688http://www.linuxvirtualserver.o ... -
haproxy & LVS*(keepalived和heartbeat) & ng的比较
2012-11-29 10:04 7514http://network.51cto.com/art/ ... -
运维架构师-并不遥远的彼岸
2012-11-28 17:45 1700在百度里搜索运维架构师,你会发现招聘的职位还不少并且月薪、年 ... -
puppet模块汇总
2012-11-21 17:08 2979在磁盘上,一个模块对应一个特殊的目录结构: MODULE_ ... -
puppet 之file
2012-11-21 16:43 2799===================== 实例1 创建 ...
相关推荐
将nagios警报转发到alerta监控系统_C_下载.zip
Nagios_Plugin_for_Cacti_安装使用篇.pdf
IP Hostname 备注 192.168.88.31 server nagios服务端 ...nagios客户端 ...nagios-plugins版本:2.2.1 ...添加监控脚本,设计一个能监控nginx端口的脚本;并添加到远程监控项目中; 添加监控脚本,设计一个能监控m
linux中的nagios监控原理和进程、端口监控配置文件及参数含义详解。
对安装部署nagios中实际经验总结,对这个免费网络监控软件进行深入了解
nagios服务端ndoutile+nagios+nagios_plugins.rarnagios服务端ndoutile+nagios+nagios_plugins.rar
Linux下nginx+nagios_监控平台搭建.doc
nagios安装配置详细版,包括监控插件编写,部署,pnp4nagios安装,短信报警等
主要介绍了Nagios的功能和自定义插件的时候需要的一些配置,都是自己尝试成功的一些配置
nagios监控nginx状态脚本 教程http://2860664.blog.51cto.com/2850664/1564225
nagios系统监控实践,nagios告警在大数据领域用得比较多
向Nagios添加监控主机 监控linux服务器
Nagios 是一种开源的网络监控系统,可用于监控网络设备、服务器和应用程序。它提供了强大的监控和报警功能,使网络管理员能够实时了解系统的状态并及时采取措施。 Nagios 具有以下主要功能: 监控服务:Nagios 可以...
它是一个完全GPL协议的开源软件包,包含有nagios主程序和它的各个插件,配置非常灵活,可以监视的项目很多,可以自定义shell脚本进行监控服务,非常适合大型网络。 nagios的包含主动监控和被动监控。 主动检查是...
NULL 博文链接:https://mushme.iteye.com/blog/1901554
nagios 配置 监控数据库 nagios 配置 监控数据库
编写的脚本用来监控mysql主从模式 环境: Centos5.6 mysql只做同步指定库,没有同步mysql库用户数据 登陆从服务器mysql,添加验证的用户 grant replication client on *.* to 'nagios'@localhost identified ...
Nagios系统监控实践(第2版) 原书完整版
NULL 博文链接:https://leiyi-sz.iteye.com/blog/1850381
Nagios系统监控实践(第2版) Nagios系统监控实践(第2版)