您好,登錄后才能下訂單哦!
第一部分安裝
Nagios的所有插件的地址:http://www.nagios.org/download/addons
1:安裝LAMP環(huán)境
# yum -y install php httpd gcc glibc glibc-common gd gd-devel
2:建立nagios帳號(hào),請(qǐng)牢記設(shè)置的密碼
# /usr/sbin/useradd nagios && passwd nagios
創(chuàng)建一個(gè)用戶(hù)組名為nagios用于從web接口執(zhí)行外部命令。將nagios用戶(hù)和apache用戶(hù)都加入到這個(gè)組中。
# /usr/sbin/groupadd nagios
# /usr/sbin/usermod -g nagios nagios
# /usr/sbin/usermod -g nagios apache
3:編譯與安裝nagios
進(jìn)入到nagios安裝包所在的文件夾下
# tar -zxvf nagios- 3.4.1.tar.gz
# cd nagios
# ./configure --with-command-group=nagios --prefix=/usr/local/nagios
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf
創(chuàng)建一個(gè)nagiosadmin的用戶(hù),用于nagios的Web接口登錄。請(qǐng)牢記你設(shè)置的密碼。
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
驗(yàn)證是否正確安裝,進(jìn)入到安裝路徑(此處是/usr/local/nagios),看是否存在etc bin sbin share var這五個(gè)目錄,如果存在,則說(shuō)明nagios正確的安裝到系統(tǒng)
4:編譯與安裝nagios-plugins
進(jìn)入到nagios-plugins安裝包所在的文件夾下
# tar -zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure--with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
# make && make install
驗(yàn)證:ls /usr/local/nagios/libexec會(huì)顯示安裝的插件文件,即所有的插件都安裝在libexec這個(gè)目錄下
5:?jiǎn)?dòng)服務(wù)
重啟apache服務(wù)讓設(shè)置生效
# service httpd restart
驗(yàn)證nagios的樣例配置文件
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果沒(méi)有報(bào)錯(cuò),啟動(dòng)nagios服務(wù)
# service nagios start
6:測(cè)試
登錄http://IP地址/nagios/,輸入用戶(hù)名和密碼,則nagios安裝成功。
第二部分監(jiān)控linux主機(jī)
一.被監(jiān)控機(jī)上安裝NRPE
1.安裝客戶(hù)端nagios插件
進(jìn)入到nagios-plugins安裝包所在的文件夾下
# tar -zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios
# make && make install
# useradd nagios
# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec
2.給客戶(hù)端安裝NRPE
首先檢查openssl是否存在,否則要安裝openssl
# rpm –qa | grep openssl
openssl-devel-1.0.0-20.el6_2.5.x86_64
openssl-1.0.0-20.el6_2.5.x86_64
進(jìn)入到nrpe安裝包所在的文件夾下
# tar -zxvf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure --prefix=/usr/local/nagios --enable-ssl --with-ssl-lib=/usr/lib/
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
返回當(dāng)前NRPE的版本
# /usr/local/nagios/libexec/check_nrpe -H localhost
啟動(dòng)NRPE
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
3.配置NRPE客戶(hù)端
添加nrpe服務(wù)器地址,允許監(jiān)控服務(wù)器對(duì)其讀取信息
# vi /usr/local/nagios/etc/nrpe.cfg
在allowed_hosts中添加允許的服務(wù)器,例如:
allowed_hosts=127.0.0.1,10.126.53.65,172.18.0.236
添加command字段來(lái)添加需要監(jiān)控的服務(wù),例如:
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_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
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_ping]=/usr/local/nagios/libexec/check_ping -H 172.18.0.237 -w 3,2% -c 10,6% -p 30
重啟nrpe
# killall -9 nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
二.監(jiān)控機(jī)上安裝NRPE
1.安裝nrpe
首先檢查openssl是否存在,否則要安裝openssl
# rpm –qa | grep openssl
openssl-devel-1.0.0-20.el6_2.5.x86_64
openssl-1.0.0-20.el6_2.5.x86_64
進(jìn)入到nrpe安裝包所在的文件夾下
# tar -zxvf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure --prefix=/usr/local/nagios --enable-ssl --with-ssl-lib=/usr/lib/
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
返回當(dāng)前NRPE的版本
# /usr/local/nagios/libexec/check_nrpe -H localhost
2.commands.cfg中定義外部構(gòu)件nrpe
# vi /usr/local/nagios/etc/objects/commands.cfg
添加check_nrpe
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line$USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
3.配置要監(jiān)控的Linux主機(jī)
# vi /usr/local/nagios/etc/nagios.cfg
修改如下:
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_dir=/usr/local/nagios/etc/objects/servers
# mkdir /usr/local/nagios/etc/objects/servers/
#chown -R nagios.nagios /usr/local/nagios/etc/objects/servers/
4.配置cgi.cfg文件
# vi /usr/local/nagios/etc/cgi.cfg
修改如下:
use_authentication=1
注意:修改文件權(quán)限
# chmod 777 /usr/local/nagios/var/rw/
# chmod 777 / usr/local/nagios/var/rw/nagios.cmd
5.新建host_service_group.cfg,設(shè)置其內(nèi)容
# vi /usr/local/nagios/etc/objects/servers/host_service_group.cfg
其文件內(nèi)容如下:
define servicegroup{
servicegroup_name host_perfdata
alias host_perfdata
}
define hostgroup{
hostgroup_name host_perfdata
alias host_perfdata
}
6.新建172.18.0.237.cfg,設(shè)置監(jiān)控內(nèi)容
# vi /usr/local/nagios/etc/objects/servers/172.18.0.237.cfg
其文件內(nèi)容如下:
define host{
uselinux-server
host_name 172.18.0.237
host_groupshost_perfdata
alias172.18.0.237
address 172.18.0.237
}
define service{
usegeneric-service
host_name 172.18.0.237
service_groupshost_perfdata
service_descriptioncheck_cpu_load
check_command check_nrpe!check_load
notifications_enabled1
}
define service{
use generic-service
host_name 172.18.0.237
service_groupshost_perfdata
service_descriptioncheck_total_process
check_command check_nrpe!check_total_procs
notifications_enabled1
}
define service {
usegeneric-service
host_name 172.18.0.237
service_groupshost_perfdata
service_descriptionPING
check_commandcheck_ping!200.0,20%!500.0,60%
notifications_enabled1
}
驗(yàn)證nagios的配置文件是否正確
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果沒(méi)有報(bào)錯(cuò),重新加載nagios服務(wù)
# service nagios reload
三.Nagios報(bào)警設(shè)置
3.1網(wǎng)頁(yè)報(bào)警
1.修改cgi.cfg配置文件
# vi /usr/local/nagios/etc/cgi.cfg
去掉下面幾行注釋
host_unreachable_sound=hostdown.wav
host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
service_unknown_sound=warning.wav
normal_sound=noproblem.wav
2.在/usr/local/nagios/share/media/下將聲音文件添加進(jìn)去
3.2通過(guò)sendEmail發(fā)送報(bào)警
1.安裝sendEmail
進(jìn)入到sendEmail安裝包所在的文件夾下
# tar -zxvf sendEmail-v1.56.tar.gz
# cd sendEmail-v1.56
# cp sendEmail /usr/local/bin/
# chmod 755 /usr/local/bin/sendEmail
2.測(cè)試
使用系統(tǒng)自帶的sendmail測(cè)試
# cd (回到根目錄)
# mail -s “I am test”admin@admin< install.log
“I am test”是郵件的主題,在admin@admin中如果能收到郵件,則說(shuō)明設(shè)置成功。
3.修改commands.cfg文件(其實(shí)這一步,可以省略,因?yàn)樵诎惭bnagios的時(shí)候,已經(jīng)默認(rèn)存在)
# /usr/local/nagios/etc/objects/commands.cfg
內(nèi)容如下:
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
4.編輯contacts.cfg文件
# /usr/local/nagios/etc/objects/contacts.cfg
內(nèi)容如下:
define contact{
contact_name nagiosadmin; Short name of user
use generic-contact; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email admin@admin ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
service_notification_commands notify-service-by-email
host_notification_commandsnotify-host-by-email
}
5.重啟nagios服務(wù)
# /etc/init.d/nagios reload
第三部分監(jiān)控Windows主機(jī)
一.被監(jiān)控機(jī)(Windows)上安裝NSClient++客戶(hù)端
下載地址:http://nsclient.org/nscp/downloads
目前最新版本:0.4.1.62,根據(jù)需要下載32位或64位機(jī)程序。
.zip格式和.msi格式大同小異,在次處我使用.msi格式,并以32位機(jī)為例。
雙擊下載好的程序,開(kāi)始安裝
選擇:Typical
勾選:Allow all users to write config file
在Allowed hosts中填寫(xiě)監(jiān)控主機(jī)的IP,NSClient password中本應(yīng)該填寫(xiě)監(jiān)控機(jī)和
被監(jiān)控機(jī)之間的通信密碼,為了方便,在次不進(jìn)行設(shè)置,勾選Modules to load
下面的所有選項(xiàng)。點(diǎn)擊Next
點(diǎn)擊Install完成安裝。
進(jìn)入到服務(wù)中,找到NSClient++(Win32),雙擊它,選擇登錄,再勾選允許服務(wù)與
桌面交互,最后重啟服務(wù)。
二.監(jiān)控機(jī)(Linux)添加監(jiān)控項(xiàng)
在/usr/local/nagios/etc/objects/servers/目錄下添加一臺(tái)Windows主機(jī)
# vi /usr/local/nagios/etc/objects/servers/10.126.53.54.cfg
其文件內(nèi)容如下:
define host{
use linux-server
host_name10.126.53.54
alias10.126.53.54
host_groupshost_perfdata
address 10.126.53.54
}
define service{
use generic-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
notifications_enabled 1
}
define service{
usegeneric-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_memory_useage
check_command check_nt!MEMUSE!-w 80 -c 90
notifications_enabled 1
}
define service{
use generic-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_cpu_load
check_command check_nt!CPULOAD!-l 5,70,80
notifications_enabled 1
}
define service{
usegeneric-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_C:\_space
check_command check_nt!USEDDISKSPACE!-l C!-w 80 -c 90
notifications_enabled 1
}
define service{
use generic-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_E:\_space
check_command check_nt!USEDDISKSPACE!-l E!-w 80 -c 90
notifications_enabled 1
}
驗(yàn)證nagios的配置文件是否正確
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果沒(méi)有報(bào)錯(cuò),重新加載nagios服務(wù)
# service nagios reload
可以進(jìn)行測(cè)試:
#/usr/local/nagios/libexec/check_nt -H 10.126.53.54 -v CPULOAD -p 12489 -l 5,70,80
#/usr/local/nagios/libexec/check_nt -H 10.126.53.54-v MEMUSE -p 12489
#/usr/local/nagios/libexec/check_nt -H 10.126.53.54 -v USEDDISKSPACE -p 12489 -l C
#/usr/local/nagios/libexec/check_nt -H 10.126.53.54 -v USEDDISKSPACE -p 12489 -l E
第四部分nagvis插件的安裝
Nagvis官方網(wǎng)站:http://www.nagvis.org/
Nagvis下載:http://jaist.dl.sourceforge.net/project/nagvis/NagVis 1.7/nagvis-1.7.3.tar.gz
ndoutils下載:http://sourceforge.net/projects/nagios/files/ndoutils-1.x/
一.安裝ndoutils
查看是否安裝mysql-devel(它是用來(lái)編譯ndoutils)
# rpm -qa | grep mysql
如果沒(méi)有安裝mysql-devel,則用yum安裝
# yum -y install mysql-devel
為ndoutils創(chuàng)建數(shù)據(jù)庫(kù)
#mysql -u root -p
Enter password:
mysql> create database ndodb;
mysql>grant all privileges on ndodb.* to ndouser@localhost identified by 'ndouser';
mysql>grant all privileges on ndodb.* to ndouser@'%' identified by 'ndouser';
mysql>flush privileges;
mysql>quit
關(guān)聯(lián)mysql頭文件和庫(kù)
# ln -s /usr/local/mysql/include/* /usr/include/
# ln -s /usr/local/mysql/lib/* /usr/lib/
注意:/usr/local/mysql是MySQL的安裝目錄
開(kāi)始安裝ndoutils
# tar zxvf ndoutils-1.5.2.tar.gz
# cd ndoutils-1.5.2
#./configure --prefix=/usr/local/nagios --enable-mysql --enable-ssl --with-ssl-lib=/usr/lib --with-ndo2db-user=nagios --with-ndo2db-group=nagios --with-mysql=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib LDFLAGS=-L/usr/lib
注意:/usr/local/mysql是MySQL的安裝目錄
#make
#make install//此命令可不用執(zhí)行
# cd db/
# ./installdb -u ndouser -p ndouser -h localhost -d ndodb
# cd ../src/
# cp file2sock log2ndo ndo2db-2x ndo2db-3x ndomod-2x.o ndomod-3x.o/usr/local/nagios/bin/
# cd ../config
# cp ndo2db.cfg-sample ndomod.cfg-sample /usr/local/nagios/etc/
# mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
# mv /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
# chmod 644 /usr/local/nagios/etc/ndo*
# vi /usr/local/nagios/etc/nagios.cfg
修改內(nèi)容如下:
check_external_commands=1(大概在146行)
command_check_interval=-1(大概在164行)
event_broker_options=-1(大概在222行)
在249行下面添加一行:
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local /nagios/etc/ndomod.cfg
process_performance_data=1(大概在834行)
# vi /usr/local/nagios/etc/ndomod.cfg
將其修改為:
# cat /usr/local/nagios/etc/ndomod.cfg |grep -v '^#'|sed /^$/d
# vi /usr/local/nagios/etc/ndo2db.cfg
將其修改為:
# cat /usr/local/nagios/etc/ndo2db.cfg |grep -v '^#'|sed /^$/d
啟動(dòng)ndo2db守護(hù)進(jìn)程
# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
二.安裝Nagvis
安裝支持庫(kù)graphviz
# cp /etc/yum.repos.d/rpmforge.repo /etc/yum.repos.d/rpmforge.repo.bak
# vi /etc/yum.repos.d/rpmforge.repo
將下面的內(nèi)容加入到最后面:
[graphviz-stable]
name=Graphviz - RHEL $releasever - $basearch
baseurl=http://www.graphviz.org/pub/graphviz/stable/redhat/el$releasever/$basearch/os/
enabled=1
gpgcheck=0
skip_if_unavailable=1
[graphviz-stable-source]
name=Graphviz - RHEL $releasever - Source
baseurl=http://www.graphviz.org/pub/graphviz/stable/SRPMS/
enabled=0
gpgcheck=0
skip_if_unavailable=1
[graphviz-stable-debuginfo]
name=Graphviz - RHEL - Debug
baseurl=http://www.graphviz.org/pub/graphviz/stable/redhat/el$releasever/$basearch/debug/
enabled=0
gpgcheck=0
skip_if_unavailable=1
[graphviz-snapshot]
name=Graphviz - RHEL $releasever - $basearch
baseurl=http://www.graphviz.org/pub/graphviz/development/redhat/el$releasever/$basearch/os/
enabled=0
gpgcheck=0
skip_if_unavailable=1
[graphviz-snapshot-source]
name=Graphviz - RHEL $releasever - Source
baseurl=http://www.graphviz.org/pub/graphviz/development/SRPMS/
enabled=0
gpgcheck=0
skip_if_unavailable=1
[graphviz-snapshot-debuginfo]
name=Graphviz - RHEL - Debug
baseurl=http://www.graphviz.org/pub/graphviz/development/redhat/el$releasever/$basearch/debug/
enabled=0
gpgcheck=0
skip_if_unavailable=1
# yum -y install graphviz*
# tar zxvf nagvis-1.7.3.tar.gz
# cd nagvis-1.7.3
# bash install.sh
詳細(xì)請(qǐng)參考官方文檔:http://docs.nagvis.org/1.7/en_US/index.html
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。