Centos6.5-----nagios快速安裝編譯配置文檔-全部虛擬環境

來源:互聯網
上載者:User

標籤:軟體   naigos   nrpe   

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

一、下載並安裝所需軟體

 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 (檢測設定檔是否有錯誤)


{ [[email protected] libexec]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers/

[[email protected] 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.   [[email protected] nagios-plugins-1.4.13]# htpasswd -c /usr/local/nagios/etc/htpasswd test

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

65.   查看認證檔案的內容

66.   [[email protected] 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]



[email protected] 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

     [[email protected] ~]# htpasswd /usr/local/nagios/etc/htpasswd.users  qiuyuetao

   (2)更改cgi.cfg配置

     [[email protected] ~]# 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設為連絡人

     [[email protected] ~]# vi /usr/local/nagios/etc/objects/contacts.cfg  #添加如下配置

      define contact{

                     contact_name                   qiuyuetao

                     use                                      generic-contact

                    alias                                     qyt

            }

        (4)在屬於userA的主機、服務組態檔的連絡人中加入qiuyuetao

         [[email protected] ~]# vi /usr/local/nagios/etc/objects/hosts.cfg

           define host {

              host_name [email protected]

              alias [email protected]

              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後生效

        [[email protected] ~]#  /etc/init.d/nagios restart


本文出自 “實用筆記” 部落格,請務必保留此出處http://qiuyt.blog.51cto.com/1229789/1580093

Centos6.5-----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.