Nagios是一款開源的免費(fèi)網(wǎng)絡(luò)監(jiān)視工具,能有效監(jiān)控Windows、Linux和Unix的主機(jī)狀態(tài),交換機(jī)路由器等網(wǎng)絡(luò)設(shè)置,打印機(jī)等。在系統(tǒng)或服務(wù)狀態(tài)異常時發(fā)出郵件或短信報警第一時間通知網(wǎng)站運(yùn)維人員,在狀態(tài)恢復(fù)后發(fā)出正常的郵件或短信通知。
創(chuàng)新互聯(lián)建站專注于企業(yè)全網(wǎng)整合營銷推廣、網(wǎng)站重做改版、延長網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5開發(fā)、商城網(wǎng)站制作、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為延長等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
可以監(jiān)視系統(tǒng)運(yùn)行狀態(tài)和網(wǎng)絡(luò)信息的監(jiān)視系統(tǒng),能監(jiān)視所指定的本地或遠(yuǎn)程主機(jī)以及服務(wù),同時提供異常通知功能等;可運(yùn)行在Linux/Unix平臺之上,同時提供一個可選的基于瀏覽器的WEB界面以方便系統(tǒng)管理人員查看網(wǎng)絡(luò)狀態(tài),各種系統(tǒng)問題,以及日志等等。
cacti默認(rèn)是以郵件發(fā)送警告信息的,雖然可以安裝插件以實(shí)現(xiàn)其他方式進(jìn)行告警,但不是他的強(qiáng)項,而nagios有著強(qiáng)大的報警機(jī)制
NSCA是可以實(shí)現(xiàn)Nagios被動監(jiān)測的一個程序。
被動監(jiān)測,就是指由被監(jiān)測的服務(wù)器主動上傳數(shù)據(jù)到Nagios監(jiān)控系統(tǒng)中。這種監(jiān)測方式提高了實(shí)時性(出現(xiàn)問題的時候,被監(jiān)測的服務(wù)器可以及時上傳數(shù)據(jù)通知Nagios,從而使管理員可以盡快作出處理,而不用像主動監(jiān)測中一樣,非要等到下一個監(jiān)測周期才能獲知被監(jiān)測服務(wù)器的狀態(tài))。
NDOUtils是一個可以把nagios的獲取的數(shù)據(jù)信息保存到MySQL數(shù)據(jù)庫里的外部構(gòu)件。
系統(tǒng):RHEL6
package:
nagios-cn-3.2.3.tar.bz2
nagios-plugins-1.4.16.tar.gz
gd-devel-2.0.35-11.el6.x86_64.rpm
tar jxf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
./configure //默認(rèn)安裝在/usr/local/nagios根據(jù)提示信息,可能需要添加參數(shù)和依賴包,--enable-embedded-perl
rhel6.4包中沒有g(shù)d-devel包,需要下載使用yum localinstall安裝
yum install perl-ExtUtils-Embed
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
useradd nagios
usermod -G nagios apache
tar zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --enable-extra-opts --enable-perl-modules --enable-libtap
make
make install
chown -R nagios.nagios /usr/local/nagios/libexec/* //設(shè)置權(quán)限
cd /usr/local/nagios/etc/objects
cp -p localhost.cfg hosts.cfg
cp -p localhost.cfg services.cfg
vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg //添加兩行
cfg_file=/usr/local/nagios/etc/objects/services.cfg
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg //注釋此行
vi hosts.cfg //如下格式添加host主機(jī)
define host{
use linux-server
host_name ty1.org
address 192.168.1.2
alias Manager
icon_p_w_picpath server.gif
statusmap_p_w_picpath server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members * ;
}
vi services.cfg //配置service,只留下define servicegroup和define service選項
define servicegroup{ 服務(wù)組并不是必須的,這是配合nagios 的監(jiān)控頁面的顯示
servicegroup_name 系統(tǒng)負(fù)荷檢查
alias 負(fù)荷檢查
members ty1.org,進(jìn)程總數(shù),ty1.org,登錄用戶數(shù),ty1.org,根分區(qū),ty1.org,交換空間利用率
}
define service{
use local-service
host_name *
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name ty1.org
service_description 根分區(qū)
check_command check_local_disk!20%!10%!/
}
define service{
use local-service
host_name ty1.org
service_description 登錄用戶數(shù)
check_command check_local_users!20!50
}
define service{
use local-service
host_name ty1.org
service_description 進(jìn)程總數(shù)
check_command check_local_procs!250!400!RSZDT
}
define service{
use local-service
host_name ty1.org
service_description 系統(tǒng)負(fù)荷
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service{
use local-service
host_name ty1.org
service_description 交換空間利用率
check_command check_local_swap!20!10
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //校驗(yàn)nagios配置文件正確性
htpasswd -m /usr/local/nagios/etc/htpasswd.users nagiosadmin //設(shè)置登錄nagios的用戶(nagiosadmin由自己定義)及密碼
/etc/init.d/nagios start
/etc/init.d/httpd restart
--------------------------------------------
nagios主機(jī)A遠(yuǎn)程監(jiān)控B主機(jī)mysql
B:yum install mysql-server
>create database nagdb;
>grant select on nagdb.* to nagios@'ipA'
A:
#cd /usr/local/nagios/libexec
#./check_mysql -H 192.168.0.7 -u nagios -d nagdb //如下顯示則監(jiān)控成功
Uptime: 10070 Threads: 1 Questions: 25 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 0.2
使nagios給QQ郵箱推送報警郵件
#cd /nagios/etc/objects
#vi commands.cfg //添加check_mysql自動檢測命令
# 'check_mysql' command definition
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -d $ARG2$
}
$USER1$ 代表/nagios/libexec目錄
#vi hosts.cfg //將以下B信息加入hosts.cfg
define host{
use linux-server
host_name desktop7.example.com //B主機(jī)名
alias Mysql
address 192.168.0.7 //B ip
icon_p_w_picpath server.gif
statusmap_p_w_picpath server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
#vi services.cfg //加入B主機(jī)service信息
define service{
use local-service
host_name desktop7.example.com
service_description MYSQL
check_command check_mysql!nagios!nagdb //!后邊分別為commands.cfg中command_line中-H -d 后的變量
notifications_enabled 1 //是否開啟提醒功能,1為開啟
}
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //檢測語法錯誤
#vi contacts.cfg //設(shè)置接受警報郵件的用戶,多個用戶用逗號分割
define contact{
email 849186008@qq.com
}
在QQ郵箱里將發(fā)送的賬戶(nagios@server97.example.com)加入白名單
B主機(jī)mysql服務(wù)器出現(xiàn)問題(nagios會先檢測四次,才會sendmail),就會給郵箱發(fā)郵件報警
--------------------------------------------------------------
NAGIOS_NRPE實(shí)現(xiàn)遠(yuǎn)端主機(jī)監(jiān)控
使用nrpe(5666)實(shí)現(xiàn)對remote host基本服務(wù)(memory、CPU、login users等)的監(jiān)控:
配置步驟可以通過解壓nrpe包在docs里有個nrpe.pdf
1、Remote Host Setup:
#tar xzf nagios-plugins-1.4.6.tar.gz
#cd nagios-plugins-1.4.6
#./configure //編譯完會顯示模塊情況,需要的安裝完后重新執(zhí)行./configure
#make && make install
#useradd nagios
#chown -R nagios.nagios /usr/local/nagios/
#yum install xinetd -y
#tar zxf nrpe-2.15.tar.gz
#cd nrpe-2.15
#./configure
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config
#make install-xinetd
#vi /etc/services
nrpe 5666/tcp //添加此行
#vi /etc/xinetd.d/nrpe
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 192.168.1.3 //添加monitor主監(jiān)控ip,此處的優(yōu)先級(會覆蓋)大于/usr/local/nagios/etc/nrpe.cfg中的
}
#/etc/init.d/xinetd start
#/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.15 //檢測nrpe_plugin安裝是否OK
此處可能報錯:
[root@ty2 nrpe-2.15]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
CHECK_NRPE: Error - Could not complete SSL handshake.
則注意查看是否將/etc/xinetd.d/nrpe中only_from后邊的127.0.0.1丟掉了,記得加上
#vi /usr/local/nagios/etc/nrpe.cfg //customize nrpe commands
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
//習(xí)慣指定磁盤檢測命令為這樣,其他的不變,此處根據(jù)自己而設(shè)定,可以不變,只檢測根目錄
2、Monitoring Host Setup:
#tar xzf nrpe-2.8.tar.gz
#cd nrpe-2.8
#./configure
#make all
#make install-plugin
#/usr/local/nagios/libexec/check_nrpe -H 192.168.1.100 -c check_disk
//-H指定remote主機(jī),-c指定命令,不加-c顯示nrpe版本信息
3、現(xiàn)在用命令已經(jīng)可以檢測遠(yuǎn)程主機(jī)系統(tǒng)信息,接下來配置nrpe命令,以便nagios能夠自動調(diào)用nrpe命令以web頁面顯示監(jiān)控信息
#vi commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
#vi services.cfg //加入想要監(jiān)控的serivce
define service{
use local-service
host_name ty.org
service_description 根分區(qū)
check_command check_nrpe!check_disk
}
define service{
use local-service
host_name ty.org
service_description 登錄用戶數(shù)
check_command check_nrpe!check_users
define servicegroup{ //可以將remote主機(jī)被監(jiān)控的service加入服務(wù)組,只需將其host_name和service_description添加在members后邊即可
servicegroup_name 系統(tǒng)負(fù)荷檢查
alias 負(fù)荷檢查
members ty2.org,進(jìn)程總數(shù),ty2.org,登錄用戶數(shù),ty2.org,根分區(qū),ty2.org,交換空間利用率,ty.org,進(jìn)程總數(shù),ty.org,登錄用戶數(shù),ty.org,根分區(qū),ty.org,交換空間利用率
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //檢測配置文件語法
/etc/init.d/nagios reload
--------------------------------------------------------------
配置飛信機(jī)器人
需要包:fetion linuxso_20101113.tar.gz
mv fetion /usr/local/nagios/libexec/
tar zxf linuxso_20101113.tar.gz -C /usr/lib //32位的包放在lib中,64位的包放在lib64中
chmod +x /usr/lib/lib*
ldconfig /usr/lib
cd /usr/local/nagios/libexec/
chown nagios.nagios fetion
chmod +x fetion
./fetion //執(zhí)行fetion命令,報錯需要裝依賴包,根據(jù)提示安裝
./fetion --mobile=****** --pwd=****** --to=****** --msg-utf8="haha" //測試fetion是否能成功發(fā)送信息
第一次要求輸入驗(yàn)證碼,在/usr/local/nagios/libexec中
將fetion添加到配置文件,實(shí)現(xiàn)自動發(fā)送飛信
vi /libexec/fetion.sh
/usr/local/nagios/libexec/fetion --mobile=*** --pwd=*** --to="$1" --msg-utf8="$2"
chmod +x fetion.sh
/usr/local/nagios/libexec/fetion.sh 18291449704 "asd" //手動測試fetion.sh
cd etc/objects/
vi templates.cfg //添加此逗號后面用fetion的模板
service_notification_commands notify-service-by-email,notify-service-by-fetion
host_notification_commands notify-host-by-email,notify-service-by-fetion
vi commands.cfg //添加以下兩個command
define command{
command_name notify-host-by-fetion
command_line $USER1$/fetion.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$"
}
define command{
command_name notify-service-by-fetion
command_line $USER1$/fetion.sh $CONTACTPAGER "$NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"
}
vi contacts.cfg
define contact{
pager 182*** //添加fetion消息接受號碼
}
//測試配置文件語法
/etc/init.d/nagios restart
nagios+cacti整合
需要的包:
ndoutils-1.5.2.tar.gz
npc-2.0.4.tar.gz
add.sql
#tar zxf npc-2.0.4.tar.gz -C /var/www/html/cacti/plugins
進(jìn)入cacti的web界面安裝npc插件
Settings->npc編輯npc,給Remote Commands打勾,
路徑/usr/local/nagios/var/rw/nagios.cmd
nagios URL:http://192.168.0.197/nagios
INSTALL ndoutils
tar zxf ndoutils-1.5.2.tar.gz
cd ndoutils-1.5.2 //看以參考README安裝
cp src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
chown nagios.nagios /usr/local/nagios/bin/ndomod.o
cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
chown nagios.nagios /usr/local/nagios/etc/ndomod.cfg
chmod 664 /usr/local/nagios/etc/ndomod.cfg
cp src/ndo2db-3x /usr/local/nagios/bin/ndo2db
chown nagios.nagios /usr/local/nagios/bin/ndo2db
cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
chown nagios.nagios /usr/local/nagios/etc/ndo2ddb.cfg
chmod 664 /usr/local/nagios/etc/ndo2db.cfg
vi ndomod.cfg
output_type=tcpsocket
#output_type=unixsocket
output=127.0.0.1
#output=/usr/local/nagios/var/ndo.sock
vi ndo2db.cfg //ndo2db默認(rèn)端口5668
#socket_type=unix
socket_type=tcp
#socket_name=/usr/local/nagios/var/ndo.sock //選用tcp,注釋掉uninx的
db_name=cacti
db_prefix=npc_ //下滑線不能少
db_user=cacti
db_pass=cacti
/usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg //啟動ndoutils
mysql -ucacti -pcacti cacti < add.sql