您好,登錄后才能下訂單哦!
Nagios是一款開源的免費網絡監視工具,能有效監控Windows、Linux和Unix的主機狀態,交換機路由器等網絡設置,打印機等。在系統或服務狀態異常時發出郵件或短信報警第一時間通知網站運維人員,在狀態恢復后發出正常的郵件或短信通知。
可以監視系統運行狀態和網絡信息的監視系統,能監視所指定的本地或遠程主機以及服務,同時提供異常通知功能等;可運行在Linux/Unix平臺之上,同時提供一個可選的基于瀏覽器的WEB界面以方便系統管理人員查看網絡狀態,各種系統問題,以及日志等等。
cacti默認是以郵件發送警告信息的,雖然可以安裝插件以實現其他方式進行告警,但不是他的強項,而nagios有著強大的報警機制
NSCA是可以實現Nagios被動監測的一個程序。
被動監測,就是指由被監測的服務器主動上傳數據到Nagios監控系統中。這種監測方式提高了實時性(出現問題的時候,被監測的服務器可以及時上傳數據通知Nagios,從而使管理員可以盡快作出處理,而不用像主動監測中一樣,非要等到下一個監測周期才能獲知被監測服務器的狀態)。
NDOUtils是一個可以把nagios的獲取的數據信息保存到MySQL數據庫里的外部構件。
系統: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 //默認安裝在/usr/local/nagios根據提示信息,可能需要添加參數和依賴包,--enable-embedded-perl
rhel6.4包中沒有gd-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/* //設置權限
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主機
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{ 服務組并不是必須的,這是配合nagios 的監控頁面的顯示
servicegroup_name 系統負荷檢查
alias 負荷檢查
members ty1.org,進程總數,ty1.org,登錄用戶數,ty1.org,根分區,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 根分區
check_command check_local_disk!20%!10%!/
}
define service{
use local-service
host_name ty1.org
service_description 登錄用戶數
check_command check_local_users!20!50
}
define service{
use local-service
host_name ty1.org
service_description 進程總數
check_command check_local_procs!250!400!RSZDT
}
define service{
use local-service
host_name ty1.org
service_description 系統負荷
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 //校驗nagios配置文件正確性
htpasswd -m /usr/local/nagios/etc/htpasswd.users nagiosadmin //設置登錄nagios的用戶(nagiosadmin由自己定義)及密碼
/etc/init.d/nagios start
/etc/init.d/httpd restart
--------------------------------------------
nagios主機A遠程監控B主機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 //如下顯示則監控成功
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主機名
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主機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 //設置接受警報郵件的用戶,多個用戶用逗號分割
define contact{
email 849186008@qq.com
}
在QQ郵箱里將發送的賬戶(nagios@server97.example.com)加入白名單
B主機mysql服務器出現問題(nagios會先檢測四次,才會sendmail),就會給郵箱發郵件報警
--------------------------------------------------------------
NAGIOS_NRPE 實現遠端主機監控
使用nrpe(5666)實現對remote host基本服務(memory、CPU、login users等)的監控:
配置步驟可以通過解壓nrpe包在docs里有個nrpe.pdf
1、Remote Host Setup:
#tar xzf nagios-plugins-1.4.6.tar.gz
#cd nagios-plugins-1.4.6
#./configure //編譯完會顯示模塊情況,需要的安裝完后重新執行./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主監控ip,此處的優先級(會覆蓋)大于/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 /
//習慣指定磁盤檢測命令為這樣,其他的不變,此處根據自己而設定,可以不變,只檢測根目錄
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主機,-c指定命令,不加-c顯示nrpe版本信息
3、現在用命令已經可以檢測遠程主機系統信息,接下來配置nrpe命令,以便nagios能夠自動調用nrpe命令以web頁面顯示監控信息
#vi commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
#vi services.cfg //加入想要監控的serivce
define service{
use local-service
host_name ty.org
service_description 根分區
check_command check_nrpe!check_disk
}
define service{
use local-service
host_name ty.org
service_description 登錄用戶數
check_command check_nrpe!check_users
define servicegroup{ //可以將remote主機被監控的service加入服務組,只需將其host_name和service_description添加在members后邊即可
servicegroup_name 系統負荷檢查
alias 負荷檢查
members ty2.org,進程總數,ty2.org,登錄用戶數,ty2.org,根分區,ty2.org,交換空間利用率,ty.org,進程總數,ty.org,登錄用戶數,ty.org,根分區,ty.org,交換空間利用率
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //檢測配置文件語法
/etc/init.d/nagios reload
--------------------------------------------------------------
配置飛信機器人
需要包: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 //執行fetion命令,報錯需要裝依賴包,根據提示安裝
./fetion --mobile=****** --pwd=****** --to=****** --msg-utf8="haha" //測試fetion是否能成功發送信息
第一次要求輸入驗證碼,在/usr/local/nagios/libexec中
將fetion添加到配置文件,實現自動發送飛信
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
進入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默認端口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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。