Nagios 安装设置

简介:

公司服务器越来越多了,本来用一个脚本去检测了,现在改用Nagios


ubuntu 客户端安装脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
tmp_dir= /tmp/nagios
nagios_ser= "192.168.1.3"
groupadd nagios  
useradd  -g nagios -s  /sbin/nologin  nagios
if  [ ! -d $tmp_dir ];  then
     mkdir  $tmp_dir
fi
cd  $tmp_dir
wget http: //downloads .sourceforge.net /project/nagios/nrpe-2 .x /nrpe-2 .15 /nrpe-2 .15. tar .gz
wget http: //nagios-plugins .org /download/nagios-plugins-2 .0.1. tar .gz
#---- install
for  in  ` ls  -1`
     do  tar  xf $i
done
apt-get -y --force- yes  install  openssl ruby1.9.1 build-essential
apt-get -y --force- yes  install  libssl-dev lm-sensors
tar  xvf nagios-plugins-2.0.1. tar .gz
cd  nagios-plugins-2.0.1
. /configure  --with-nagios-user=nagios --with-nagios-group=nagios
make   
make  install
cd  ../
tar  xvf nrpe-2.15. tar .gz
cd  . /nrpe-2 .15
. /configure  --with-ssl-lib= /usr/lib/x86_64-linux-gnu
make  all   
make  install -plugin   
make  install -daemon   
make  install -daemon-config
#mv ./check_* /usr/local/nagios/libexec
#chmod 755 -R /usr/local/nagios/libexec
chown  -R nagios:nagios  /usr/local/nagios/
cat  > /usr/local/nagios/etc/nrpe .cfg<<EOF
log_facility=daemon
pid_file= /var/run/nrpe .pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1,$nagios_ser
                                              
dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
command [check_users]= /usr/local/nagios/libexec/check_users  -w 5 -c 10
command [check_load]= /usr/local/nagios/libexec/check_load  -w 15,10,5 -c 30,25,20
command [check_zombie_procs]= /usr/local/nagios/libexec/check_procs  -w 5 -c 10 -s Z
command [check_total_procs]= /usr/local/nagios/libexec/check_procs  -w 150 -c 200
command [check_procs]= /usr/local/nagios/libexec/check_procs  -w 150 -c 200
command [check_alldisk]= /usr/local/nagios/libexec/check_alldisk  -w 90 -c 95
command [check_http]= /usr/local/nagios/libexec/check_http  -H 127.0.0.1 -w 5 -c 10
command [check_ping]= /usr/local/nagios/libexec/check_ping  -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5
command [check_ssh]= /usr/local/nagios/libexec/check_ssh  -4 127.0.0.1
command [check_swap]= /usr/local/nagios/libexec/check_swap   -w 30% -c 10%
command [check_sensors]= /usr/local/nagios/libexec/check_sensors
command [check_mdadm]= /usr/local/nagios/libexec/check_mdadm
command [check_smart]= /usr/local/nagios/libexec/check_smart
command [check_drbd]= /usr/local/nagios/libexec/check_drbd
EOF
echo  "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d"  >>  /etc/rc . local
/usr/local/nagios/bin/nrpe  -c  /usr/local/nagios/etc/nrpe .cfg -d
rm  -rf $tmp_dir



自己折腾的ruby脚本,

1:check_smart 磁盘状态检测

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env ruby
#0 ok; 1 warning; 2 critical; 3 unknown
#echo "nagios ALL=NOPASSWD:/usr/sbin/smartctl" >>/etc/sudoers
#CentOS sed -i "s:Defaults  requiretty:Defaults:nagios !requiretty:" /etc/sudoers
#调用 check_nrpe!check_smart
health =  ""
`ls - 1  /dev/sd[a-z]* | grep [a-z]$`.split. each  do  |hdd|
   status = `sudo /usr/sbin/smartctl - H  #{hdd} | grep result | awk -F: '{print $2}'`
   if  status.match(/ PASSED /)
     health = health + hdd +  "  OK\n"
   else
     health = health + hdd +  "  Fail\n"
   end
end
if  health.include?  "Fail"
         puts health
         exit  2
end
puts health
exit  0

2:check_mdadm 软阵列检测

1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env ruby
#0 ok; 1 warning; 2 critical; 3 unknown
status = `cat /proc/mdstat`
if  status.scan( 'U' ).size == status.scan( 'md' ).size *  2
     puts  "Soft Raid OK"
     exit  0
else
     puts  "Soft Raid Fail"
     exit  2
