溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發(fā)布時間:2020-06-01 19:50:01 來源:網(wǎng)絡 閱讀:805 作者:邱月濤 欄目:移動開發(fā)

寫這個文檔的目的,就是為了方便 快捷的部署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 (檢測配置文件是否有錯誤)


{ [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


二、創(chuàng)建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 用戶 沒有執(zhí)行權限 /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***************************************************


在被監(jiān)控機器上安裝。


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  //在后面增加監(jiān)控主機的地址,以空格間隔


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 清空一下規(guī)則,然后保存。

然后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 被監(jiān)控端IP地址       測試是否連接成功





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

pkill nrpe;

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



二、添加監(jiān)控節(jié)點及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:新建立文件夾及節(jié)點無法生效


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

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

添加 要檢測的目錄。

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



問題2:《《apache 啟動失敗 》》  默認安裝在/usr/sbin/下,執(zhí)行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




于是上網(wǎng)查了一下,根據(jù)前人的經驗,問題終于解決了??偨Y一下,方便以后使用。


原因:這個問題應該是沒有在 /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

然后發(fā)送測試郵件,驗證sendmail的可用性:

# echo "Hello World" | mail abc@abc.com



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設為聯(lián)系人

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

      define contact{

                     contact_name                   qiuyuetao

                     use                                      generic-contact

                    alias                                     qyt

            }

        (4)在屬于userA的主機、服務配置文件的聯(lián)系人中加入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


向AI問一下細節(jié)

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

AI