nagios3.2.0搭建過程

很久沒有更新博客了,記錄下我在生產環境下安裝nagios3.2.0,

一、nagios 的安裝

1.1 基礎支持套件

1)gcc glibc glibc-common gd gd-devel xinetd openssl-devel

# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

2)部署lamp環境 yum install httpd mysql mysql-server php php-mysql -y ,或源碼安裝

1.2 創建nagios用戶和用戶組

# /usr/sbin/useradd -m nagios

# /usr/sbin/useradd apache -M -s /sbin/nologin

# /usr/sbin/groupadd nagcmd

# /usr/sbin/usermod -a -G nagcmd nagios

# /usr/sbin/usermod -a -G nagcmd apache

1.3 編譯安裝nagios

# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.0/nagios-3.2.0.tar.gz/download

# tar zxvf nagios-3.2.0.tar.gz

# cd nagioss-3.2.0

# ./configure --prefix=/usr/local/nagios --with-group=nagios --with-user=nagios --with-command-group=nagcmd

# make all

# make install

# make install-init

# make install-config

# make install-commandmode

# make install-webconf

驗證程序是否被正確安裝

切換目錄到安裝路徑(這裏是/usr/local/nagios),看是否存在etc、bin、sbin、share、var 這五個目錄,

1.4 設置開機自起

# chkconfig --add nagios

# chkconfig nagios on

1.5 安裝nagios插件

# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz

# tar zxvf nagios-plugins-1.4.15.tar.gz

# cd nagios-plugins-1.4.15

# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules

# make && make install

1.6 創建apache目錄驗證文件

# htpasswd -c /usr/local/nagios/etc/htpasswd nagios

1.7 給nagios用戶開權限,讓他能夠查看信息

# vim /usr/local/nagios/etc/cgi.cfg 在所有的nagiosadmin後面添加nagios用,隔開

:%s/nagiosadmin/nagiosadmin\,nagios/g

到這裏nagios 的安裝也就基本完成了,啓動apache,你可以通過web來訪問了

1.8 定義監控項 在/usr/local/nagios/etc/objects目錄下

時間timeperiods.cfg 配置文件

define timeperiod{

timeperiod_name 24x7

alias 24 Hours A Day, 7 Days A Week

sunday 00:00-24:00

monday 00:00-24:00

tuesday 00:00-24:00

wednesday 00:00-24:00

thursday 00:00-24:00

friday 00:00-24:00

saturday 00:00-24:00

}

插件commands.cfg

define command{

command_name check-host-alive

command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5

}

監控誰localhost.cfg

define host {

host_name fudong

alias test

address 0.0.0.0

check_command check-host-alive

notification_options d,u,r

check_interval 1

max_check_attempts 2

contact_groups admins

notification_interval 10

notification_period 24x7

}

聯繫人contacts.cfg

define contact {

contact_name kyo

alias kyo

host_notification_period 24x7

host_notification_options d,u,r

service_notification_period 24x7

service_notification_options w,u,c,r

service_notification_commands notify-service-by-email

host_notification_commands notify-host-by-email

email [email protected]

}

define contactgroup{

contactgroup_name admins

alias Nagios Administrators

members nagiosadmin,kyo

}

1.9 檢查錯誤

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


二、監控遠程主機nrpe插件的安裝(被監控主機上的)

2.1 解決perl編譯問題與時間同步

# echo "export LC_ALL=C">>/etc/profile

# source /etc/profile

# /usr/sbin/ntpdate pool.ntp.org

# uptime

2.2 安裝Nagios所需要的基礎軟件包

# yum install gcc glibc glibc-common gd gd-devdel openssl-devel -y

2.3 建立nagios用戶

# useradd nagios

2.4 安裝插件

# tar zxvf nagios-plugins-1.4.15.tar.gz

# cd nagios-plugins-1.4.15

# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios

# make && make install

2.5 安裝NRPE

# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz

# tar zxvf nrpe-2.13.tar.gz

# cd nrpe-2.13

# ./configure

# make all

# make install-plugin #監控機需要安裝check_nrpe 這個插件,被監控機並不需要,

# make install-daemon

# make install-daemon-config

# make install-xinetd

2.6 在被監控機上開啓nrpe

# vim /etc/xinetd.d/nrpe

# default: on

# description: NRPE (Nagios Remote Plugin Executor)

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 = 192.168.18.254 #監控主機的ip,保證他可以連接進來!

}

2.7 編輯/etc/services 文件,增加NRPE服務

# vim /etc/services

nrpe 5666/tcp

# service xinetd restart

2.8 查看NRPE是否啓動與測試

# netstat -an |grep 5666

# /usr/local/nagios/libexec/check_nrpe -H 192.168.18.188

NRPE v2.12 返回當前NRPE的版本 也就是在本地用check_nrpe連接nrpe daemon是正常的。

注:爲了後面工作的順利進行,注意本地防火牆要打開5666能讓外部的監控機訪問。

# iptables -I INPUT -p tcp --dport 5666 -j ACCEPT

2.9 查看NRPE的監控命令

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

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_u]=/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_hda1]=/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

通過以上字段來定義命令,以及接收命令後執行的插件。

重啓nagios服務








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