Nagios監控安裝之一

來源:互聯網
上載者:User

標籤:成功   use   roc   clu   object   維護   desc   ams   引用   

配置nagios監控系統檔案
Nagios的設定檔:
Nagios.cfg:主設定檔,定義各種設定檔的名稱和位置
Cgi.cfg:控制CGI的設定檔
Resource.cfg:資源檔,定義各種變數,以便於其他檔案調用
Objects:其他設定檔存放目錄,此目錄下主要有:
Command.cfg:命令設定檔,定義各種命令格式,以備其他檔案調用
contacts.cfg:連絡人和組,發郵件等警示資訊時可以調用
localhost.cfg:監控原生設定檔
timeperiods.cfg:定義監控時間的設定檔,便於其他檔案調用
Hostgroups.cfg:定義監控的主機(組),需手動建立。

設定檔之間的關係

在nagios的配置過程中涉及的幾個定義有主機、主機群組、服務、服務組、連絡人、連絡人群組、監控時間和監控命令等。
從這些定義可以看出,nagios各個設定檔之間互為關聯、彼此引用的。成功配置出一台nagios監控系統,每個配置
檔案之間依賴與被依賴的關係,最重要的有四點:
1,定義監控那些主機,主機群組,服務和服務組
2,定義這個監控要用什麼命令實現
3,定義監控的時間段
4,定義主機或伺服器出現問題時要通知的連絡人和連絡人群組

配置nagios

