CentOS 6.5下快速安裝編譯配置Nagios文檔

CentOS 6.5下快速安裝編譯配置Nagios文檔-全部虛擬環境。

寫這個文檔的目的,就是爲了方便 快捷的部署Nagios,涉及到個人喜好的配置,大家自行修改,可以套用。

網絡監控器Nagios全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios搭建與配置詳解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx環境下構建Nagios監控平臺 http://www.linuxidc.com/Linux/2011-07/38112.htm

在RHEL5.3上配置基本的Nagios系統(使用Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios監控端和被控端安裝配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安裝 Nagios Core 網絡監控運用 http://www.linuxidc.com/Linux/2013-11/93047.htm

一、下載並安裝所需軟件

1,yum install gcc mysql httpd php gd openssl openssl-devel mysql-server vim wget

Wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.7.tar.gz

Wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

Wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

Ls 可以看到nagios-4.0.7.tar.gz nagios-plugins-2.0.3.tar.gz nrpe-2.14.tar.gz

yum install wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp

useradd nagios

passwd nagios

groupadd nagcmd

usermod –a –G nagcmd nagios

(nagcmd:x:504:nagios)

tar –xvzf nagios-4.0.7.tar.gz

cd nagios-4.0.7

./configure –with-command-group=nagcmd

可以先./configure –help先看看幫助,應爲默認爲主是用nagios用戶,不需要指定—with-nagios-user或其它什麼的。

make all

make install

make install-init

這個安裝/etc/rc.d/init.d中的init腳本

make install-commandmode

這個安裝和配置權限

  目錄的外部命令文件

make install-config

這個安裝* * /usr/local/nagios/etc配置文件示例

  你必須修改這些示例文件之前

  使用Nagios。閱讀HTML文檔

make install-webconf

 這個安裝Nagios的Apache配置文件

  Web界面

Cp –R contrib/eventhandlers/ /usr/local/nagios/libexec/

(-R:遞歸複製目錄,即連同目錄下的子目錄和文件一起復制。)

Chown –R nagios:nagios /usr/local/nagios/libexec/eventhandlers

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (檢測配置文件是否有錯誤)

{ [root@Nagios libexec]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers/

[root@Nagios libexec]# ll

total 4

drwxr-xr-x. 4 nagios nagios 4096 Oct 21 01:16 eventhandlers}

/etc/init.d/nagios start 或者service nagios start

Chkconfig --add nagios

Chkconfig nagios on

Chkconfig httpd on

Service httpd start

二、創建web用戶

切換到ngios用戶

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

輸入密碼nagios

三、安裝nagios-plugins

Tar –xvzf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins-2.0.3

./configure {–with-nagios-user=nagios –with-nagios-group=nagios}

Make

Make install

前面這步做了可以略過,反正要做一次。

Chkconfig nagios on 或者chkconfig –level 35 nagios on

Chkconfig httpd on 或者 chkconfig –level 35 httpd on

四、關閉防火牆和selinux

service iptables stop

Vim /etc/sysconfig/selinux 把selinux改成disabled這個需重啓生效。

http://192.168.1.202/nagios/ 這個是nagios地址,要輸入用戶名和密碼的nagiosadmin nagios

******無法開題notifications報錯****************************************

Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!

這個主要是apache 用戶 沒有執行權限 /usr/local/nagios/var/rw/nagios.cmd 造成,

解決方法:

usermod -a -G nagcmd apache

將apache用戶添加到nagios用戶組,就OK了。

date -s 調整日期時間  clock -w 保存

五、安裝NRPE插件。

Tar –xvzf nrpe-2.14.tar.gz

Cd nrpe-2.14

./configure

make && make install

make install-plugin

把check_nrpe放到/usr/local/nagios/libex下。才能使用check_nrpe。

***********************************************************************************

*********************************2***************************************************

在被監控機器上安裝。

Nagios-plugins安裝.

Useradd nagios

Passwd nagios

Tar –xvzf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins

./configure

Make

Make install

Chown –R nagios:nagios /usr/local/nagios

安裝nrpe-2.14

Tar –xvzf nrpe-2.14.tar.gz

Cd nrpe-2.14

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

yum install xinetd

chkconfig --add xinetd

chkconfig xinetd on

make install-xinetd

vim /etc/xinetd.d/nrpe

在該文件的only_from  = 127.0.0.1 192.168.1.107  //在後面增加監控主機的地址,以空格間隔

vim /usr/local/nagios/etc/nrpe.cfg 這裏也是充許訪問裏添加 192.168.107

vim /etc/services

啓動nrpe就好了。

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

service xinetd restart

netstat -at |grep nrpe

Netstat –an | grep 5666

Vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT (該語句有待,不過我另一臺也是這樣配的)

好像不添加上面這個不得行,會報check_nrpe:Error - Could not complete SSL handshake

運行ipables –F 清空一下規則,然後保存。

然後iptables –L –n 查看確認後。

Service iptables save

Service iptables restart

2、配置文件方面:

(1)/usr/local/nagios/etc/nrpe.cfg 此配置文件是配置正確,多個IP地址逗號隔開,且要注意空格:allowed_host=127.0.0.1,  192.168.0.1 這是不對的,必須是allowed_host=127.0.0.1,192.168.1.202  逗號之後不能有空格;

(2)檢查是否配置裏限制了,在 /etc/xinetd.d/nrpe 文件中要添加允許訪問的服務器的IP地址,在 “only_from = ” 這一行添加, 多個IP地址用空格隔開,例如:only_from      = 192.168.0.8 192.168.1.202

被控端:

vi /etc/xinetd.d/nrpe

only_from 增加主控IP

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

allowed_hosts 增加主控IP

service xinetd restart

主控端:

/usr/local/nagios/libexec/check_nrpe -H 被監控端IP地址      測試是否連接成功

修改nrpe.cfg後一定要重啓nrpe,大俠我是這樣做的:

pkill nrpe;

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

一、添加監控節點及service

二、增加驗證用戶

也就是通過web訪問nagios的時候,必須要用這個用戶登陸.在這裏我們增加用戶test:密碼爲12345

64.  [root@localhost nagios-plugins-1.4.13]# htpasswd -c /usr/local/nagios/etc/htpasswd test

可以用 which命令查看 htpasswd命令的位置,如果是源碼安裝的apache這裏就寫htpasswd的全路徑。用戶是test,命令結束會提示你輸入密碼,這裏輸入123456即可。

65.  查看認證文件的內容

66.  [root@localhost nagios-plugins-1.4.13]# less /usr/local/nagios/etc/htpasswd

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


三、檢測定義快捷命令

問題1:新建立文件夾及節點無法生效

解決:修改nagios目錄文件,使其目錄被檢測

vi /usr/local/nagios/etc/nagios.cfg

添加 要檢測的目錄。

cfg_dir=/usr/local/nagios/etc/cfgs

問題2:《《apache 啓動失敗 》》  默認安裝在/usr/sbin/下,執行apachectl start時候,提示如下錯誤:

httpd: apr_sockaddr_info_get() failed for shiwei

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

於是上網查了一下,根據前人的經驗,問題終於解決了。總結一下,方便以後使用。

原因:這個問題應該是沒有在 /etc/httpd/conf/httpd.conf 中設定 ServerName。所以apache會用主機上的名稱來取代,首先會去找 /etc/hosts 中有沒有主機的定義。

解決辦法:

(1)可以設定httpd.conf文件中的 ServerName,如下:ServerName localhost:80

(2)在 /etc/hosts 中填入自己的主機名稱 bogon,如下:127.0.0.1 shiwei (用戶名稱)

問題3 NRPE: Unable to read output

我的解決辦法是:修改nagios目錄的權限

#chown -R nagios:nagios nagios/

#chmod -R 775 nagios/

問題解決。linux

四、添加command

command[check_cpu]=/usr/local/nagios/libexec/check_cpu_pct -w $ARG1$ -c $ARG2$

command[check_memory]=/usr/local/nagios/libexec/check_mem -w $ARG1$ -c $ARG2$

將配置文件拷貝到指定目錄後,修改所屬及訪問權限。

command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$

command[check_swap]=/usr/local/nagios/libexec/check_swap -w $ARG1$ -c $ARG2$228

command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$

command[check_io]=/usr/local/nagios/libexec/check_iostat -d $ARG3$ -w $ARG1$ -c $ARG2$

五、安裝sendmail

首先要確保sendmail相關組件的完整安裝,我們可以使用如下的命令來完成sendmail的安裝:

# yum install -y sendmail*

然後重新啓動sendmail服務:

# service sendmail restart

然後發送測試郵件,驗證sendmail的可用性:

# echo "Hello World" | mail [email protected]

Root@Nagios objects]# service sendmail restart

