十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
公司服务器越来越多了,本来用一个脚本去检测了,现在改用Nagios
10年积累的成都网站建设、做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站策划后付款的网站建设流程,更有汾阳免费网站建设让你可以放心的选择与我们合作。ubuntu 客户端安装脚本
#!/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 i 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<> /etc/rc.local /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d rm -rf $tmp_dir
自己折腾的ruby脚本,
1:check_smart 磁盘状态检测
#!/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 软阵列检测
#!/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检测
#!/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 检测磁盘空间
#!/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
服务器安装参考
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。