溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

nagios的安裝配置方法

發(fā)布時(shí)間:2021-07-22 23:42:01 來源:億速云 閱讀:329 作者:chen 欄目:移動(dòng)開發(fā)

這篇文章主要講解了“nagios的安裝配置方法”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“nagios的安裝配置方法”吧!

簡單介紹下nagios

開源網(wǎng)絡(luò)監(jiān)控

監(jiān)控的分類:

狀態(tài)的連續(xù)監(jiān)控:對(duì)實(shí)時(shí)狀態(tài)進(jìn)行監(jiān)控。

狀態(tài)的變化監(jiān)控:但某一時(shí)刻監(jiān)控的狀態(tài)發(fā)生變化時(shí),就進(jìn)行匯報(bào)。

nagios是一款遵循GPLV2的開源網(wǎng)絡(luò)監(jiān)控軟件,可用來監(jiān)控制定的多種系統(tǒng)的主機(jī)、服務(wù),并在它們的工作狀態(tài)發(fā)生變化時(shí)通知管理員。

1)監(jiān)控網(wǎng)絡(luò)服務(wù)(HTTP/POP3/SMTP/PING/MYSQL等)

2)監(jiān)控主機(jī)資源(磁盤利用率、內(nèi)存利用率、CPU負(fù)載等)

3)簡潔的插件設(shè)計(jì)接口,使得用戶可以輕松開發(fā)所需的檢測(cè)腳本(運(yùn)維則可直接找到相關(guān)腳本并使用)

4)并行服務(wù)模式

5)輕松描述網(wǎng)絡(luò)結(jié)構(gòu),并且能夠區(qū)辨“宕機(jī)”和“主機(jī)不可達(dá)”

6)通過郵件或用戶自定義的方式將主機(jī)或服務(wù)的工作狀態(tài)變化情況通知給管理員

7)當(dāng)服務(wù)或主機(jī)問題產(chǎn)生與解決時(shí)將告警發(fā)送給聯(lián)系人(通過EMail/短信、用戶定義方式)

8)自動(dòng)日志滾動(dòng)

9)可以通過web方式直觀的查看當(dāng)前網(wǎng)絡(luò)狀態(tài)、通知和問題歷史、日志文件等,此組件為可選

undefined

Nagios通常由一個(gè)主程序(Nagios)、一個(gè)插件程序(Nagios-plugins)和四個(gè)可選的ADDON(NRPE/NSCA/NSCLIENT++和NDOUTILS)組成。

NRPE:用來在監(jiān)控的的遠(yuǎn)程LINUX/UNIX主機(jī)上執(zhí)行腳本插件以實(shí)現(xiàn)對(duì)這些主機(jī)資源的監(jiān)控;

              試驗(yàn)中用到的版本是NRPE-2.1.2.tar.gz

NSCA:用來讓被監(jiān)控的遠(yuǎn)程Linux/Unix主機(jī)主動(dòng)將監(jiān)控信息發(fā)送給Nagios服務(wù)器(這在冗余監(jiān)控模式中,特別要用到)

NSCLIENT++:用來監(jiān)控Windows主機(jī)時(shí)安裝在Windows主機(jī)上的組件;

NDOUTILS:則用來將NAGIOS的配置信息和各EVETN產(chǎn)生的數(shù)據(jù)存入數(shù)據(jù)庫,以實(shí)現(xiàn)對(duì)這些數(shù)據(jù)的快速檢索和處理;


NAGIOS是通過配置文件來驅(qū)動(dòng)這個(gè)監(jiān)控流程,因?yàn)樗械膬?nèi)容都是可配置的,所以也就非常靈活,功能自然也就槍彈,把太多的工作留給使用者。

1、新添加監(jiān)控主機(jī)

要修改localhost.cfg或windows.cfg配置文件

這里的默認(rèn)路徑為/usr/local/nagios/etc/objects/localhost.cfg或者/usr/local/nagios/etc/objects/windows.cfg

2、調(diào)整監(jiān)控的命令

要修改commands.cfg配置文件

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

3、要更改聯(lián)系人的信息

要修改contacts.cfg配置文件

/usr/local/nagios/etc/objects/contacts.cfg

4、要調(diào)整監(jiān)控時(shí)間

要修改timeperiods.cfg配置文件

/usr/local/nagios/etc/objects/contacts.cfg

5、添加具體的監(jiān)控服務(wù)

要修改services.cfg配置文件,這里信息都是來自其他配置文件的

6、存放相關(guān)的命令執(zhí)行腳本

/usr/local/nagios/libexecls

7、/usr/local/nagios/etc/objects/commands.cfg 定義相關(guān)命令


yum 源安裝配置

vi /etc/yum.repos.d/Centos-Media.repo

[xscl]

baseurl=file:///mnt/cdrom/

gpgcheck=0

enabled=1

:wq


安裝nagios必須的基本組件的運(yùn)行依賴于httpd、gcc和gd.

yum clean all