Shutting down sendmail:                                    [FAILED]

Starting sendmail:                                        [  OK  ]

Starting sm-client:                                        [  OK  ]

chkconfig sendmail off

chkconfig sendmail off  加速開機時間

重啓服務器注意1,開機nrpe 二啓動sendmail 三 iptables 設置


Nagios 多用戶的一些配置

剛開始我想到在搭nagios的時候,用戶驗證是用apache來做的,接到這個需求後的第一反應是這個東西可能做不了。但接着一想,不應該啊,nagios本身至少會有一些用戶配置的吧,於是乎開始尋找相關資料,基本配置如下:

(1)新增一個apache用戶,如qiuyuetao

[root@service3F-38 ~]# htpasswd /usr/local/nagios/etc/htpasswd.users  qiuyuetao

(2)更改cgi.cfg配置

[root@service3F-38 ~]# vi /usr/local/nagios/etc/cgi.cfg

use_authentication=1

如果只允許查看,不允許管理,加上下面配置

authorized_for_read_only=qiuyuetao

authorized_for_all_services=qiuyuetao

authorized_for_all_hosts=qiuyuetao

(3)將userA設爲聯繫人

[root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/contacts.cfg  #添加如下配置

define contact{

contact_name                  qiuyuetao

use                                      generic-contact

alias                                    qyt

}

(4)在屬於userA的主機、服務配置文件的聯繫人中加入qiuyuetao

[root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/hosts.cfg

define host {

host_name web02-1.22@sh

alias web02-1.22@sh

address 10.1.1.22

contacs qyt

contact_groups sys_admins

check_command check-host-alive

max_check_attempts 5

notification_interval  3

notification_period 24x7

notification_options d,u,r

}

(5)重啓nagios後生效

[root@service3F-38 ~]#  /etc/init.d/nagios restart


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