You prefer to build Nagios from source code so that you can control the compiletime options. You also want to get the latest version because the packages in your Linux distribution are several versions behind. What additional libraries do you need?
You need an HTTP server such as Apache or Lighttpd, the usual Linux build environment, plus libraries to support the statusmap, trends, and histograms. Nagios uses a lot of Common Gateway Interface (CGI) scripts (these are scripts used by web servers to generate pages), so it needs the GD libraries and their dependencies. On Fedora, install these packages:
The Development Tools package group (yum install 'Development Tools'
)
libgd
libgd-devel
libpng
libpng-devel
libjpeg
libjpeg-devel
zlib
zlib-devel
On Debian, you need these packages:
build-essential
libgd2
libgd2-dev
libpng12-0
libgd2-dev
libjpeg62
libjpeg62-dev
zlib1g
zlib1g-dev
There are four Nagios tarballs. These are the versions that were current when this was written:
nagios-2.9.tar.gz
nagios-plugins-1.4.8.tar.gz
nrpe-2.8.1.tar.gz
nsca-2.7.1.tar.gz
The first two contain the core Nagios framework and plug-ins. With these, you can perform host and service checks without installing any client software. The second two require you to install and configure Nagios on the client computers. nrpe performs additional checks, such as CPU status and other hardware checks. ncsa adds all kinds of encryption and security. These might be useful for monitoring important Linux or Unix servers; in this chapter, we're going to focus on configuring only the Nagios server, and setting up the service and host checks that do not require client software.
Installing Nagios from sources is more complex than for most applications, so follow these steps to achieve Nagios nirvana. First, download the two current stable nagios and nagios-plugins tarballs from Nagios.org (http://www.nagios.org/download) into the directory of your choice. Compare the md5sums, which are posted on the download page:
$ md5sum nagios-2.9.tar.gz
bb8f0106dc7f282c239f54db1f308445 nagios-2.9.tar.gz
Then, unpack them:
$ tar zxvf nagios-2.9.tar.gz
$ tar zxvf nagios-plugins-1.4.8.tar.gz
Create a nagios group and user, and create /usr/local/nagios as its home directory:
# groupadd nagios
# useradd -g nagios -md /usr/local/nagios nagios
Now, create an external command group. First find out which user Apache runs as. On Fedora, use this command:
$ grep 'User ' /etc/httpd/conf/httpd.conf
User apache
On Debian, use this command:
$ grep 'User ' /etc/apache2/apache2.conf
User www-data
The rest of the steps are the same for both. Create a nagioscmd group, and add the Apache user and nagios user to it:
# groupadd nagioscmd
# usermod -G nagioscmd [your Apache user]
# usermod -G nagioscmd nagios
Next, enter the nagios-2.9 directory, and run the configure script with the options shown here. Then, install Nagios and the Nagios helpers:
$ cd nagios-2.9
$ ./configure --with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios \
--with-nagios-user=nagios --with-nagios-group=nagios \
--with-command-group=nagioscmd
$ make all
# make install
# make install-init
# make install-commandmode
# make install-config
Now, enter the nagios-plugins-1.4.8 directory and install the plug-ins:
# cd ../nagios-plugins-1.4.8
# ./configure
# make
# make install
The plug-ins will be installed in /usr/local/nagios/libexec.
Nagios will not start until you create a basic working configuration. You can now view the Nagios HTML documentation at /usr/local/nagios/share/index.html,as Figure 13-1 shows. You can read the help docs even though Nagios is not running.
The next recipe tells you how to configure Apache to serve up the Nagios pages.
If you need to start over and recompile Nagios, be sure to run
the make devclean
command first to
clean up leftover object files and get a fresh start.
On small networks, you can get away with using your HTTP server to run Nagios and a bunch of other services, but it's better to use a dedicated HTTP plus Nagios installation.
That takes care of installing your basic Nagios framework. The source
install puts everything in /usr/local/nagios. Of
course, you may customize the file locations with configure
options; run configure--help
to see all the available
options.
The installation options for Nagios version 2.9 are mostly self-explanatory, except for these two:
--with-cgiurl=
Defines the web directory where the Nagios CGI scripts will go.
--with-htmurl=
Defines the URL for the Nagios web interface.
This is what the Makefile targets do:
Compile and install Nagios.
Install the start-up script.
Set appropriate file permissions.
Install sample configuration files.
Review the INSTALLING and README files in the Nagios tarball, and the INSTALL and REQUIREMENTS files in nagios-plugins for current options and requirements. Look in /usr/local/nagios/share for the HTML documentation.
Nagios.org: http://www.nagios.org/
Chapter 8, "Managing Users and Groups," in Linux Cookbook, by Carla Schroder (O'Reilly)
Chapter 4, "Installing Programs from Source Code," in Linux Cookbook