Chinaunix首页 | 论坛 | 博客
  • 博客访问: 364975
  • 博文数量: 83
  • 博客积分: 2213
  • 博客等级: 大尉
  • 技术积分: 835
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-16 20:26
文章分类

全部博文(83)

文章存档

2015年(1)

2012年(1)

2011年(14)

2007年(20)

2006年(47)

我的朋友

分类: LINUX

2006-08-30 11:01:51

Nagios Install and Configuration

Written by Creighton Long
MP352: ITL Project
Project Advisor: Jeanna Matthews
Last Updated: 4/25/05

My Requirements

  • Linux with a C compiler and TCP/IP configured
  • Apache web server
  • Thomas Boutell's gd library version 1.6.3 or higher
  • root access
  • not going to be rebuilt during the semester by COSI/ITL

Optional/Prerequisite Steps

  • changed roots password (I used the root account instead of pseudo)
  • installed openssh-server (most of my work was done from a remote machine)
  • installed apache2
  • created /var/www/index.html
  • commented out the "Redirect Match" line in /etc/apache2/sites-enabled/default to direct to the index file
  • uncommented "AddHandler cgi-script .cgi" in apache2.conf and added ".sh .pl", and added "Options +ExecCGI"

Enabling Apt-Get

Apt can be used to install Apache2, the gdlib libraries and Nagios from the Ubuntu repositories, however I had problems with those versions. I ended up only using the Apache2 package and I compiled the graphics, gd libraries and Nagios from source.

  • enable apt repositories in /etc/apt/sources.list as described in
    I kept all "hoary" instead of changing to "warty"
  • Note: the Nagios package was slightly outdated so the configuration below might not be identical, particularly the locations of the Nagios directories.
  • Apt links

Step-by-Step Instructions for Nagios 2.03b

Note: these are the steps I took to install/configure Nagios to work with Apache2 on the Clarkson University ITL and COSI machines, your mileage may very. The documentation for Nagios is excellent and I highly recommend that anyone installing Nagios follow their instructions!

Note: As the focus of this page is the installation of Nagios, I spent little time documenting the prerequisite programs: the sections not pertaining directly to Nagios may be flawed.

Download Required Files

  • Note: I stored them in ~/download/

Untar Downloaded Source

  • tar xzf nagios-2.0b3.tar.gz
  • tar xzf nagios-plugins-1.4.tar.gz
  • tar xzf gd-2.0.33.tar.gz
  • tar xzf zlib-1.2.2.tar.gz
  • tar xzf libpng-1.2.8-config.tar.gz
  • tar xzf jpegsrc.v6b.tar.gz

Install Libraries

  • install , , , , and (links go to brief install instructions)

Add User Nagios

  • adduser nagios

Make Nagios Directory

  • mkdir /usr/local/nagios
  • chown nagios.nagios /usr/local/nagios

Identify the Web Server User

  • grep "^User" /etc/apache2/apache2.conf
    User www-data
    In the case of my Apache2 install, it is www-data

Add Command File Group and Add the Users to it

  • /usr/sbin/groupadd nagcmd
  • /usr/sbin/usermod -G nagcmd www-data
  • /usr/sbin/usermod -G nagcmd nagios

Run the Configure Script

  • ./configure --prefix=/usr/local/nagios --with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd
    *** Configuration summary for nagios 2.0b3 04-03-2005 ***:
    
    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
    Init directory: /etc/init.d
    Host OS: linux-gnu
    Web Interface Options:
    ------------------------
    HTML URL:
    CGI URL:
    Traceroute (used by WAP):
    Review the options above for accuracy. If they look okay,
    type 'make all' to compile the main program and CGIs.

Compile Binaries

  • make all

Install Binaries and HTML files

  • make install

Install Init Script

  • make install-init

Set Command Mode File Permissions

  • make install-commandmode

Install Sample Config Files

  • make install-config

