標籤:centos 6.4x64安裝部署nagios
本文參考了http://wangzan18.blog.51cto.com/8021085/1628984
http://linuxnote.blog.51cto.com/9876511/1637773
一、nagios概述
Nagios是外掛程式式的結構,它本身沒有任何監控功能,所有的監控都是通過外掛程式進行的,因此其是高度模組化和富於彈性的。Nagios監控的對象可分為兩類:主機和服務。主機通常指的是物理主機,如伺服器、路由器、工作站和印表機等,這裡的主機也可以是虛擬設備,如xen虛擬出的Linux系統;而服務通常指某個特定的功能,如提供http服務的httpd進程等。而為了管理上的方便,主機和服務還可以分別被規劃為主機群組和服務組等。
Nagios不監控任何具體數值指標(如作業系統上的進程個數),它僅用四種抽象屬性對被監控對象的狀態進行描述:OK、WARNING, CRITICAL和UNKNOWN。於是,管理員只需要對某種被監控對象的WARNING和CRITICAL狀態的閾值進行關注和定義即可。Nagios通過將WARTING和CRTICAL的閾值傳遞給外掛程式,並由外掛程式負責某具體對象的監控及結果分析,其輸出資訊為狀態資訊(OK,WARNING,CRITICAL或UNKOWN)以及一些附加的詳細說明資訊。
二、環境
系統:centos 6.4x64迷你安裝
nagios-server: 192.168.3.71
nagios-client: 192.168.3.72
三、安裝nagios
Nagios通常由一個主程式(Nagios)、一個外掛程式程式(Nagios-plugins)和四個可選的ADDON(NRPE、NSCA、NSClient++和NDOUtils)組成。Nagios的監控工作都是通過外掛程式實現的,因此,Nagios和Nagios-plugins是伺服器端工作所必須的組件。而四個ADDON中,NRPE用來在監控的遠程Linux/Unix主機上執行指令碼外掛程式以實現對這些主機資源的監控;NSCA用來讓被監控的遠程Linux/Unix主機主動將監控資訊發送給Nagios伺服器(這在冗餘監控模式中特別要用到);NSClient++是用來監控Windows主機時安裝在Windows主機上的組件;而NDOUtils則用來將Nagios的配置資訊和各event產生的資料存入資料庫,以實現這些資料的快速檢索和處理。這四個ADDON(附件)中,NRPE和NSClient++工作於用戶端,NDOUtils工作於伺服器端,而NSCA則需要同時安裝在伺服器端和用戶端。
目前,Nagios只能安裝在Linux系統主機上,其編譯需要用到gcc。同時,如果打算使用web介面的管理工具的話,還需要有apache伺服器和GD圖形庫的支援
安裝nagios依賴關係
[[email protected] ~]# yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server ntp
同步時間
[[email protected] ~]# ntpdate asia.pool.ntp.org25 May 10:45:35 ntpdate[22419]: step time server 118.67.201.10 offset 140.952903 sec[[email protected] ~]# hwclock -w[[email protected] ~]# crontab -lMAILTO=""*/10 * * * * /usr/sbin/ntpdate asia.pool.ntp.org
添加nagios運行需要的使用者和組
[[email protected] ~]# groupadd nagcmd[[email protected] ~]# useradd -G nagcmd nagios
把apache添加到
[[email protected] ~]# usermod -a -G nagcmd apache
下載nagios,並安裝
[[email protected] ~]# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz/download[[email protected] ~]# tar xf nagios-3.3.1.tar.gz [[email protected] ~]# cd nagios[[email protected] nagios]# ./configure --with-command-group=nagcmd --enable-event-broker [[email protected] nagios]# make all #安裝所有主程式[[email protected] nagios]# make install #安裝主程式,CHI和HTML檔案[[email protected] nagios]# make install-init #安裝啟動指令碼[[email protected] nagios]# make install-commandmode #配置目錄許可權[[email protected] nagios]# make install-config #安裝樣本檔案[[email protected] nagios]# make install-webconf #安裝nagios的web網站設定檔
為nagios配置警示資訊的郵件地址
#編輯檔案前,先備份[[email protected] nagios]# cp /usr/local/nagios/etc/objects/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg.$(date +%F).bak#郵箱地址修改成自己要設定的地址[[email protected] nagios]# sed -i ‘s#[email protected]#[email protected]#‘ /usr/local/nagios/etc/objects/contacts.cfg[[email protected] nagios]# grep [email protected] /usr/local/nagios/etc/objects/contacts.cfg email [email protected]; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
建立一個登陸驗證的使用者和密碼
#這裡設定密碼weyee2014[[email protected] nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
關閉iptables和啟動httpd
[[email protected] nagios]# service iptables stop[[email protected] nagios]# service httpd start
安裝nagios-plugins
#下載nagios-plugins[[email protected] ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz[[email protected] ~]# tar xf nagios-plugins-2.0.3.tar.gz [[email protected] ~]# cd nagios-plugins-2.0.3[[email protected] nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios[[email protected] nagios-plugins-2.0.3]# make && make install
配置nagios啟動層級
#將nagios添加到開機自啟動[[email protected] ~]# chkconfig --add nagios[[email protected] ~]# chkconfig nagios on#檢查設定檔[[email protected] ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg [[email protected] ~]# service nagios startStarting nagios: done.[[email protected] ~]# ps aux |grep nagiosnagios 45840 0.0 0.1 28048 1396 ? Ssl 11:25 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgroot 45852 0.0 0.0 103248 832 pts/0 S+ 11:25 0:00 grep nagios
訪問http://192.168.3.71/nagios,使用者名稱和密碼是上文中設定的nagiosadmin:weyee2014
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/6D/5F/wKiom1VilvjQa-lYAAZTSwYNjbg238.jpg" title="nagios-admin.JPG" alt="wKiom1VilvjQa-lYAAZTSwYNjbg238.jpg" />
四、安裝NRPE
NRPE需要nagios-pluin的支援
[[email protected] ~]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz/download[[email protected] ~]# tar xf nrpe-2.15.tar.gz [[email protected] ~]# cd nrpe-2.15[[email protected] nrpe-2.15]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl[[email protected] nrpe-2.15]# make all[[email protected] nrpe-2.15]# make install-plugin[[email protected] nrpe-2.15]# make install-daemon[[email protected] nrpe-2.15]# make install-daemon-config
配置NRPE
#編輯NRPE的設定檔[[email protected] ~]# egrep -v "^$|^#" /usr/local/nagios/etc/nrpe.cfg log_facility=daemonpid_file=/var/run/nrpe.pidserver_port=5666server_address=192.168.3.71 #修改這裡nrpe_user=nagiosnrpe_group=nagiosallowed_hosts=192.168.3.0/24 #修改這裡 dont_blame_nrpe=0allow_bash_command_substitution=0debug=0command_timeout=60connection_timeout=300command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
啟動NRPE
[[email protected] ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d[[email protected] ~]# netstat -anpt |grep 5666tcp 0 0 192.168.3.71:5666 0.0.0.0:* LISTEN 48946/nrpe
編寫NRPCE的啟動指令碼,將指令碼放到/etc/init.d路徑下
[[email protected] ~]# cat /etc/init.d/nrped #!/bin/bash# chkconfig: 2345 88 12# description: NRPE DAEMONNRPE=/usr/local/nagios/bin/nrpeNRPECONF=/usr/local/nagios/etc/nrpe.cfgcase "$1" instart)echo -n "Starting NRPE daemon..."$NRPE -c $NRPECONF -decho " done.";;stop)echo -n "Stopping NRPE daemon..."pkill -u nagios nrpeecho " done.";;restart)$0 stopsleep 2$0 start;;*)echo "Usage: $0 start|stop|restart";;esacexit 0#賦予指令碼許可權,並測試[[email protected] ~]# chmod +x /etc/init.d/nrped [[email protected] ~]# chkconfig --add nrped[[email protected] ~]# chkconfig nrped on[[email protected] ~]# service nrped stopStopping NRPE daemon... done.[[email protected] ~]# netstat -anpt |grep nrpe[[email protected] ~]# pidof nrpe#重新啟動nrpe[[email protected] ~]# service nrped startStarting NRPE daemon... done.[[email protected] ~]# netstat -anpt |grep nrpetcp 0 0 192.168.3.71:5666 0.0.0.0:* LISTEN 49019/nrpe [[email protected] ~]# pidof nrpe49019[[email protected] ~]# ps aux |grep nrpe |grep -v grepnagios 49019 0.0 0.1 39240 1312 ? Ss 11:53 0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
五、在用戶端安裝NRPE
在nagios-client上安裝NRPE,需要先安裝nagios-plugin
[[email protected] ~]# yum install ntpdate gcc* openssl openssl-devel -y[[email protected] ~]# ntpdate asia.pool.ntp.org25 May 13:52:18 ntpdate[22302]: step time server 212.26.18.41 offset 2955.354923 sec[[email protected] ~]# hwclock -w[[email protected] ~]# crontab -lMIALTO=""*/10 * * * * /usr/sbin/ntpdate asia.pool.ntp.org[[email protected] ~]# useradd -s /sbin/nologin nagios[[email protected] ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz[[email protected] ~]# tar xf nagios-plugins-2.0.3.tar.gz [[email protected] ~]# cd nagios-plugins-2.0.3[[email protected] nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios[[email protected] nagios-plugins-2.0.3]# make all[[email protected] nagios-plugins-2.0.3]# make install
安裝NRPE
[[email protected] ~]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz/download[[email protected] nrpe-2.15]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl[[email protected] nrpe-2.15]# make all[[email protected] nrpe-2.15]# make install-plugin[[email protected] nrpe-2.15]# make install-daemon[[email protected] nrpe-2.15]# make install-daemon-config#修改設定檔[[email protected] nrpe-2.15]# egrep -v "^#|^$" /usr/local/nagios/etc/nrpe.cfg log_facility=daemonpid_file=/var/run/nrpe.pidserver_port=5666server_address=192.168.3.72 #監控本機哪個IPnrpe_user=nagiosnrpe_group=nagiosallowed_hosts=192.168.3.71 #允許哪個IP對本機進行監控#編寫nrpe啟動指令碼[[email protected] ~]# cat /etc/init.d/nrped #!/bin/bash# chkconfig: 2345 88 12# description: NRPE DAEMONNRPE=/usr/local/nagios/bin/nrpeNRPECONF=/usr/local/nagios/etc/nrpe.cfgcase "$1" instart)echo -n "Starting NRPE daemon..."$NRPE -c $NRPECONF -decho " done.";;stop)echo -n "Stopping NRPE daemon..."pkill -u nagios nrpeecho " done.";;restart)$0 stopsleep 2$0 start;;*)echo "Usage: $0 start|stop|restart";;esacexit 0[[email protected] ~]# chmod +x /etc/init.d/nrped [[email protected] ~]# chkconfig --add nrped[[email protected] ~]# chkconfig nrped on[[email protected] ~]# service nrped startStarting NRPE daemon... done.[[email protected] ~]# netstat -anpt |grep nrpetcp 0 0 192.168.3.72:5666 0.0.0.0:* LISTEN 46882/nrpe
到此nagios和用戶端的安裝已完成
本文出自 “ly36843營運” 部落格,請務必保留此出處http://ly36843.blog.51cto.com/3120113/1654887
centos 6.4x64安裝部署nagios