nagios監控windows及linux從而實現飛信報警

nagios主要功能是實現報警

yum環境搭建:

[root@localhost~]#mount/dev/cdrom/mnt/cdrom/

mount:blockdevice/dev/cdromiswrite-protected,mountingread-only

[root@localhost~]#vim/etc/yum.repos.d/rhel-debuginfo.repo

[rhel-server]

name=RedHatEnterpriseLinuxserver

baseurl=file:///mnt/cdrom/Server

enabled=1

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

安裝步驟

安裝lamp環境

yuminstallmysqlmysql-develhttpdphpphp-gdphp-mbstring

測試lamp環境

創建一個組nagcmd

[[email protected]]#groupaddnagcmd

創建一個賬號nagios

[[email protected]]#useradd-mnagios

加入組

[[email protected]]#usermod-a-Gnagcmdnagios

將apache賬號也添加進來

[[email protected]]#usermod-a-Gnagcmdapache

解壓縮

cdnagios-cn-3.2.3

配置

./configure--with-command-group=nagcmd--enable-event-broker

或者

./configure--with-command-group=nagcmd--prefix=/usr/local/nagios--sysconfdir=/etc/nagios--enable-event-broker

[email protected]]#makeall

[[email protected]]#makeinstall

(-Thisinstallstheinitscriptin/etc/rc.d/init.d)

makeinstall-commandmode

-Thisinstallsandconfigurespermissionsonthe

directoryforholdingtheexternalcommandfile

makeinstall-config

-Thisinstallssampleconfigfilesin/usr/local/nagios/etc

進入nagios目錄

cd/usr/local/nagios/

在http服務器的配置目錄(conf.d)下形成nagiosweb程序

cdnagios-cn-3.2.3

makeinstall-webconf

創建一個登陸nagiosweb程序的用戶這個賬號在以後通過web登陸nagios認證時使用

htpasswd-c/usr/local/nagios/etc/htpasswd.usersnagiosadmin

啓動apache

servicehttpdstartchkconfighttpdon

安裝nagios插件

./configure(perfix=/usr/local/nagios)--with-nagios-user=nagios--with-nagios-group=nagios

或者

./configure--with-nagios-user=nagios--with-nagios-group=nagios

make

makeinstall

將nagios服務加入chkconfig管理之類

chkconfig--addnagios

chkconfig--addnagios

檢查nagios的配置文件的語法是否正確

/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg

可以將/usr/local/nagios/bin加入命令搜索路徑中

vim.bashrc

..bashrc重新讀取環境文件

可以將/usr/local/nagios/etc/nagios.cfg設置爲一個連接

ln-s/usr/local/nagios/etc/nagios.cfg/etc/nagios.cfg

檢查語法

nagios-v/etc/nagios.cfg

啓動nagios服務

啓動httpd服務

編輯vim/usr/local/nagios/etc/nagios.cfg

註釋36行#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

重啓nagios會報錯,原因,是無可監控

打開該文件中的其他主機比如windows

39cfg_file=/usr/local/nagios/etc/objects/windows.cfg

重啓服務

windows檢測客戶端配置

Snmp161

Nsclienrt12489check_nt

Nrpe5666

naclient改變裏面的ns.ini

然後從其windows上的ncclient

在nagios服務器上,更改object下的window。dfg定義

重啓nagios服務

134231414.png

134231307.png

134232212.png

134232412.png

linux客戶段安裝

先創建賬號nagios

[root@localhost~]#yuminstallmysqlmysql-serverhttpdmysql-devel

[root@localhost~]#useraddnagios

安裝插件

./configure(perfix=/usr/local/nagios)--with-nagios-user=nagios--with-nagios-group=nagios

或者

./configure--with-nagios-user=nagios--with-nagios-group=nagios

make&&makeinstall

安裝nrpe(客戶端和服務端都需要)

#tar-zxvfnrpe-2.12.tar.gz

#cdnrpe-2.12.tar.gz

#./configure--with-nrpe-user=nagios\

--with-nrpe-group=nagios\

--with-nagios-user=nagios\

--with-nagios-group=nagios\

--enable-command-args\

--enable-ssl

#makeall

#makeinstall-plugin

#makeinstall-daemon

#makeinstall-daemon-config

編輯客戶端nrpe配置文件

vim/usr/local/nagios/etc/nrpe.cfg

(allowed_hosts=192.168.101.102(服務器地址))

以進程的方式啓動nrpe

/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d

nrpe服務器段

1.#./configure--with-nrpe-user=nagios\

--with-nrpe-group=nagios\

--with-nagios-user=nagios\

--with-nagios-group=nagios\

--enable-command-args\

--enable-ssl

#makeall

#makeinstall-plugin

2.commands.cfg定義外部構件nrpe

vim/usr/local/nagios/etc/objects/commands.cfg

增加

definecommand{

command_namecheck_nrpe

command_line$USER1$/check_nrpe-H$HOSTADDRESS$-c$ARG1$

}

3.爲了監控linux系統修改nagios.cfg

vim/usr/local/nagios/etc/nagios.cfg

添加一行

cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg

4.在/usr/local/nagios/etc/objects創建mylinux.cfg

definehost{

uselinux-server;Inheritdefaultvaluesfromatemplate

host_namemylinux;Thenamewe'regivingtothishost

aliasmylinux;Alongernameassociatedwiththehost

address192.168.101.110;IPaddressofthehost

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck-swap

check_commandcheck_nrpe!check_swap

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck_load

check_commandcheck_nrpe!check_load

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck-disk

check_commandcheck_nrpe!check_had1

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck_user

check_commandcheck_nrpe!check_users

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck_procs

check_commandcheck_nrpe!check_total_procs

}

改變數組

chownnagios.nagiosmylinux.cfg

5實現飛信報警

腳本(附件下載)

a、將飛信的文檔傳入linux系統,將庫文件放入/usr/lib目錄

chmoda+xfetion

b、使用下列命令測試./fetion--mobile=15136848083--pwd=lsx885--to15136848083--msg-type=0--msg-utf8$HOSTNAME

c.編輯vim/usr/local/nagios/etc/objects/contacts.cfg(這個文件可以不修改)

vim/usr/local/nagios/etc/objects/templates.cfg

34service_notification_commandsnotify-service-by-fetion;sendservicenotificationsviaemail

35host_notification_commandsnotify-service-by-fetion;sendhostnotificationsviaemail

d。定義命令

vim/usr/local/nagios/etc/objects/commands.cfg

definecommand{

command_namenotify-service-by-fetion

command_line/usr/bin/fetion--mobile=15136848083--pwd=lsx885--to15136848083--msg-type=0--msg-utf8$HOSTNAME

}

check_nrpe語法:

check_nrpe...-c<command>[-a<argument><argument><argument>]

check_nrpe的內置命令:

·CheckAlwaysCRITICAL(check)

·CheckAlwaysOK(check)

·CheckAlwaysWARNING(check)

·CheckCPU(check)

·CheckCRITICAL(check)

·CheckCounter(check)

·CheckEventLog/CheckEventLog(check)

·CheckFile(check)

·CheckFileSize(check)

·CheckMem(check)

·CheckMultiple(check)

·CheckOK(check)

·CheckProcState(check)

·CheckServiceState(check)

·CheckTaskSched/CheckTaskSched(check)

·CheckUpTime(check)

·CheckVersion(check)

·CheckWARNING(check)

·CheckWMI/CheckWMI(check)

·CheckWMIValue(check)

用法如:

#check_nrpe...-cCheckCPU-awarn=80crit=90time=20mtime=10stime=4

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章