溫馨提示×

溫馨提示×

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

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

nagios安裝配置記錄

發(fā)布時間:2020-07-17 10:35:19 來源:網(wǎng)絡(luò) 閱讀:349 作者:影帝周星星 欄目:移動開發(fā)

一、創(chuàng)建nagios用戶和用戶組。

[root@localhost ~]#useradd -s /sbin/nologin nagios
[root@localhost ~]#mkdir /usr/local/nagios
[root@localhost ~]#chown -R nagios:nagios /usr/local/nagios

二、編譯安裝nagios

[root@localhost ~]# tar -zxvf nagios-3.5.0.tar.gz
[root@localhost ~]# cd nagios
[root@localhost nagios]#./configure --prefix=/usr/local/nagios
[root@localhost ~]# tar -zxvf nagios-3.5.0.tar.gz
[root@localhost ~]# cd nagios
[root@localhost nagios]#./configure --prefix=/usr/local/nagios
[root@localhost nagios]#make all
[root@localhost nagios]#make install
[root@localhost nagios]# make install-init #在/etc/rc.d/init.d目錄下創(chuàng)建nagios啟動腳本
[root@localhost nagios]# make install-config #安裝示例配置文件
[root@localhost nagios]# make install-commandmode #配置目錄權(quán)限

三、nagios目錄對應(yīng)功能說明:

   bin:可執(zhí)行程序所在目錄

   etc:配置文件所在目錄

   sbin:cgi文件所在目錄,也就是執(zhí)行外部命令所需文件所在目錄

   share:網(wǎng)頁文件所在目錄

   libexec:外部插件所在目錄

   var:日志文件,lock等文件所在目錄。修改日志文件時間格式,修改拷貝的文件(perl -i -pe '($t) = ($_ =~ m/^\[(\d+)\]/); $nice=scalar localtime $t; s/^\[(\d+)\]/[$nice]/'  nagios.log)

   var/archives:日志自動歸檔目錄

   var/rw:用來存放外部命令文件的目錄

四、安裝nagios插件。

[root@localhost ~]# tar -zxvf nagios-plugins-1.4.16.tar.gz
[root@localhost ~]# yum -y install openssl*
[root@localhost ~]# cd nagios-plugins-1.4.16
[root@localhost nagios-plugins-1.4.16]# ./configure --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.16]# make
[root@localhost nagios-plugins-1.4.16]# make install

五、安裝并配置httpd和php

[root@localhost ~]# yum -y install php httpd
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
User nagios
Group nagios
DirectoryIndex index.html index.html.var index.php
AddType application/x-httpd-php .php
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
        <Directory "/usr/local/nagios/sbin">
                AuthType Basic
                options ExecCGI
                AllowOverride None
                Order allow,deny
                Allow from all
                AuthName "Nagios Access"
                AuthUserFile /usr/local/nagios/etc/htpasswd
                Require valid-user
        </Directory>
Alias /nagios "/usr/local/nagios/share"
        <Directory "/usr/local/nagios/share">
                AuthType Basic
                Options None
                AllowOverride None
                Order allow,deny
                Allow from all
                AuthName "Nagios Access"
                AuthUserFile /usr/local/nagios/etc/htpasswd
                Require valid-user
        </Directory>
[root@localhost ~]# htpasswd -cm /usr/local/nagios /etc/htpasswd USER
[root@localhost ~]# service httpd restart
[root@localhost ~]# service nagios restart
#訪問http://ip/nagios 輸入用戶/密碼就可以看到nagios管理界面

六、安裝插件NRPE

[root@localhost ~]# tar -zxvf nrpe-2.14.tar.gz
[root@localhost ~]# cd nrpe-2.14
[root@localhost nrpe-2.14]# ./configure
[root@localhost nrpe-2.14]# make all
[root@localhost nrpe-2.14]# make install-plugin
[root@localhost ~]# cd /usr/local/nagios/etc
[root@localhost etc]# mkdir monitor
[root@localhost etc]# cp -R objects/* monitor/
[root@localhost etc]# vim monitor/commands.cfg
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
[root@localhost libexec]# ./check_nrpe -H 192.168.1.1 #檢查與被監(jiān)控對象的連通性

七、定義被監(jiān)控主機(jī)和服務(wù)。

[root@localhost ~]# vim /usr/local/nagios/etc/cgi.cfg #將用戶名修改為nagios界面登錄的用戶名
default_user_name=USER
[root@localhost ~]# vim /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/monitor  #注釋掉cfg_file開頭的行
[root@localhost ~]# vim /usr/local/nagios/etc/monitor/contacts.cfg  #需要指定聯(lián)系人才能實(shí)現(xiàn)監(jiān)控
define contact{
        contact_name                    USER   #必須改為http驗(yàn)證用戶  
        use                             generic-contact
        alias                           Nagios Admin   
        email                           admin@domain.com
        }
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 USER
        }
[root@localhost ~]# service postfix restart #重啟郵件服務(wù)
[root@localhost ~]# vim /usr/local/nagios/etc/monitor/hosts.cfg #定義主機(jī)
define host{
        use       windows-server   #引用模板windows-server的屬性信息
        host_name test-server      #主機(jī)命名
        alias     test             #別名
        address   ip_address       #ip地址
        }
