centos7 部署安装nagios

 

部署lap环境

Centos7安装epel源:

1 rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

 

[root@juny-10 ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

1 yum clean all && yum list

 

安装所需要的依赖

1 yum install gcc glibc glibc-common php gd gd-devel libpng libmng libjeg zlib -y

 

已安装:

  gd-devel.x86_64 0:2.0.35-26.el7           libmng.x86_64 0:1.0.10-14.el7           php.x86_64 0:5.4.16-42.el7         

 

作为依赖被安装:

  expat-devel.x86_64 0:2.1.0-10.el7_3                          fontconfig-devel.x86_64 0:2.10.95-11.el7                 

  freetype-devel.x86_64 0:2.4.11-15.el7                        httpd.x86_64 0:2.4.6-67.el7.centos.6           

  httpd-tools.x86_64 0:2.4.6-67.el7.centos.6                   libX11-devel.x86_64 0:1.6.5-1.el7    

  libXau-devel.x86_64 0:1.0.8-2.1.el7                          libXpm-devel.x86_64 0:3.5.12-1.el7                       

  libjpeg-turbo-devel.x86_64 0:1.2.90-5.el7                    libpng-devel.x86_64 2:1.5.13-7.el7_2                     

  libxcb-devel.x86_64 0:1.12-1.el7                             libzip.x86_64 0:0.10.1-8.el7        

  mailcap.noarch 0:2.1.41-2.el7                                php-cli.x86_64 0:5.4.16-42.el7 

  php-common.x86_64 0:5.4.16-42.el7                            xorg-x11-proto-devel.noarch 0:7.7-20.el7                 

  zlib-devel.x86_64 0:1.2.7-17.el7    

安装httpd 然后启动

1 yum install httpd -y

启动httpd

1  systemctl start httpd

 

 

新建nagios用户

1  useradd nagios

 

新建一个运行组

1  groupadd nagcmd

 

把用户和Apache加到新建的组里面去

1  usermod -G nagcmd nagios
1  usermod -G nagcmd apache

新建一个Nagios文件夹

把需要用到的安装包放到文件夹里面

1 mkdir Nagios
1 cd Nagios/

 

[root@juny-10 Nagios]# ls

nagios-3.5.1.tar.gz  nagios-plugins-2.1.1.tar.gz  nrpe-2.15.tar.gz  vautour_style.zip

[root@juny-10 Nagios]#

解压并到nagios目录下

1  tar xvf nagios-3.5.1.tar.gz -C /usr/local/src/ ; cd /usr/local/src/nagios

指定组进行编译

[root@juny-10 nagios]# ./configure --with-command-group=nagcmd

*** Configuration summary for nagios 3.5.1 08-30-2013 ***:

 

 General Options:

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

        Nagios executable:  nagios

        Nagios user/group:  nagios,nagios         #运行用户

       Command user/group:  nagios,nagcmd      #运行用户组

            Embedded Perl:  no

             Event Broker:  yes

        Install ${prefix}:  /usr/local/nagios       #安装的位置

                Lock file:  ${prefix}/var/nagios.lock

   Check result directory:  ${prefix}/var/spool/checkresults

           Init directory:  /etc/rc.d/init.d

  Apache conf.d directory:  /etc/httpd/conf.d          #Apache的conf.d配置文件目录

             Mail program:  /usr/bin/mail

                  Host OS:  linux-gnu

 

 Web Interface Options:

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

                 HTML URL:  http://localhost/nagios/      #登录地址

                  CGI URL:  http://localhost/nagios/cgi-bin/

 Traceroute (used by WAP):  /usr/bin/traceroute

 

 

Review the options above for accuracy.  If they look okay,

type 'make all' to compile the main program and CGIs.

 

 

[root@juny-10 nagios]# make all

*** 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):

#提示安装步骤、

  make install

     - This installs the main program, CGIs, and HTML files

 

  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!

 

  make install-webconf

     - This installs the Apache config file for the Nagios

       web interface

 

  make install-exfoliation            #主题相关的,不需要安装

     - This installs the Exfoliation theme for the Nagios

       web interface

 

  make install-classicui   #主题相关的,不需要安装

     - This installs the classic theme for the Nagios

       web interface

 

 

*** Support Notes *******************************************

 

If you have questions about configuring or running Nagios,

please make sure that you:

 

     - Look at the sample config files

     - Read the documentation on the Nagios Library at:

           http://library.nagios.com

 

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://support.nagios.com

 

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

 

Enjoy.

 

[root@juny-10 nagios]#

[root@juny-10 nagios]# make install

#安装生成/usr/local/nagios/,其中/usr/local/nagios/share即nagiosWEB访问界面的站点目录

[root@juny-10 nagios]# make install-init

#安装生成/etc/rc.d/init.d/nagios  启动脚本

/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d

/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

 

*** Init script installed ***

[root@juny-10 nagios]# make install-commandmode

#设定相应nagios工作目录的权限

/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw

chmod g+s /usr/local/nagios/var/rw

 

*** External command directory configured ***

[root@juny-10 nagios]# make install-config

#安装生成/usr/local/nagios/etc下的nagios相关配置文件

 

*** Config files 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.

 

[root@juny-10 nagios]#

[root@juny-10 nagios]# make install-webconf

#安装Nagios的WEB配置文件到Apache的conf.d目录下

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

 

*** Nagios/Apache conf file installed ***

 

到此安装就结束了

在安装的时候,make install生成share这个目录,这个目录是访问界面目录:

[root@juny-10 nagios]# ls /usr/local/nagios/share/

