一:寫bash腳本時(shí)候經(jīng)常用到的顏色代碼
創(chuàng)新互聯(lián)是網(wǎng)站建設(shè)技術(shù)企業(yè),為成都企業(yè)提供專業(yè)的成都做網(wǎng)站、網(wǎng)站制作,網(wǎng)站設(shè)計(jì),網(wǎng)站制作,網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制適合企業(yè)的網(wǎng)站。十年品質(zhì),值得信賴!
COLOR_SUCCESS=$(echo -en "[url=file://\\033[1;32m]\\033[1;32m[/url]" ) COLOR_FAILURE=$(echo -en "[url=file://\\033[1;31m]\\033[1;31m[/url]" ) COLOR_WARNING=$(echo -en "[url=file://\\033[1;33m]\\033[1;33m[/url]") COLOR_NORMAL=$(echo -en "[url=file://\\033[0;39m]\\033[0;39m[/url]")
二:自動(dòng)化部署簡(jiǎn)介
由于服務(wù)器數(shù)量的不斷增加,面對(duì)數(shù)以千計(jì)的需要做Nagios 監(jiān)控的客戶端,自動(dòng)化部署就會(huì)被提上日程了,自動(dòng)化部署最簡(jiǎn)單的是把安裝時(shí)的命令通過腳本組合在一起,再加上一些成功與否的判斷
Nagios server 端Nagios服務(wù)器自動(dòng)安裝腳本部署腳本
#!/bin/sh #==================================== # $Name: nagios-server-install.sh # $Revision: 1.0 # $Function: install the nagios monitor # $Author: zangyunchao # $organization: 洛陽理工&zzu # $Create Date: 2013.05 #==================================== #顏色設(shè)置 COLOR_SUCCESS=$(echo -en "[url=file://\\033[1;32m]\\033[1;32m[/url]" ) COLOR_FAILURE=$(echo -en "[url=file://\\033[1;31m]\\033[1;31m[/url]" ) COLOR_WARNING=$(echo -en "[url=file://\\033[1;33m]\\033[1;33m[/url]") COLOR_NORMAL=$(echo -en "[url=file://\\033[0;39m]\\033[0;39m[/url]") yum -y install httpd gcc gcc-c++ glibc glibc-common gd gd-devel useradd nagios groupadd nagcmd usermod -G nagcmd nagios usermod -G nagcmd apache cd /usr/local/src wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz wget http://nchc.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz tar zxvf nagios-3.0.6.tar.gz cd nagios-3.0.6 ./configure --with-command-group=nagcmd --prefix=/usr/local/nagios make all make install make install-init make install-config make install-commandmode make install-webconf cd ../ tar zxvf nagios-plugins-1.4.13.tar.gz cd nagios-plugins-1.4.13 ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios make && make install cd ../ tar zxvf nrpe-2.13.tar.gz cd nrpe-2.13 ./configure make all make install-plugin make install-daemon make install-daemon-config htpasswd -bc /usr/local/nagios/etc/htpasswd.users xiaozang333 xiaozang333 #為nagios登錄名和密碼要牢記 echo "alias nagioscheck='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg' " >> /root/.bashrc source /root/.bashrc chkconfig nagios on chkconfig httpd on service httpd start service nagios start service sendmail start
Nagios Client 端《linux系統(tǒng)》部署腳本
腳本一
#!/bin/sh #==================================== # $Name: nagios-server-install.sh # $Revision: 1.0 # $Function: install the nagios monitor # $Author: zangyunchao # $organization: 洛陽理工&zzu # $Create Date: 2013.05 #==================================== useradd nagios cd /usr/local/src wget http://nchc.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz tar zxvf nagios-plugins-1.4.13.tar.gz cd nagios-plugins-1.4.13 ./configure make make install chown nagios:nagios /usr/local/nagios chown -R nagios:nagios /usr/local/nagios/libexec cd ../ tar zxvf nrpe-2.13.tar.gz cd nrpe-2.13 ./configure make all make install-plugin make install-daemon make install-daemon-config sed -i 's@allowed_hosts=127.0.0.1@allowed_hosts=114.112.11.11@' /usr/local/nagios/etc/nrpe.cfg /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
nagios服務(wù)監(jiān)控端增加window主機(jī)腳本(windows系統(tǒng))
## script begins here #! /bin/bash echo "Enter Host Name" read name echo "Enter IP Address of $name" read ip_add echo " define host{ use windows-server //使用的主機(jī)組名 host_name $name //主機(jī)名 alias $name //主機(jī)別名 }
nagios監(jiān)控系統(tǒng)內(nèi)存
#!/bin/sh #==================================== # $Name: sysmem_check.sh # $Revision: 1.0 # $Function: This Nagios plugin can be check linux system memory status # $Author: zangyunchao cp from Shundong Zhao # $organization: UnixHot # $Create Date: 2010-06-10 #==================================== USAGE_Method="$(basename $0) [-w|--warning] <Free Percent> [-c|--critical] <Free Percent>" USAGE_Value="WARNING value must be large than CRITICAL value: `basename $0` $*" STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 #設(shè)置Nagios要求的狀態(tài) if [ $# -lt 4 ];then echo echo "Usage: $USAGE_Method" echo exit 0 fi while [ $# -gt 0 ];do case "$1" in -w|--warning) shift WARNING=$1 ;; -c|--critical) shift CRITICAL=$1 ;; esac shift done if [[ $WARNING -eq $CRITICAL || $WARNING -lt $CRITICAL ]] then echo echo "$USAGE_Value" echo echo "Usage: $USAGE_Method" echo exit 0 fi FREE_MEM=$(free -m | grep - | awk -F ' ' '{print $4}') #取當(dāng)前未使用的內(nèi)存,注意是未使用! TOTAL_MEM=$(free -m | grep Mem | awk -F ' ' '{print $2}') #取當(dāng)前系統(tǒng)總內(nèi)存 PERCENT=$(bc <<< "scale=2;$FREE_MEM/$TOTAL_MEM" | tr '^.' ' ') #使用bc輸出百分比 if [ "$PERCENT" -le "$CRITICAL" ] #如果監(jiān)測(cè)百分比小于等于用戶設(shè)置的嚴(yán)重錯(cuò)誤值,返回2 then echo "CRITICAL - $FREE_MEM MB ($PERCENT%) Free Memory" exit 2 fi if [ "$PERCENT" -le "$WARNING" ] #如果百分比小于等于用戶設(shè)置的警告值就警告并返回1 then echo "WARNING - $FREE_MEM MB ($PERCENT%) Free Memory" exit 1 fi if [ "$PERCENT" -gt "$WARNING" ] #如果百分比大于用戶設(shè)置的警告值就輸出OK返回0 then echo "OK - $FREE_MEM MB ($PERCENT%) Free Memory" exit 0 fi
nagios client 被監(jiān)控端-----for linux系統(tǒng)
#/bin/bash clear echo "=========================================================================" echo "Welcome to UnixHot Linux Monitor" echo "zangyunchao graduation created" echo "" echo "UHLM v1.0 client by UnixHot " echo "=========================================================================" echo "" echo "For more information please visit http://www.unixhot.com/" echo "" SOFTWARE_PATH=/usr/local/src PACKAGE1=gcc PACKAGE2=glibc PACKAGE3=xinetd #PACKAGE4=gd download(){ echo "==================Start download Nagios Client package===========" cd $SOFTWARE_PATH wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz chmod +x nagios-plugins-1.4.14.tar.gz chmod +x nrpe-2.12.tar.gz echo "Download packages finished!" echo "=================================================================" } nagios-plugins(){ echo "=======================install Nagios-plugins=====================" cd $SOFTWARE_PATH useradd -s /sbin/nologin nagios tar zxvf nagios-plugins-1.4.14.tar.gz cd nagios-plugins-1.4.14 ./configure make && make install } nrpe(){ echo "=======================install nrpe================================" cd $SOFTWARE_PATH tar zxvf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure && make all make install-plugin make install-daemon make install-daemon-config make install-xinetd } config(){ echo "=======================Config======================================" sed -i 's/yes/no/g' /etc/xinetd.d/nrpe sed -i 's/127.0.0.1/127.0.0.1 '$Nagios_Server'/g' /etc/xinetd.d/nrpe echo "nrpe 5666/tcp #nrpe" >> /etc/services chown -R nagios:nagios /usr/local/nagios /etc/init.d/xinetd restart sleep 5 netstat -na | grep 5666 echo "************************************************" echo "If you look the LISTEN 5666 port,Congratulations, Nagios-Client Install are successful" echo "************************************************" } main(){ rpm -q $PACKAGE1 $PACKAGE2 $PACKAGE3 > /tmp/rpm.log SOFTWARE_STATUS=`grep 'not installed' /tmp/rpm.log` if [ -z "$SOFTWARE_STATUS" ];then echo "Please input the Nagios Server IP Address" read echo "The Nagios server ip address is $REPLY" Nagios_Server=$REPLY download nagios-plugins nrpe config else echo "Please install the following software first!" echo "" echo "" grep 'not installed' /tmp/rpm.log echo "" fi }
網(wǎng)站名稱:基于nagios網(wǎng)絡(luò)監(jiān)控----腳本
分享鏈接:http://aaarwkj.com/article24/gjgpce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、服務(wù)器托管、小程序開發(fā)、做網(wǎng)站、微信公眾號(hào)、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)