define hostgroup{                  #必須定義組
        hostgroup_name  windows-servers
        alias           windows Servers
        members         test-server
        }
[root@localhost ~]# vim /usr/local/nagios/etc/monitor/services.cfg #定義服務(wù)
define service{
        use                      local-service
        host_name                test-server
        service_description      EXAMPLE
        check_command            check-host-alive
        }
[root@localhost ~]# cd /sbin
[root@localhost sbin]# ln -s /usr/local/nagios/bin/nagios nagios
[root@localhost sbin]# nagios -v /usr/local/nagios/etc/nagios.cfg #檢查主配置文件

八、客戶端安裝nrpe和nagios-plugin。

[root@localhost ~]# useradd nagios
[root@localhost ~]# yum -y install openssl
[root@localhost ~]# tar -zxvf nagios-plugins-1.4.16.tar.gz
[root@localhost ~]# cd nagios-plugins-1.4.16
[root@localhost nagios-plugins-1.4.16]# ./configure --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.16]# make&make install
check_http.c: In function ‘process_arguments’:
check_http.c:312: error: ‘ssl_version’ undeclared (first use in this function)
check_http.c:312: error: (Each undeclared identifier is reported only once
check_http.c:312: error: for each function it appears in.)
[root@localhost ~]# make clean  #清除掉之前make的殘余信息
[root@localhost ~]# ./configure  --prefix=/usr/local/nagios
[root@localhost ~]# make&make install
[root@localhost ~]# chown nagios:nagios /usr/local/nagios
[root@localhost ~]# chown -R nagios:nagios /usr/local/nagios/libexec/
[root@localhost ~]# tar -zxvf nrpe-2.14.tar.gz
[root@localhost ~]# cd nrpe-2.14
[root@localhost nrpe-2.14]# ./configure
[root@localhost nrpe-2.14]# make all
[root@localhost nrpe-2.14]# make install-plugin
[root@localhost nrpe-2.14]# make install-daemon
[root@localhost nrpe-2.14]# make install-daemon-config
[root@localhost nrpe-2.14]# make install-xinetd
[root@localhost ~]# vim /etc/xinetd.d/nrpe
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       = 127.0.0.1 192.168.1.10 #指定監(jiān)控主機(jī)的IP
}
[root@localhost ~]# vim /etc/services
nrpe            5666/tcp                # nrpe
[root@localhost ~]# service xinetd restart
[root@localhost ~]# /usr/local/nagios/libexec/check_nrpe -H localhost #測試本地nrpe daemon是否正常
[root@localhost ~]# vim /usr/local/nagios/etc/nrpe.cfg #添加監(jiān)控服務(wù)
command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1 -w 5 -c 10
#以下在服務(wù)端添加
[root@localhost ~]# vim /usr/local/nagios/etc/monitor/services.cfg
define service{
        use                      local-service
        host_name                test-linux
        service_description      linux
        check_command            check_nrpe!check_http
        }

九、配置Fetion短信報警。

[root@localhost ~]# tar -zxvf fetion20101113.tar.gz
[root@localhost ~]# cd fetion20101113
[root@localhost ~]# mv fetion /bin   #剪切主程序到/bin
[root@localhost ~]# mkdir /usr/local/fetion
[root@localhost ~]# mv fetion20101113/* /usr/local/fetion/
[root@localhost ~]# vim /etc/ld.so.conf.d/fetion.conf
/usr/local/fetion     #指向Fetion的庫文件目錄
[root@localhost ~]# ldconfig  #重新讀取庫文件
[root@localhost ~]# fetion --help   #測試命令是否可執(zhí)行
[root@localhost ~]# yum -y install libgcc_s.so.1 #安裝缺失的庫文件
[root@localhost ~]# fetion --mobile=10086 --pwd=123456 --to=10010 --msg-utf8=Test --debug  #發(fā)送測試短信,接收人必須是飛信好友,首次發(fā)送需填寫驗(yàn)證碼:/bin/10086.jpg
[root@nagios ~]# vim /usr/local/nagios/etc/monitor/commands.cfg  #修改commands配置文件
# 'notify-host-by-fetion' command definition
define command{
          command_name    notify-host-by-fetion
          command_line    /bin/fetion --mobile=10086 --pwd=123456 --to=$CONTACTPAGER$ --msg-utf8="***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"
                }
# 'notify-service-by-fetion' command definition
define command{
        command_name    notify-service-by-fetion
        command_line    /bin/fetion --mobile=10086 --pwd=123456 --to=$CONTACTPAGER$ --msg-utf8="***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n"
                }
[root@nagios ~]# vim /usr/local/nagios/etc/monitor/contacts.cfg   #修改聯(lián)系人配置文件
define contact{
        contact_name                    Tom
        use                             generic-contact
        alias                           Monitor user
        email                           Tom@gmail.com
        service_notification_commands   notify-service-by-fetion
        host_notification_commands      notify-host-by-fetion
        pager                           10086   #手機(jī)號碼
        }
define contact{
        contact_name                    Tony
        use                             generic-contact
        alias                           Monitor user
        email                           Tony@gmail.com
        service_notification_commands   notify-service-by-fetion
        host_notification_commands      notify-host-by-fetion
        pager                           10010
        }
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 Tom,Tony
        }
[root@localhost ~]#


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

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

AI