您好,登錄后才能下訂單哦!
一:寫bash腳本時候經常用到的顏色代碼
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]")
二:自動化部署簡介
由于服務器數量的不斷增加,面對數以千計的需要做Nagios 監控的客戶端,自動化部署就會被提上日程了,自動化部署最簡單的是把安裝時的命令通過腳本組合在一起,再加上一些成功與否的判斷
Nagios server 端Nagios服務器自動安裝腳本部署腳本
#!/bin/sh #==================================== # $Name: nagios-server-install.sh # $Revision: 1.0 # $Function: install the nagios monitor # $Author: zangyunchao # $organization: 洛陽理工&zzu # $Create Date: 2013.05 #==================================== #顏色設置 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系統》部署腳本
腳本一
#!/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服務監控端增加window主機腳本(windows系統)
## 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 //使用的主機組名 host_name $name //主機名 alias $name //主機別名 }
nagios監控系統內存
#!/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 #設置Nagios要求的狀態 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}') #取當前未使用的內存,注意是未使用! TOTAL_MEM=$(free -m | grep Mem | awk -F ' ' '{print $2}') #取當前系統總內存 PERCENT=$(bc <<< "scale=2;$FREE_MEM/$TOTAL_MEM" | tr '^.' ' ') #使用bc輸出百分比 if [ "$PERCENT" -le "$CRITICAL" ] #如果監測百分比小于等于用戶設置的嚴重錯誤值,返回2 then echo "CRITICAL - $FREE_MEM MB ($PERCENT%) Free Memory" exit 2 fi if [ "$PERCENT" -le "$WARNING" ] #如果百分比小于等于用戶設置的警告值就警告并返回1 then echo "WARNING - $FREE_MEM MB ($PERCENT%) Free Memory" exit 1 fi if [ "$PERCENT" -gt "$WARNING" ] #如果百分比大于用戶設置的警告值就輸出OK返回0 then echo "OK - $FREE_MEM MB ($PERCENT%) Free Memory" exit 0 fi
nagios client 被監控端-----for linux系統
#/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 }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。