Install Plugins

  • ./configure
                         --with-cgiurl: /nagios/cgi-bin
                    --with-nagios-user: nagios
                   --with-nagios-group: nagios
                   --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
                   --with-ping-command: /bin/ping -n -U -w %d -c %d %s
                  --with-ping6-command: /bin/ping6 -n -U -c %d %s
                          --with-lwres: no
                           --with-ipv6: yes
                        --with-openssl: no
          --enable-emulate-getaddrinfo: no
  • make
  • make check
    =====================
    18 of 20 tests failed
    =====================
    
  • make install

Setting Up the Web Interface

  • add the Nagios directories to /etc/apache2/apache2.conf
    # BEGIN FOR NAGIOS
    ScriptAlias /cgi-bin/nagios /usr/local/nagios/sbin
    ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

    Options ExecCGI
    AllowOverride AuthConfig
    Order Allow,Deny
    Allow From All
    AuthName "Nagios Access"
    AuthType Basic
    AuthUserFile /usr/local/nagios/etc/htpasswd.users
    require valid-user

    Alias /nagios /usr/local/nagios/share

    Options None
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all

    # END FOR NAGIOS
  • Note: I chose to allow access to the Nagios web files and to restrict cgi access to authenticated users. Set these however you would like.
  • Note: the authentication use option for Nagios is located in /usr/local/nagios/etc/cgi.cfg and is called "use_authentication." Read carefully before setting Nagios to run without authentication.
  • htpasswd2 -c /usr/local/nagios/etc/htpasswd.users nagiosadmin and set a password for the admin account, repeat as necessary for each account you would like to make.
  • /etc/init.d/apache2 restart

Sample Config Files

  • cd /usr/local/nagios/etc
  • rename all of the sample files to remove "-sample." This can be done manually, or you can use the following script from the OnLamp Nagios article
    • for i in *cfg-sample; do mv $i `echo $i | sed -e s/cfg-sample/cfg/`; done;
  • check the config files
    • /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  • Note: I received the following error using the default config:
    Reading configuration data...
    Error: Command 'check-host-alive' has already been defined
    Error: Could not register command (config file '/usr/local/nagios/etc/minimal.cfg', starting on line 76)
    ***> One or more problems was encountered while processing the config files...
    Apparently this is a common problem with version 2.0b3, and I found a temporary solution on the unofficial forums: Simply comment out all of the definitions it complains about! So for me, that was all of the lines between the Commands section and the Contacts section. Once you've done that you should ideally see the following at the bottom of your test:
    Total Warnings: 0
    Total Errors: 0
    Things look okay - No serious problems were detected during the pre-flight check
  • restart Nagios using /etc/init.d/nagios restart

Adding Hosts, Hostgroups, and Services

  • This is where you add information about your computers and network for Nagios to monitor. This section is highly network-specific and for security reason I won't be posting the configuration data I used. The sample files are very easy to follow and there is a wealth of data found in the Nagios documentation.
  • I started with minimal.cfg and added one host/hostgroup/service/etc at a time to make debugging as easy as possible, though bigger.cfg is an excellent example of how to many larger numbers of resources.
  • Note: It is incredibly useful to plan out your hosts/hostgroups into logical groups before you start entering them.
  • I started with the following 3 hostgroups
    • COSI Lab - all computers and resources located in the COSI lab
    • Routers and Gateways - networking hardware that both labs depend on
    • ITL Lab - all computers and resources located in the ITL lab
  • Each hostgroup is clearly defined and contact groups are obvious (nagiosadmin will be notified of all failures, lab monitors for COSI will only be notified of a failure on a COSI machine, and so on).
  • The easiest way to start monitoring a network is to define the ping service for each machine you add. It is also easy to add services to monitor an HTTP server. You can gain more information about specific plugins by doing the following:
    • cd /usr/local/nagios/libexec
    • ./plugin_name -help (ie, "./check_tcp -help")