為了能更清楚的說明問題,同時也為了維護方便,建議將nagios各個定義的對象建立獨立的設定檔。
建立conf目錄來定義host主機
建立hostgroups.cfg檔案來定義主機群組
用預設的contacts.cfg檔案來定義連絡人和連絡人群組
用預設的commands.cfg檔案來定義命令
用預設的timeperiods.cfg來定義監控時間段
用預設的templetes.cfg檔案作為資源引用檔案
安裝環境、軟體準備:
CentOS release 6.5 (Final)
nagios-3.5.1.tar.gz
nagios-plugins-1.4.16.tar.gz
nrpe-2.12.tar.gz
Nagios-Server 192.168.0.151 Client:192.168.0.152,192.168.0.150
正式安裝前準備:
1,配置YUM源
2,配置環境變數
[[email protected] soft]# echo ‘export LC_ALL=C‘>> /etc/profile
[[email protected] soft]# tail -1 /etc/profile
export LC_ALL=C
[[email protected] soft]# source /etc/profile
3,關閉防火牆、SELINUX
[[email protected] soft]# /etc/init.d/iptables stop
[[email protected] soft]# chkconfig iptables off
[[email protected] soft]# sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config
[[email protected] soft]# setenforce 0
4,配置定時任務
[[email protected] soft]# crontab -e
#time sync by tony at 2018-01-29
/5 /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
5,安裝gcc和lamp環境
[[email protected] soft]#yum install gcc glibc glibc-common -y
[[email protected] soft]#yum install gd gd-devel -y
[[email protected] soft]#yum install httpd php php-gd -y
[[email protected] soft]#yum install mysql
-y
6,添加使用者和使用者組
[[email protected] soft]# /usr/sbin/useradd -m nagios
[[email protected] soft]# /usr/sbin/useradd apache
[[email protected] soft]# /usr/sbin/groupadd nagcmd
[[email protected] soft]# /usr/sbin/usermod -a -G nagcmd nagios
[[email protected] soft]# /usr/sbin/usermod -a -G nagcmd apache
7,安裝Nagios-Core
[[email protected] soft]# tar xf nagios-3.5.1.tar.gz
[[email protected] soft]#cd nagios
[[email protected] nagios]# ./configure --with-command-group=nagcmd
[[email protected] nagios]# make all
[[email protected] nagios]# make install
[[email protected] nagios]# make install-init
[[email protected] nagios]# make install-config
[[email protected] nagios]# make install-commandmode
[[email protected] nagios]# make install-webconf
8,配置web認證:
[[email protected] nagios]# htpasswd -cb /usr/local/nagios/etc/htpasswd.users tony hwg123
Adding password for user tony
9,安裝Nagios外掛程式
[[email protected] soft]# yum -y install perl-devel
[[email protected] soft]# tar xf nagios-plugins-1.4.16.tar.gz
[[email protected] soft]# cd nagios-plugins-1.4.16
[[email protected] nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
[[email protected] nagios-plugins-1.4.16]#make && make install
[[email protected] nagios-plugins-1.4.16]#cd ../
[[email protected] soft]# ls /usr/local/nagios/libexec/|wc -l
10,安裝NRPE
[[email protected] soft]# tar xf nrpe-2.12.tar.gz
[[email protected] soft]# cd nrpe-2.12
[[email protected] nrpe-2.12]# ./configure
[[email protected] nrpe-2.12]# make all
[[email protected] nrpe-2.12]# make install-plugin
[[email protected] nrpe-2.12]# make install-daemon
[[email protected] nrpe-2.12]# make install-daemon-config
[[email protected] nrpe-2.12]# cd ../
11,啟動Nagios和Http
[[email protected] soft]# /etc/init.d/nagios start
[[email protected] soft]# /etc/init.d/httpd start
[[email protected] soft]# lsof -i :80

用戶端配置:
1,配置YUM源:
2,配置環境變數:
[[email protected] ~]# echo ‘export LC_ALL=C‘>> /etc/profile
[[email protected] ~]# tail -1 /etc/profile
export LC_ALL=C
[[email protected]lient ~]# source /etc/profile
3,關閉防火牆、SELINUX
[[email protected] soft]# /etc/init.d/iptables stop
[[email protected] soft]# chkconfig iptables off
[[email protected] soft]# sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config
[[email protected] soft]# setenforce 0
4,配置定時任務
[[email protected] soft]# crontab -e
#time sync by tony at 2018-01-29
/5 * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
5,
[[email protected] ~]# /usr/sbin/useradd -m nagios -s /sbin/nologin
6,上傳安裝包
[[email protected] nagios-plugins-1.4.16]# yum -y install perl-devel perl-CPAN
[[email protected] data]# tar xf nagios-plugins-1.4.16.tar.gz
[[email protected] data]# cd nagios-plugins-1.4.16
[[email protected] nagios-plugins-1.4.16]# ./configure --prefix=/usr/local/nagios --enable-perl-modules --enable-redhat-pthread-workaround
[[email protected] nagios-plugins-1.4.16]# make && make install
7,
[[email protected] nagios-plugins-1.4.16]# cd ../
[[email protected] data]# tar xf nrpe-2.12.tar.gz
[[email protected] data]# cd nrpe-2.12
[[email protected] nrpe-2.12]# ./configure
[[email protected] nrpe-2.12]# make all
[[email protected] nrpe-2.12]# make install-plugin
[[email protected] nrpe-2.12]# make install-daemon
[[email protected] nrpe-2.12]# make install-daemon-config
[[email protected] nrpe-2.12]# cd ..
8,安裝外掛程式監控磁碟IO
[[email protected] data]# tar xf Params-Validate-0.91.tar.gz
[[email protected] data]# cd Params-Validate-0.91
[[email protected] Params-Validate-0.91]#perl Makefile.PL
[[email protected] Params-Validate-0.91]# make
[[email protected] Params-Validate-0.91]# make install

[[email protected] data]# tar xf Class-Accessor-0.31.tar.gz
[[email protected] data]# cd Class-Accessor-0.31
[[email protected] Class-Accessor-0.31]# perl Makefile.PL
[[email protected] Class-Accessor-0.31]# make
[[email protected] Class-Accessor-0.31]# make install

[[email protected] data]# tar xf Config-Tiny-2.12.tar.gz
[[email protected] data]# cd Config-Tiny-2.12
[[email protected] Config-Tiny-2.12]# perl Makefile.PL
[[email protected] Config-Tiny-2.12]# make
[[email protected] Config-Tiny-2.12]# make install

[[email protected] data]# tar xf Math-Calc-Units-1.07.tar.gz
[[email protected] data]# cd Math-Calc-Units-1.07
[[email protected] Math-Calc-Units-1.07]# perl Makefile.PL
[[email protected] Math-Calc-Units-1.07]# make
[[email protected] Math-Calc-Units-1.07]# make install

[[email protected] data]# tar xf Regexp-Common-2010010201.tar.gz
[[email protected] data]# cd Regexp-Common-2010010201
[[email protected] Regexp-Common-2010010201]# perl Makefile.PL
[[email protected] Regexp-Common-2010010201]# make
[[email protected] Regexp-Common-2010010201]# make install
[[email protected] Regexp-Common-2010010201]# cd ..

[[email protected] data]# tar xf Nagios-Plugin-0.34.tar.gz
[[email protected] data]# cd Nagios-Plugin-0.34
[[email protected] Nagios-Plugin-0.34]# perl Makefile.PL
[[email protected] Nagios-Plugin-0.34]# make
[[email protected] Nagios-Plugin-0.34]# make install

[[email protected] data]# yum install sysstat -y
[[email protected] data]# /bin/cp ./check_memory.pl /usr/local/nagios/libexec
[[email protected] data]# /bin/cp ./check_iostat /usr/local/nagios/libexec
[[email protected] data]# chmod 755 /usr/local/nagios/libexec/check_memory.pl
[[email protected] data]# chmod 755 /usr/local/nagios/libexec/check_iostat
[[email protected] data]# dos2unix /usr/local/nagios/libexec/check_memory.pl
[[email protected] data]# dos2unix /usr/local/nagios/libexec/check_iostat

[[email protected] etc]# cp nrpe.cfg nrpe.cfg.ori
[[email protected] etc]# sed -i ‘199,203d‘ /usr/local/nagios/etc/nrpe.cfg
[[email protected] etc]#echo "command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c 30,25,20">>/usr/local/nagios/etc/nrpe.cfg
[[email protected] etc]#echo "command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c 3%">>/usr/local/nagios/etc/nrpe.cfg
[[email protected] etc]#echo "command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p /">>/usr/local/nagios/etc/nrpe.cfg
[[email protected] etc]#echo "command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%">>/usr/local/nagios/etc/nrpe.cfg
[[email protected] etc]#echo "command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10">>/usr/local/nagios/etc/nrpe.cfg
[[email protected] ~]# pkill nrpe
[[email protected] ~]# sleep 2
[[email protected] ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[[email protected] ~]# echo "#nagios nrpe process cmd by tony 2018-2-2" >> /etc/rc.local
[[email protected] ~]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d">>/etc/rc.local
[[email protected] ~]# netstat -lnt|grep 5666 && echo "nagios client is ok"
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
nagios client is ok

第三,配置server端Nagios監控服務
[[email protected] ~]# ll /usr/local/nagios/
total 32
drwxrwxr-x 2 nagios nagios 4096 Feb 1 22:33 bin #可執行檔
drwxrwxr-x 3 nagios nagios 4096 Feb 8 14:25 etc #Nagios主要設定檔
drwxr-xr-x 2 root root 4096 Feb 1 22:25 include
drwxrwxr-x 2 nagios nagios 4096 Feb 1 22:32 libexec
drwxr-xr-x 5 root root 4096 Feb 1 22:25 perl
drwxrwxr-x 2 nagios nagios 4096 Feb 1 22:09 sbin #cgi程式
drwxrwxr-x 11 nagios nagios 4096 Feb 1 22:25 share #Nagios展示程式PHP
drwxrwxr-x 5 nagios nagios 4096 Feb 8 21:57 var #資料及記錄檔

[[email protected] etc]# vim 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/services

Definitions for monitoring the local (Linux) host

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
1,主機服務
[[email protected] objects]# vim hosts.cfg
define host{
use linux-server
host_name 152-NFS
alias 152-NFS
address 192.168.0.152
}
define host{
use linux-server
host_name 151-Nagios
alias 152-Nagios
address 192.168.0.151
}

Define an optional hostgroup for Linux machines

define hostgroup{
hostgroup_name linux-servers
alias Linux Servers
members 152-NFS,151-Nagios
}

2,服務配置
[[email protected] objects]# vim services.cfg
define service {
use generic-service
host_name 152-NFS
service_description Disk Partition
check_command check_nrpe! check_disk

              }

define service {
use generic-service
host_name 152-NFS
service_description Swap Useage
check_command check_nrpe! check_swap

              }

define service {
use generic-service
host_name 152-NFS
service_description MEM Useage
check_command check_nrpe! check_mem

              }

define service {
use generic-service
host_name 151-Nagios
service_description Disk Partition
check_command check_nrpe! check_disk

              }

define service {
use generic-service
host_name 151-Nagios
service_description Swap Useage
check_command check_nrpe! check_swap

              }

define service {
use generic-service
host_name 151-Nagios
service_description MEM Useage
check_command check_nrpe! check_mem

              }

3,命令配置
[[email protected] objects]# vim commands.cfg
在設定檔結尾加上這些內容
#‘check_nrpe ‘command definintion
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Nagios監控安裝之一

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.