config.inc.php  docs    includes   js        media       rss-corefeed.php  side.php  stylesheets

contexthelp     images  index.php  main.php  robots.txt  rss-newsfeed.php  ssi

 

在make install-init的时候,生成启动脚本

[root@juny-10 nagios]# ls /etc/init.d/nagios

/etc/init.d/nagios

 

在make install-config的时候,生成了Nagios的相关配置文件;包括以后安装了plugin等软件后,配置文件也会放入此目录

resource.cfg:定义了很多资源变量的调用

[root@juny-10 nagios]# ls /usr/local/nagios/etc/

cgi.cfg  nagios.cfg  objects  resource.cfg

 

在make install-webconf的时候,已经把web-conf的配置文件放入了/etc/httpd/conf.d/下面

[root@juny-10 nagios]# ls /etc/httpd/conf.d/nagios.conf

/etc/httpd/conf.d/nagios.conf  #里面配置了一个别名,直接引用了/usr/local/nagios/share目录

 

[root@juny-10 nagios]# vim /etc/httpd/conf.d/nagios.conf

 

 

可以看到别名和路径

 

Nagios的主目录

[root@juny-10 nagios]# ll /usr/local/nagios/

总用量 0

drwxrwxr-x  2 nagios nagios  38 11月  6 01:01 bin  #nagios执行程序的所在目录

drwxrwxr-x  3 nagios nagios  74 11月  6 01:04 etc  #nagios配置文件目录;初安装时只有几个配置文件

drwxrwxr-x  2 nagios nagios   6 11月  6 01:01 libexec  #监控所用命令、需要安装nagios-plugins插件才会有;不是空的

drwxrwxr-x  2 nagios nagios 311 11月  6 01:01 sbin   #nagios的cgi文件所在目录,外部命令所需要的文件存放目录

drwxrwxr-x 10 nagios nagios 257 11月  6 01:01 share   #nagios前端页面

drwxrwxr-x  5 nagios nagios  45 11月  6 01:03 var     #日志文件

[root@juny-10 nagios]#

 

认识nagios配置文件

[root@juny-10 nagios]# vim /usr/local/nagios/etc/nagios.cfg

log_file=/var/log/nagios/nagios.log                        #日志位置

cfg_file=/etc/nagios/objects/commands.cfg          #这个文件定义了很多命令

cfg_file=/etc/nagios/objects/contacts.cfg                   #定义联系人,怎么联系

cfg_file=/etc/nagios/objects/timeperiods.cfg                #定义了时间段

cfg_file=/etc/nagios/objects/templates.cfg                  #模板(联系人,主机,时间)

cfg_file=/etc/nagios/objects/localhost.cfg                  #监控本机相关配置文件

#cfg_file=/etc/nagios/objects/windows.cfg                   #windows,默认不监控

#cfg_file=/etc/nagios/objects/switch.cfg                    #交换机路由器监控,默认不监控

#cfg_file=/etc/nagios/objects/printer.cfg                   #打印机监控,默认不监控

 

#cfg_dir=/etc/nagios/servers                                #定义了服务合集(多个使用)

#cfg_dir=/etc/nagios/printers                               #定义了打印机合集(多个使用)

#cfg_dir=/etc/nagios/switches                               #定义了交换合集(多个使用)

#cfg_dir=/etc/nagios/routers                                #定义了路由合集(多个使用)

resource_file=/etc/nagios/private/resource.cfg 资源变量配置文件,包括$USER1$变量(一个路径)等

status_update_interval=10                                   #状态更新时间,单位s

log_rotation_method=d                                       #日志滚动,默认天

service_check_timeout=60                                    #服务检查超时时间

host_check_timeout=30                                   #主机检查超时时间

event_handler_timeout=30                              

notification_timeout=30

ocsp_timeout=5

perfdata_timeout=5

 

认识下cgi文件

[root@juny-10 nagios]# vim /usr/local/nagios/etc/cgi.cfg

main_config_file= /usr/local/nagios/etc/nagios.cfg             #主配置文件

physical_html_path= /usr/local/nagios/share          #物理路径

url_html_path=/nagios                               #在URL后面加上/nagios才能访问

use_authentication=1                                #使用认证

use_ssl_authentication=0                          #不使用ssl

authorized_for_system_information=nagiosadmin       #认证用户

 

测试nagios

重启Apache服务

[root@juny-10 nagios]# systemctl restart httpd

在浏览器输入ip/nagios

 

 

可以看到需要用户名和密码

查看用户名和密码

[root@juny-10 nagios]# vim /etc/httpd/conf.d/nagios.conf

在Directory字段里面有Auth这三个字段,那么就可以使用htpasswd来生成用户名和密码

 

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

New password: 123456

Re-type new password: 123456

Adding password for user nagiosadmin

# -c表示创建,二次添加用户,不能使用-c参数

 

检查配置文件

在nagios的目录下,bin目录下有一个nagios命令,这个命令可以帮助我们对配置文件的检查工作以及指定相关配置文件

[root@juny-10 nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

 

Nagios Core 3.5.1

Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors

Copyright (c) 1999-2009 Ethan Galstad

Last Modified: 08-30-2013

License: GPL

 

 

Total Warnings: 0          #警告

Total Errors:   0           #错误

 

Things look okay - No serious problems were detected during the pre-flight check

[root@juny-10 nagios]#

 

 

 

重启Apache再次测试

[root@juny-10 nagios]# systemctl restart httpd

 

登录成功

 

但是现在还没有做任何深入配置,所以现在只是可以登录而已!

 

转载于:https://www.cnblogs.com/it-hack/p/7807372.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值