Allow Nagiosadmin Access to all of the CGIs

  • I added to following lines to /usr/local/nagios/etc/cgi.cfg in their given sections
    • authorized_for_system_information=nagiosadmin
    • authorized_for_configuration_information=nagiosadmin
    • authorized_for_all_services=nagiosadmin
      authorized_for_all_hosts=nagiosadmin
    • authorized_for_all_service_commands=nagiosadmin
      authorized_for_all_host_commands=nagiosadmin

Commands

  • /etc/init.d/nagios start|stop|restart|reload|force-reload|status
  • /etc/init.d/apache2 start|stop|restart|reload|force-reload

Important Files and Directories

/etc/apache2/apache2.conf The config file for Apache2. This contains information about the directories your web server can access and the authentication required.
/usr/local/nagios/bin Contains the binary files
/usr/local/nagios/etc Contains the object configuration files, including minimal.cfg and cgi.cfg.
/usr/local/nagios/libexec Contains the plugins.
/usr/local/nagios/sbin Contains the cgi files for the web interface.
/usr/local/nagios/share Contains the web files.
/usr/local/nagios/var Contains the log file called nagios.log, the cache file, temp file, status file, archives folder and more.
/etc/apache2 Contains the configuration files for Apache2, necessary for configuring authentication.
/var/log/apache2 Contains the log files for Apache2, useful for confirming authentication is configured correctly.
/var/www The root directory for web documents. I placed an index.html file here that directed visitors to /nagios and provided information about the server.

Future Goals

  • Install NsClient on the Windows machines in the lab.
  • Get the images from http://prdownloads.sourceforge.net/nagios/imagepak-base.tar.gz and put them in /usr/share/nagios/htdocs/images/logos
  • Write a plugin to determine if the lab computers are booted to Linux or Windows
  • Determine a way to use MAC addresses for each host instead of hostnames or IP addresses since hostnames and IP addresses change so frequently in the labs ( suggests its possible, suggests plugins need MAC support).

Possible Problems

  • Installing gcc
    • apt-get install gcc
    • apt-get install gcc-3.4
    • apt-get install gcc-3.4-doc
  • Installing zlib-1.2.2
    • cd ~/downloads/zlib-1.2.2
    • ./configure
    • make
    • make install
  • Installing libpng-1.2.8
    • Note: install zlib first
    • cd ~/downloads/libpng-1.2.8-config
    • cp scripts/makefile.std makefile
    • ./configure
    • make
    • make install
  • Install libjpeg-v6b
    • Note: I encountered problems with the standard install and found the following solution .
    • cd ~/downloads/jpeg-6b
    • ./configure --prefix=${prefix} --enable-static --enable-sharedMake
    • make
    • strip rdjpgcom wrjpgcom .libs/{cjpeg,djpeg,jpegtran}Install
    • mkdir -p ${prefix}/{bin,include,lib,man/man1}
    • make test
    • make install
  • Installing gd-2.0.33
    • cd ~/downloads/gd-2.0.33
    • ./configure
      ** Configuration summary for gd 2.0.33:
      
      Support for PNG library: yes
      Support for JPEG library: yes
      Support for Freetype 2.x library: no
      Support for Fontconfig library: no
      Support for Xpm library: no
      Support for pthreads: yes

      This was my output, I'm not sure if the three libraries that lack support are needed or not, however PNG and JPEG support are necessary otherwise some of the CGI scripts won't function.

    • make
    • make install
  • Some of the CGIs seem to be missing or don't work
    • I had this problem when I rushed through the install without JPEG support. Status Map, Trends, and Alert Historogram were not installed.
    • a description of the problem can be found in the FAQ .
  • Accessing CGIs results in improper authorization message
    • a description of the problem can be found in the FAQ carefully read the .
    • the I posted to share my problem
  • If the 3-D status map tries to download a file, you might not have a VRML plugin for your browser.
    • a description of the problem can be found in the FAQ and their suggestions are
    • I opted to install , though at the time of writing this Firefox opens the file in an IE window anyway.

Resources







阅读(2290) | 评论(0) | 转发(0) |
0

上一篇:正则表达式

下一篇:提拉米苏[Tiramisu]

给主人留下些什么吧!~~