準(zhǔn)備工作:

  1. yum -y install  httpd*  php

  2. yum -y install gcc glibc glibc-common

  3. yum -y install gd gd-devel


groupadd nagcmd

useradd -m nagios

usermod -a -G nagcmd nagios

# usermod -a -G nagcmd apache

#j將apache用戶加入nagcmd組使之工作時(shí)具有足夠的權(quán)限

下載所需要的安裝組件:

服務(wù)器端所用的安裝包:nagios   nagios-plugins  ndoutils(非必須)

linux客戶端:nrpe

windows客戶端:NSCLIENT

創(chuàng)建用戶:

chkconfig httpd on

useradd   nagios

cd /root

上傳軟件包我這里下載的nagios-3.3.1.tar.gz

tar-xzvf nagios-3.3.1.tar.gz

cd nagios

#./configure --with-command-group=nagcmd

make  install

報(bào)錯(cuò)解決方法如下:

今天安裝nagios3.3.1,不是第一次安裝了,之前都很順利,這次安裝的時(shí)候,在執(zhí)行命令make install的時(shí)候,報(bào)錯(cuò)了。大致如下  


  1. [root@magedunagios]#makeinstall

  2. cd./base&&makeinstall

  3. make[1]:Enteringdirectory`/root/nagios/base'

  4. makeinstall-basic

  5. make[2]:Enteringdirectory`/root/nagios/base'

  6. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/bin

  7. /usr/bin/install-c-m774-onagios-gnagiosnagios/var/www/html/nagios/bin

  8. /usr/bin/install-c-m774-onagios-gnagiosnagiostats/var/www/html/nagios/bin

  9. make[2]:Leavingdirectory`/root/nagios/base'

  10. makestrip-post-install

  11. make[2]:Enteringdirectory`/root/nagios/base'

  12. /usr/bin/strip/var/www/html/nagios/bin/nagios

  13. /usr/bin/strip/var/www/html/nagios/bin/nagiostats

  14. make[2]:Leavingdirectory`/root/nagios/base'

  15. make[1]:Leavingdirectory`/root/nagios/base'

  16. cd./cgi&&makeinstall

  17. make[1]:Enteringdirectory`/root/nagios/cgi'

  18. makeinstall-basic

  19. make[2]:Enteringdirectory`/root/nagios/cgi'

  20. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/sbin

  21. forfilein*.cgi;do\

  22. /usr/bin/install-c-m775-onagios-gnagios$file/var/www/html/nagios/sbin;\

  23. done

  24. make[2]:Leavingdirectory`/root/nagios/cgi'

  25. makestrip-post-install

  26. make[2]:Enteringdirectory`/root/nagios/cgi'

  27. forfilein*.cgi;do\

  28. /usr/bin/strip/var/www/html/nagios/sbin/$file;\

  29. done

  30. make[2]:Leavingdirectory`/root/nagios/cgi'

  31. make[1]:Leavingdirectory`/root/nagios/cgi'

  32. cd./html&&makeinstall

  33. make[1]:Enteringdirectory`/root/nagios/html'

  34. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share

  35. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/media

  36. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/stylesheets

  37. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/contexthelp

  38. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/docs

  39. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/docs/p_w_picpaths

  40. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/p_w_picpaths

  41. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/p_w_picpaths/logos

  42. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/includes

  43. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/includes/rss

  44. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/includes/rss/extlib

  45. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/ssi

  46. /usr/bin/install-c-m664-onagios-gnagiosrobots.txt/var/www/html/nagios/share

  47. rm-f/var/www/html/nagios/share/index.html

  48. rm-f/var/www/html/nagios/share/main.html

  49. rm-f/var/www/html/nagios/share/side.html

  50. forfilein*.php;\

  51. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share;done

  52. forfileinstylesheets/*.css;\

  53. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/stylesheets;done

  54. forfileincontexthelp/*.html;\

  55. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/contexthelp;done

  56. forfileinp_w_picpaths/*.gif;\

  57. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths;done

  58. forfileinp_w_picpaths/*.jpg;\

  59. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths;done

  60. forfileinp_w_picpaths/*.png;\

  61. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths;done

  62. forfileinp_w_picpaths/*.ico;\

  63. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths;done

  64. forfileinp_w_picpaths/logos/*.*;\

  65. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths/logos;done

  66. forfileinincludes/*.*;\

  67. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/includes;done

  68. forfileinincludes/rss/*;\

  69. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/includes/rss;done

  70. /usr/bin/install:omittingdirectory`includes/rss/extlib'

  71. /usr/bin/install:omittingdirectory`includes/rss/htdocs'

  72. /usr/bin/install:omittingdirectory`includes/rss/scripts'

  73. make[1]:***[install]Error1

  74. make[1]:Leavingdirectory`/root/nagios/html'

  75. make:***[install]Error2


很糾結(jié)啊,google了一下,有解決方案,好像是makefile里有語法錯(cuò)誤,具體怎么導(dǎo)致的不清楚,執(zhí)行完以下命令,就OK了

  1. # sed-i's:forfileinincludes/rss/\*;:forfileinincludes/rss/\*.\*;:g'./html/Makefile

  2. # sed-i's:forfileinincludes/rss/extlib/\*;:forfileinincludes/rss/extlib/\*.\*;:g'./html/Makefile

  3. 然后,執(zhí)行以下命令,來完成安裝

預(yù)配置Nagios主程序的環(huán)境以及指定安裝路徑
[root@nagios-3.3.1]# ./configure --prefix=/usr/local/nagios
預(yù)配置成功后將返回配置環(huán)境信息
----------------------------------------------------
*** Configuration summary for nagios 2.9 04-10-2007 ***:

General Options:
-------------------------
       Nagios executable:  nagios
       Nagios user/group:  nagios,nagios
      Command user/group:  nagios,nagios
           Embedded Perl:  no
            Event Broker:  yes
       Install ${prefix}:  /usr/local/nagios
               Lock file:  ${prefix}/var/nagios.lock
          Init directory:  /etc/rc.d/init.d
                 Host OS:  linux-gnu

Web Interface Options:
------------------------
                HTML URL:  http://localhost/nagios/
                 CGI URL:  http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):  /bin/traceroute


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

請(qǐng)注意看最后的提示,如果對(duì)以上反饋信息接受的話,則需要繼續(xù)執(zhí)行“make all”命令來編譯主程序以及CGI。


.編譯Nagios主程序
[root@KCentOS5C nagios-2.9]# make all
Nagios主程序編譯成功后將返回信息
-----------------------------------------------------
*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
如果在編譯當(dāng)中沒有發(fā)生錯(cuò)誤的話,那么可以照以下這些命令繼續(xù)操作。

 make install
    - This installs the main program, CGIs, and HTML files
 執(zhí)行“make install”命令來對(duì)主程序,CGI以及HTML網(wǎng)頁進(jìn)行安裝。

 make install-init
    - This installs the init script in /etc/rc.d/init.d
 執(zhí)行“install-init”命令來在/etc/rc.d/init.d/目錄中安裝啟動(dòng)腳本。

 make install-commandmode
    - This installs and configures permissions on the
      directory for holding the external command file
 執(zhí)行“install-commandmode”命令來安裝和配置外部命令對(duì)Nagios主路徑操作的權(quán)限。(這里所謂的外部命令主要是指Apache服務(wù)通過CGI來對(duì)Nagios的進(jìn)行的操作。用戶將通過Web以執(zhí)行CGI程序腳本的方式來對(duì)Nagios的檢測(cè)結(jié)果進(jìn)行讀取和調(diào)用。)

 make install-config
    - This installs *SAMPLE* config files in /usr/local/nagios/etc
      You'll have to modify these sample files before you can
      use Nagios.  Read the HTML documentation for more info
      on doing this.  Pay particular attention to the docs on
      object configuration files, as they determine what/how
      things get monitored!
 執(zhí)行“make install-config”命令將會(huì)在/usr/local/etc/這個(gè)Nagios編譯安裝的主配置路徑下安裝示例配置模板,這將對(duì)于之后的配置制定幫助很大。

*** Support Notes *******************************************
這些關(guān)于支持的信息就不再詳細(xì)講了

If you have questions about configuring or running Nagios,
please make sure that you:

    - Look at the sample config files
    - Read the HTML documentation
    - Read the FAQs online at http://www.nagios.org/faqs

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:

    - What version of Nagios you are using
    - What version of the plugins you are using
    - Relevant snippets from your config files
    - Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

http://www.nagios.org/support/

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

Enjoy.
-----------------------------------------------------


5.安裝Nagios主程序、CGI以及網(wǎng)頁
[root@KCentOS5C nagios-2.9]# make install
安裝完Nagios主程序、CGI和網(wǎng)頁的之后將提示安裝成功信息以及剩余可操作的步驟
-----------------------------------------------------
*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

 make install-init
    - This installs the init script in /etc/rc.d/init.d

 make install-commandmode
    - This installs and configures permissions on the
      directory for holding the external command file

 make install-config
    - This installs *SAMPLE* config files in /usr/local/nagios/etc
      You'll have to modify these sample files before you can
      use Nagios.  Read the HTML documentation for more info
      on doing this.  Pay particular attention to the docs on
      object configuration files, as they determine what/how
      things get monitored!
-----------------------------------------------------


6.安裝Nagios的系統(tǒng)啟動(dòng)腳本
[root@KCentOS5C nagios-2.9]# make install-init
安裝完Nagios的系統(tǒng)啟動(dòng)腳本之后將提示腳本安裝成功信息以及剩余可操作的步驟
-----------------------------------------------------
*** Init script installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

 make install-commandmode
    - This installs and configures permissions on the
      directory for holding the external command file

 make install-config
    - This installs *SAMPLE* config files in /usr/local/nagios/etc
      You'll have to modify these sample files before you can
      use Nagios.  Read the HTML documentation for more info
      on doing this.  Pay particular attention to the docs on
      object configuration files, as they determine what/how
      things get monitored!
-----------------------------------------------------


7.將Nagios的啟動(dòng)腳本添加到系統(tǒng)服務(wù)當(dāng)中去
[root@KCentOS5C ~]# chkconfig --add nagios

8.將Nagios服務(wù)加入到系統(tǒng)啟動(dòng)服務(wù)當(dāng)中去
[root@KCentOS5C ~]# chkconfig nagios on

9.安裝和配置外部命令對(duì)Nagios主路徑的操作權(quán)限
[root@KCentOS5C nagios-2.9]# make install-commandmode
安裝配置外操作權(quán)限后將提示配置成功信息以及剩余可操作步驟
-----------------------------------------------------
*** External command directory configured ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

 make install-config
    - This installs *SAMPLE* config files in /usr/local/nagios/etc
      You'll have to modify these sample files before you can
      use Nagios.  Read the HTML documentation for more info
      on doing this.  Pay particular attention to the docs on
      object configuration files, as they determine what/how
      things get monitored!
-----------------------------------------------------


10.將Apache服務(wù)宿主用戶加到nagios組里面
這樣做是為了讓Apache有適當(dāng)?shù)臋?quán)限能夠通過CGI腳本程序?qū)agios進(jìn)行調(diào)用,否則Apache將沒有權(quán)限調(diào)用Nagios,用戶通過Web將無法訪問Nagios處理的所有信息。
[root@KCentOS5C nagios-2.9]# usermod -G n apache


11.安裝Nagios的配置模板
[root@KCentOS5C nagios-2.9]# make install-config
安裝完畢Nagios的配置模板后將反饋安裝成功的提示信息。
-----------------------------------------------------
*** Sample config file installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

If you have questions about configuring Nagios properly, please:
      - Look at the sample config files
      - Read the HTML documentation
      - Read the FAQs online at http://www.nagios.org/faqs
*BEFORE* you post a question to one of the mailing lists.
-----------------------------------------------------


為email指定您想用來接收nagios警告信息的郵件地址,默認(rèn)是本機(jī)的nagios用戶:

# vi /usr/local/nagios/etc/objects/contacts.cfg

email        nagios@localhost       #這個(gè)是默認(rèn)設(shè)置

# make install-webconf

#在/etc/httpd/conf.d/nagios.conf生成web相關(guān)配置文件,用于定義nagios使用的CGI選項(xiàng),web的身份認(rèn)證等

[root@station71 nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

New password:

Re-type new password:

Adding password for user nagios

#為nagios的web頁面創(chuàng)建賬號(hào)密碼,對(duì)訪問進(jìn)行身份認(rèn)證

service httpd restart

chkconfig httpd on

啟動(dòng)httpd,并設(shè)置開機(jī)啟動(dòng)

進(jìn)入Nagios-plugins插件包目錄
[root@KCentOS5C ~]# cd nagios-plugins-1.4.10

3.預(yù)配置Nagios-plugin插件程序的環(huán)境以及指定安裝路徑

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

[root@ nagios-plugins-1.4.10]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql預(yù)配置完成的話將會(huì)建立Makefile并反饋檢測(cè)系統(tǒng)環(huán)境的結(jié)果。
-----------------------------------------------------
config.status: creating po/Makefile
           --with-apt-get-command:
             --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
              --with-ping-command: /bin/ping -n -U -w %d -c %d %s
                      --with-ipv6: yes
                     --with-mysql: no
                   --with-openssl: yes
                    --with-gnutls: no
                      --with-perl: /usr/bin/perl
            --enable-perl-modules: no
                    --with-cgiurl: /nagios/cgi-bin
              --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
-----------------------------------------------------

4.編譯Nagios-plugin插件程序
[root@KCentOS5C nagios-plugins-1.4.10]# make

5.安裝Nagios-plugin插件程序

[root@KCentOS5C nagios-plugins-1.4.10]# make install

6.查看安裝情況

[root@KCentOS5C nagios-plugins-1.4.10]# ll /usr/local/nagios/

-----------------------------------------------------
total 28
drwxrwxr-x 2 nagios nagios 4096 Oct  5 13:25 bin
drwxrwxr-x 2 nagios nagios 4096 Oct  5 19:03 etc
drwxr-xr-x 2 root   root   4096 Oct  5 19:07 libexec
drwxrwxr-x 2 nagios nagios 4096 Oct  5 13:25 sbin
drwxrwxr-x 9 nagios nagios 4096 Oct  5 19:07 share
drwxrwxr-x 4 nagios nagios 4096 Oct  5 19:08 var

-----------------------------------------------------

只要Nagios主路徑下出現(xiàn)libexec目錄就說明安裝成功了,這個(gè)目錄里面存放著就是Nagios插件執(zhí)行程序。但是有個(gè)問題,就是剛安裝好會(huì)有一些目錄和文件的屬主是root。這里的libexec就有這個(gè)問題。

4.編譯Nagios-plugin插件程序
[root@KCentOS5C nagios-plugins-1.4.10]# make

5.安裝Nagios-plugin插件程序

[root@KCentOS5C nagios-plugins-1.4.10]# make install

6.查看安裝情況

[root@KCentOS5C nagios-plugins-1.4.10]# ll /usr/local/nagios/

-----------------------------------------------------
total 28
drwxrwxr-x 2 nagios nagios 4096 Oct  5 13:25 bin
drwxrwxr-x 2 nagios nagios 4096 Oct  5 19:03 etc
drwxr-xr-x 2 root   root   4096 Oct  5 19:07 libexec
drwxrwxr-x 2 nagios nagios 4096 Oct  5 13:25 sbin
drwxrwxr-x 9 nagios nagios 4096 Oct  5 19:07 share

drwxrwxr-x 4 nagios nagios 4096 Oct  5 19:08 var

7/ cd /usr/local/nagios/libexec

ll

[root@localhost libexec]# ll

total 6436

-rwxr-xr-x. 1 root root 376516 Jun  4 19:06 check_apt

-rwxr-xr-x. 1 root root   2254 Jun  4 19:06 check_breeze

-rwxr-xr-x. 1 root root 128392 Jun  4 19:06 check_by_ssh

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_clamd -> check_tcp

-rwxr-xr-x. 1 root root  85678 Jun  4 19:06 check_cluster

-r-sr-xr-x. 1 root root 123723 Jun  4 19:06 check_dhcp

-rwxr-xr-x. 1 root root 121722 Jun  4 19:06 check_dig

-rwxr-xr-x. 1 root root 417871 Jun  4 19:06 check_disk

-rwxr-xr-x. 1 root root   9148 Jun  4 19:06 check_disk_smb

-rwxr-xr-x. 1 root root 129579 Jun  4 19:06 check_dns

-rwxr-xr-x. 1 root root  80681 Jun  4 19:06 check_dummy

-rwxr-xr-x. 1 root root   3056 Jun  4 19:06 check_file_age

-rwxr-xr-x. 1 root root   6318 Jun  4 19:06 check_flexlm

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_ftp -> check_tcp

-rwxr-xr-x. 1 root root 123705 Jun  4 19:06 check_hpjd

-rwxr-xr-x. 1 root root 519173 Jun  4 19:06 check_http

-r-sr-xr-x. 1 root root 133809 Jun  4 19:06 check_icmp

-rwxr-xr-x. 1 root root  93400 Jun  4 19:06 check_ide_smart

-rwxr-xr-x. 1 root root  15137 Jun  4 19:06 check_ifoperstatus

-rwxr-xr-x. 1 root root  12601 Jun  4 19:06 check_ifstatus

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_imap -> check_tcp

-rwxr-xr-x. 1 root root   6890 Jun  4 19:06 check_ircd

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_jabber -> check_tcp

-rwxr-xr-x. 1 root root 106623 Jun  4 19:06 check_ldap

lrwxrwxrwx. 1 root root     10 Jun  4 19:06 check_ldaps -> check_ldap

-rwxr-xr-x. 1 root root 106565 Jun  4 19:06 check_load

-rwxr-xr-x. 1 root root   6020 Jun  4 19:06 check_log

-rwxr-xr-x. 1 root root  20287 Jun  4 19:06 check_mailq

-rwxr-xr-x. 1 root root  93126 Jun  4 19:06 check_mrtg

-rwxr-xr-x. 1 root root  92471 Jun  4 19:06 check_mrtgtraf

-rwxr-xr-x. 1 root root 129508 Jun  4 19:06 check_mysql

-rwxr-xr-x. 1 root root 122490 Jun  4 19:06 check_mysql_query

-rwxr-xr-x. 1 root root 105598 Jun  4 19:06 check_nagios

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_nntp -> check_tcp

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_nntps -> check_tcp

-rwxr-xr-x. 1 root root 127807 Jun  4 19:06 check_nt

-rwxr-xr-x. 1 root root 130198 Jun  4 19:06 check_ntp

-rwxr-xr-x. 1 root root 119287 Jun  4 19:06 check_ntp_peer

-rwxr-xr-x. 1 root root 117856 Jun  4 19:06 check_ntp_time

-rwxr-xr-x. 1 root root 159492 Jun  4 19:06 check_nwstat

-rwxr-xr-x. 1 root root   8324 Jun  4 19:06 check_oracle

-rwxr-xr-x. 1 root root 109022 Jun  4 19:06 check_overcr

-rwxr-xr-x. 1 root root 105553 Jun  4 19:06 check_pgsql

-rwxr-xr-x. 1 root root 132787 Jun  4 19:06 check_ping

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_pop -> check_tcp

-rwxr-xr-x. 1 root root 396825 Jun  4 19:06 check_procs

-rwxr-xr-x. 1 root root 106620 Jun  4 19:06 check_real

-rwxr-xr-x. 1 root root   9584 Jun  4 19:06 check_rpc

-rwxr-xr-x. 1 root root   1412 Jun  4 19:06 check_sensors

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_simap -> check_tcp

-rwxr-xr-x. 1 root root 445174 Jun  4 19:06 check_smtp

-rwxr-xr-x. 1 root root 447023 Jun  4 19:06 check_snmp

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_spop -> check_tcp

-rwxr-xr-x. 1 root root 103128 Jun  4 19:06 check_ssh

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_ssmtp -> check_tcp

-rwxr-xr-x. 1 root root 108201 Jun  4 19:06 check_swap

-rwxr-xr-x. 1 root root 158985 Jun  4 19:06 check_tcp

-rwxr-xr-x. 1 root root 105150 Jun  4 19:06 check_time

lrwxrwxrwx. 1 root root      9 Jun  4 19:06 check_udp -> check_tcp

-rwxr-xr-x. 1 root root 117678 Jun  4 19:06 check_ups

-rwxr-xr-x. 1 root root  83418 Jun  4 19:06 check_users

-rwxr-xr-x. 1 root root   2939 Jun  4 19:06 check_wave

-rwxr-xr-x. 1 root root 109707 Jun  4 19:06 negate

-rwxr-xr-x. 1 root root 103234 Jun  4 19:06 urlize

-rwxr-xr-x. 1 root root   1939 Jun  4 19:06 utils.pm

-rwxr-xr-x. 1 root root   2728 Jun  4 19:06 utils.sh

8、

7.遞歸更改Nagios主路徑的屬主

[root@KCentOS5C nagios-plugins-1.4.10]# chown -R nagios.nagios /usr/local/nagios/

8.遞歸增加Nagios主路徑同組用戶讀寫屬性

[root@KCentOS5C nagios-plugins-1.4.10]# chmod -R g+wr /usr/local/nagios/

四.配置Apache服務(wù):
1.備份Apache服務(wù)的主配置文件
[root@KCentOS5C ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup

2.配置Apache服務(wù)的主配置文件
[root@KCentOS5C ~]# vi /etc/httpd/conf/httpd.conf
這里主要改動(dòng)以下這些參數(shù):
-----------------------------------------------------
ServerName *:80

配置Apache的服務(wù)器名,如果有域名的話請(qǐng)?zhí)顚懻_的服務(wù)器名。

Include conf.d/*.conf

確認(rèn)Apache擴(kuò)展配置文件的存放路徑。
-----------------------------------------------------


3.察看Nagios網(wǎng)頁配置模板文件
[root@KCentOS5C ~]# less nagios-2.9/sample-config/httpd.conf
-----------------------------------------------------
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file.  Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

設(shè)定了Nagios的CGI執(zhí)行目錄對(duì)應(yīng)的系統(tǒng)路徑。

<Directory "/usr/local/nagios/sbin">
#  SSLRequireSSL
  Options ExecCGI
  AllowOverride None
  Order allow,deny
  Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
  AuthName "Nagios Access"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd.users

這里指定了訪問用戶帳戶庫文件。
  Require valid-user
</Directory>

Alias /nagios "/usr/local/nagios/share"

設(shè)定了Nagios的網(wǎng)頁URL對(duì)應(yīng)的系統(tǒng)路徑。

<Directory "/usr/local/nagios/share">
#  SSLRequireSSL
  Options None
  AllowOverride None
  Order allow,deny
  Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
  AuthName "Nagios Access"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd.users

這里指定了訪問用戶帳戶庫文件
  Require valid-user
</Directory>
-----------------------------------------------------
基本上這個(gè)文件可以直接使用。根據(jù)這個(gè)配置文件中指定的AuthUserFile項(xiàng),它指定的是通過Apache訪問Nagios的合法用戶的帳戶名單庫文件,需要使用htpasswd命令對(duì)這個(gè)名單庫進(jìn)行用戶的添加。而默認(rèn)安裝環(huán)境下在/usr/local/nagios/etc/目錄下是沒有htpasswd.user這個(gè)文件的,所以需要手動(dòng)添加。請(qǐng)?zhí)貏e注意,用root身份建立的htpasswd.user文件的權(quán)限問題,應(yīng)該在建立該文件完畢后立即更改為nagios用戶nagios組的所有權(quán),并且要增加Nagios同組用戶讀寫權(quán)限。


4.整合Nagios網(wǎng)頁配置文件到Apache中
將Nagios網(wǎng)頁配置文件作為Apache的擴(kuò)展配置文件復(fù)制改名到Apache的擴(kuò)展配置文件目錄/etc/httpd/conf.d/目錄下
[root@KCentOS5C ~]# cp nagios-2.9/sample-config/httpd.conf /etc/httpd/conf.d/nagios-httpd.conf

5.建立Nagios的網(wǎng)頁訪問用戶帳戶文件(這里必須要與Nagios網(wǎng)頁配置文件當(dāng)中AuthUserFile指定的路徑文件名一致)
[root@KCentOS5C ~]# touch /usr/local/nagios/etc/htpasswd.user

6.更改Nagios網(wǎng)頁訪問用戶帳戶文件的屬主
[root@KCentOS5C ~]# chown nagios.nagios /usr/local/nagios/etc/htpasswd.users

7.對(duì)Nagios網(wǎng)頁訪問用戶帳戶文件增加同組成員讀寫權(quán)限(這主要是賦給apache這個(gè)系統(tǒng)用戶)
[root@KCentOS5C ~]# chmod g+wr /usr/local/nagios/etc/htpasswd.users

8.察看Nagios網(wǎng)頁訪問用戶帳戶文件的屬性信息
[root@KCentOS5C ~]# ll /usr/local/nagios/etc/htpasswd.users
-rw-rw-r-- 1 nagios nagios 0 Oct  5 14:05 /usr/local/nagios/etc/htpasswd.users

9.添加htpasswd.user用戶
我添加了一個(gè)kanecruise用戶,口令是123456。
[root@KCentOS5C ~]# htpasswd -m /usr/local/nagios/etc/htpasswd.user kanecruise
------------------------------------------------------------
New password: 123456
Re-type new password: 123456
Adding password for user kanecruise
------------------------------------------------------------


10.察看htpasswd的使用方法,這里我就解釋一些比較重要和常用的。
[root@KCentOS5C ~]# htpasswd
-------------------------------------------------------------
Usage:
       htpasswd [-cmdpsD] passwordfile username
       htpasswd -b[cmdpsD] passwordfile username password
       htpasswd -n[mdps] username
       htpasswd -nb[mdps] username password

-c  Create a new file.
    建立新的帳戶庫文件。

-n  Don't update file; display results on stdout.

-m  Force MD5 encryption of the password.
    添加一個(gè)MD5口令加密的新用戶。

-d  Force CRYPT encryption of the password (default).

-p  Do not encrypt the password (plaintext).
    添加一個(gè)口令不加密的新用戶。

-s  Force SHA encryption of the password.
    添加一個(gè)SHA口令加密的新用戶。

-b  Use the password from the command line rather than prompting for it.

-D  Delete the specified user.
    刪除一個(gè)指定的用戶

On Windows, NetWare and TPF systems the '-m' flag is used by default.
在Windows、NetWare以及TPF這些操作系統(tǒng)中“-m”參數(shù)(啟用MD5對(duì)口令加密)是默認(rèn)使用的
On all other systems, the '-p' flag will probably not work.
在其他的所有操作系統(tǒng)中“-p”(不對(duì)口令啟用加密)參數(shù)將可能會(huì)引起失敗。
-------------------------------------------------------------


11.檢查htpasswd帳戶文件
[root@KCentOS5C ~]# cat /usr/local/nagios/etc/htpasswd.users
-------------------------------------------------------------
kanecruise:$apr1$Qwk9h/..$HaRakpabADGZL10dwPcrx1
-------------------------------------------------------------
用戶添加正確,并且口令都以MD5的方式加密了。

五.Nagios的配置文件:
默認(rèn)下Nagios編譯安裝后都沒有現(xiàn)成的配置文件,它們都以模板配置文件的方式在/usr/local/nagios/etc/這個(gè)主配置路徑下,需要手動(dòng)復(fù)制并配置成可用的配置文件。

1.處理Nagios的主配置文件
Nagios的主配置文件為nagios.cfg。
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/nagios.cfg-sample /usr/local/nagios/etc/nagios.cfg

2.配置Nagios的主配置文件
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/nagios.cfg
主要修改和確認(rèn)以下幾個(gè)較重要的配置項(xiàng),其余的類似優(yōu)化涉及到的配置調(diào)整這里暫不交待了。這次不像上回我用RPM包安裝Nagios那次的配置方式,這次我打算將所有Nagios功能定義配置都集中在localhost.cfg這一個(gè)文件當(dāng)中去,而命令定義文件commands.cfg獨(dú)立保存一個(gè)文件,因此除了這兩個(gè)文件不注釋外,其他的Nagios功能定義文件都保持注釋狀態(tài)。
-------------------------------------------------------------
log_file=/usr/local/nagios/var/nagios.log
確認(rèn)Nagios服務(wù)的日志記錄文件,需要確認(rèn)此項(xiàng)是解注狀態(tài)的。默認(rèn)編譯安裝后沒有該文件,要手動(dòng)添加并指定適當(dāng)?shù)淖x寫權(quán)限。

cfg_file=/usr/local/nagios/etc/commands.cfg
在Nagios中將對(duì)應(yīng)功能插件定義成命令的命令定義文件,需要確認(rèn)此項(xiàng)是解注狀態(tài)的。默認(rèn)編譯安裝后也沒有該文件,需要從模版復(fù)制。

cfg_file=/usr/local/nagios/etc/localhost.cfg
設(shè)定Naigos對(duì)象功能定義的配置文件,需要確認(rèn)此項(xiàng)是解注狀態(tài)的。默認(rèn)編譯安裝后也沒有該文件,需要從模版復(fù)制。

cfg_file=/usr/local/nagios/etc/resource.cfg

設(shè)定Nagios的資源文件,需要確認(rèn)此項(xiàng)是解注狀態(tài)的。默認(rèn)編譯安裝后也沒有該文件,需要從模版復(fù)制。

#cfg_file=/usr/local/nagios/etc/contactgroups.cfg
#cfg_file=/usr/local/nagios/etc/contacts.cfg
#cfg_file=/usr/local/nagios/etc/dependencies.cfg
#cfg_file=/usr/local/nagios/etc/escalations.cfg
#cfg_file=/usr/local/nagios/etc/hostgroups.cfg
#cfg_file=/usr/local/nagios/etc/hosts.cfg
#cfg_file=/usr/local/nagios/etc/services.cfg
#cfg_file=/usr/local/nagios/etc/timeperiods.cfg
#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
以上這些分塊功能的定義配置文件需要保持注釋,因?yàn)檫@些文件的作用都已經(jīng)集中到localhost.cfg這一個(gè)文件當(dāng)中去了。

nagios_user=nagios
nagios_group=nagios
設(shè)定Nagios服務(wù)的宿主用戶和組。

#check_external_commands=0
check_external_commands=1
設(shè)定Nagios外部檢查命令功能開關(guān),默認(rèn)是值0。將原來的注釋掉,更改為值1,必須要打開該功能,否則CGI將不能調(diào)用。

command_check_interval=15s
#command_check_interval=-1
設(shè)定命令檢查的時(shí)間間隔,將原來值-1的項(xiàng)注釋掉,啟用原來備用值為15s(15秒)。這項(xiàng)的時(shí)間間隔值請(qǐng)按實(shí)際需求情況設(shè)定。
-------------------------------------------------------------

對(duì)Nagios的主日志文件的操作如下:

手動(dòng)建立Nagios主日志文件
[root@KCentOS5C ~]# touch /usr/local/nagios/var/nagios.log


改變Nagios主日志文件的屬主。

[root@KCentOS5C ~]# chown nagios.nagios /usr/local/nagios/var/nagios.log


添加同組成員的讀寫權(quán)限。

[root@KCentOS5C ~]# chmod g+rw /usr/local/nagios/var/nagios.log


查看日志文件的屬性。

[root@KCentOS5C ~]# ll /usr/local/nagios/var/nagios.log
-rw-rw-r-- 1 nagios nagios 0 Oct  5 15:28 /usr/local/nagios/var/nagios.log


3.處理Nagios的CGI配置文件:
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/cgi.cfg-sample /usr/local/nagios/etc/cgi.cfg

4.配置Nagios的CGI配置文件
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/cgi.cfg
這里主要注意關(guān)于訪問用戶身份驗(yàn)證的配置項(xiàng)的設(shè)定。Nagios系統(tǒng)將各種操作行為的授權(quán)用戶分的非常的仔細(xì),所以在實(shí)際應(yīng)用當(dāng)中可以分的非常細(xì),什么用戶可以做哪些操作而哪些用戶又沒有權(quán)限做哪些操作。但是這里我只簡單的授權(quán)給同一個(gè)用戶。請(qǐng)?zhí)貏e注意,這里的授權(quán)用戶的對(duì)象必須只能夠是在htpasswd中添加注冊(cè)過的用戶。
-------------------------------------------------------------
use_authentication=1
設(shè)定啟用身份驗(yàn)證。

authorized_for_system_information=kanecruise
設(shè)定系統(tǒng)信息的授權(quán)用戶。

authorized_for_configuration_information=kanecruise
設(shè)定配置信息的授權(quán)用戶。

authorized_for_system_commands=kanecruise
設(shè)定系統(tǒng)命令的授權(quán)用戶。

authorized_for_all_services=kanecruise
設(shè)定全部監(jiān)測(cè)服務(wù)的授權(quán)用戶。

authorized_for_all_hosts=kanecruise
設(shè)定全部被監(jiān)測(cè)主機(jī)的授權(quán)用戶。

authorized_for_all_service_commands=kanecruise
設(shè)定全部監(jiān)測(cè)服務(wù)命令的授權(quán)用戶。

authorized_for_all_host_commands=kanecruise
設(shè)定全部主機(jī)命令的授權(quán)用戶。
-------------------------------------------------------------

5.處理Nagios的命令定義文件
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/commands.cfg-sample /usr/local/nagios/etc/commands.cfg

6.處理Nagios的資源文件

[root@KCentOS5C ~]# cp /usr/local/nagios/etc/resource.cfg-sample /usr/local/nagios/etc/resource.cfg


目前來說暫時(shí)不需要對(duì)Nagios命令定義文件做什么修改。但是如果要添加新的命令或者修改現(xiàn)有命令的定義的話,則需要修改該文件。

感謝各位的閱讀,以上就是“nagios的安裝配置方法”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)nagios的安裝配置方法這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI