history 24 of 36
Install Nagios Core 3 and Plugins on CentOS 6: Quick Steps
A short command list for building Nagios Core 3.4.4 and the Nagios plugins from source on CentOS 6, then logging in to the web interface.
Written
- Monitoring and security
- Written for CentOS 6
- Written for Nagios Core 3.4.4
From my Linux study notes, 2016. Some commands and versions here are old, so please reuse them carefully. Anything marked "added later", and the notes at the end, explain what has changed since.
This is my short list of commands for installing Nagios Core and the Nagios plugins from source on CentOS 6. For a longer walkthrough that also creates the Nagios user and groups, sets the alert email address and checks the configuration, see my other post, “Install Nagios on CentOS: Users, Web Login, Alerts and Checks”.
Before you start
- Run these commands as root (or put
sudoin front of them). - Use a test server first.
- The Nagios install steps expect a
nagiosuser and group to exist. This post does not create them, and without them the install steps fail. Create them first (this is the same as in my other Nagios post):
useradd -m nagiosgroupadd nagcmdusermod -a -G nagcmd nagiosusermod -a -G nagcmd apacheInstallation of Nagios Core
-
Install the packages needed to build Nagios and run its web interface (Apache, PHP, the C compiler and the GD graphics library):
Terminal window yum install gd gd-devel httpd php gcc glibc glibc-common -
Make a folder to keep the downloads in:
Terminal window mkdir /root/nagios -
Go into it:
Terminal window cd /root/nagios -
Download Nagios Core and the Nagios plugins:
Terminal window wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.4.tar.gzwget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz -
Extract Nagios:
Terminal window tar xvzf nagios-3.4.4.tar.gzxextracts,vlists the files as they are extracted,zhandles the gzip compression andfnames the archive file. -
Go into the extracted folder:
Terminal window cd nagiosIf
cd nagiosfails, runlsto see the exact folder name the archive created andcdinto that instead. -
Run the configure script, which checks your system and prepares the build:
Terminal window ./configureIf you created the
nagcmdgroup above, use./configure --with-command-group=nagcmdinstead so the web interface can send commands to Nagios. -
Compile and install. In the original post these were written on one line separated by commas; they are separate commands, run one after another:
Terminal window make allmake installmake install-initmake install-commandmodemake install-configmake install-webconfmake installinstalls the program under/usr/local/nagios/.make install-initinstalls the start-up script.make install-commandmodesets permissions on the folder used for external commands.make install-configinstalls the sample configuration files.make install-webconfadds the Apache configuration for the web interface.
-
Create the web login user
nagiosadmin. You will be asked to type a password twice:Terminal window htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminThe
-coption creates the file. Only use it the first time; running it again with-coverwrites the file and removes existing users. -
Set Nagios to start at boot and start it now:
Terminal window chkconfig nagios onservice nagios start
Installation of Nagios plugins
The plugins are the small programs Nagios runs to do the actual checks (ping, disk space, HTTP and so on).
cd ..tar xvzf nagios-plugins-1.4.15.tar.gzcd nagios-plugins-1.4.15./configuremakemake installCorrection: the download in step 4 is version 1.4.16, but these commands extract 1.4.15. Use the same version you downloaded:
cd ..tar xvzf nagios-plugins-1.4.16.tar.gzcd nagios-plugins-1.4.16./configure --with-nagios-user=nagios --with-nagios-group=nagiosmakemake installThen start Apache and set it to start at boot:
service httpd startchkconfig httpd onLog in
Now log in at http://your-ip/nagios with user nagiosadmin and the password you set in step 9.
To check it worked: the page should ask for a username and password, then show the Nagios home page. The “Services” page should list checks for localhost. If the page does not load from another computer, check that the firewall allows port 80.
Notes for today
-
CentOS 6 reached end of life on 30 November 2020 and gets no security updates. Rocky Linux and AlmaLinux are the common free replacements.
-
Nagios Core 3 is old. Nagios Core 4 replaced it. The SourceForge links above may no longer work; get the current Nagios Core and plugin releases from the official site, https://www.nagios.org/, and check the documentation for your version, as the build steps have changed.
-
Services: on systems with systemd,
service x start/chkconfig x onbecome:Terminal window sudo systemctl start httpdsudo systemctl enable httpd -
Packages:
yumbecamednfon newer Red Hat-family systems (yumstill works as an alias). -
Firewall: on Rocky Linux and AlmaLinux, allow web traffic with:
Terminal window sudo firewall-cmd --permanent --add-service=httpsudo firewall-cmd --reload -
Security: the web login uses HTTP basic authentication. Over plain
http://the password is sent unencrypted, so put the Nagios web interface behind HTTPS, or restrict it to your own network, on any server reachable from the internet.