end

3:check_drbd DRBD检测

1
2
3
4
5
6
7
8
9
#!/usr/bin/ruby
#0 ok; 1 warning; 2 critical; 3 unknown
if  `cat /proc/drbd`.scan( "UpToDate" ).count == `ls -la /dev/ | grep ^b | grep drbd | wc -l`.to_i *  2
     puts  "DRBD OK"
     exit  0
else
     puts  "DRBD Critical"
     exit  2
end

4:check_alldisk 检测磁盘空间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env ruby
#ARGV[1] min ,ARGV[3] max
# -w 90 -c 95
#0 ok; 1 warning; 2 critical; 3 unknown
space =  ''
status = `df -hl -x tmpfs -x devtmpfs | grep -v ^Filesystem`.split
if  status.size <  6  #unkown
     puts  "UNKOWN"
     exit  3
end
(status.size /  6 ).times  do  |x|
     current_use, min_use, max_use = status[ 4  + x *  6 ][ 0 ..- 2 ].to_i,  ARGV [ 1 ].to_i,  ARGV [ 3 ].to_i
     if   current_use > max_use  #critical
         space = space + status[x *  6 ] +  "  "  + status[ 4  + x *  6 ] +   "  "  + status[ 5  + x *  6 ] + "  Critical\n"
     elsif  current_use > min_use  and  current_use <= max_use  #warning
         space = space + status[x *  6 ] +  "  "  + status[ 4  + x *  6 ] +   "  "  + status[ 5  + x *  6 ] +  "  Warning\n"
     elsif   current_use <= min_use  #ok
         space = space + status[x *  6 ] +  "  "  + status[ 4  + x *  6 ] +   "  "  + status[ 5  + x *  6 ] +  "  OK\n"
     end
end
if  space.include?( "Crtitical" )
     puts space
     exit  2
elsif  space.include?( "Warning" )
     puts space
     exit  1
else
     puts space
     exit  0
end


本文转自 nonono11 51CTO博客,原文链接:http://blog.51cto.com/abian/1412478,如需转载请自行联系原作者
相关文章
|
9天前
|
数据采集 人工智能 安全
|
5天前
|
机器学习/深度学习 人工智能 前端开发
构建AI智能体:七十、小树成林,聚沙成塔:随机森林与大模型的协同进化
随机森林是一种基于决策树的集成学习算法,通过构建多棵决策树并结合它们的预测结果来提高准确性和稳定性。其核心思想包括两个随机性:Bootstrap采样(每棵树使用不同的训练子集)和特征随机选择(每棵树分裂时只考虑部分特征)。这种方法能有效处理大规模高维数据,避免过拟合,并评估特征重要性。随机森林的超参数如树的数量、最大深度等可通过网格搜索优化。该算法兼具强大预测能力和工程化优势,是机器学习中的常用基础模型。
312 164
|
4天前
|
机器学习/深度学习 自然语言处理 机器人
阿里云百炼大模型赋能|打造企业级电话智能体与智能呼叫中心完整方案
畅信达基于阿里云百炼大模型推出MVB2000V5智能呼叫中心方案,融合LLM与MRCP+WebSocket技术,实现语音识别率超95%、低延迟交互。通过电话智能体与座席助手协同,自动化处理80%咨询,降本增效显著,适配金融、电商、医疗等多行业场景。
318 155
|
5天前
|
编解码 人工智能 自然语言处理
⚽阿里云百炼通义万相 2.6 视频生成玩法手册
通义万相Wan 2.6是全球首个支持角色扮演的AI视频生成模型,可基于参考视频形象与音色生成多角色合拍、多镜头叙事的15秒长视频,实现声画同步、智能分镜,适用于影视创作、营销展示等场景。
355 4
|
12天前
|
SQL 自然语言处理 调度
Agent Skills 的一次工程实践
**本文采用 Agent Skills 实现整体智能体**,开发框架采用 AgentScope,模型使用 **qwen3-max**。Agent Skills 是 Anthropic 新推出的一种有别于mcp server的一种开发方式,用于为 AI **引入可共享的专业技能**。经验封装到**可发现、可复用的能力单元**中,每个技能以文件夹形式存在,包含特定任务的指导性说明(SKILL.md 文件)、脚本代码和资源等 。大模型可以根据需要动态加载这些技能,从而扩展自身的功能。目前不少国内外的一些框架也开始支持此种的开发方式,详细介绍如下。
885 6

热门文章

最新文章