Exercise 14: Nagios Installation
In this exercise, you will learn to install Nagios.
1. Prerequisite – Ensure below options are selected under Software & Updates in
your Ubuntu VM
2. To install Apache and PHP, follow the below commands
$ sudo apt-get update
$ sudo apt-get install wget build-essential unzip openssl libssl-dev
$ sudo apt-get install apache2 php libapache2-mod-php php-gd libgd-dev
3. Create Nagios User
Create a new user account for Nagios in your system and assign a password for
the Nagios user.
User: nagios
Pwd: nagiosuser
sudo adduser nagios
Create a group for Nagios setup “nagcmd” and add Nagios user to this group. Also,
add Nagios user in the Apache group.
$ sudo groupadd nagcmd
$ sudo usermod -a -G nagcmd nagios
$ sudo usermod -a -G nagcmd www-data
4. Install Nagios Core Service
After installing required dependencies and adding user accounts, let’s start
with Nagios core installation. Download latest Nagios core service from the official
site.
$ cd /opt
$ sudo wget
https://github.com/NagiosEnterprises/nagioscore/releases/download/
nagios-4.5.2/nagios-4.5.2.tar.gz
$ sudo tar xzf nagios-4.5.2.tar.gz
After extracting, navigate to Nagios source directory and install using make
command.
$ cd nagios-4.5.2
$ sudo ./configure --with-command-group=nagcmd
$ sudo make all
$ sudo make install
$ sudo make install-init
$ sudo make install-daemoninit
$ sudo make install-config
$ sudo make install-commandmode
$ sudo make install-exfoliation
Copy event handlers scripts under libexec directory. These binaries provide multiple
events triggers for your Nagios web interface.
$ sudo cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
$ sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
5. Setup Apache with Authentication
Create an Apache configuration file for your Nagios server as below
in /etc/apache2/conf-available/nagios.conf
$ sudo vi /etc/apache2/conf-available/nagios.conf
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Next, you need to setup apache authentication for user nagiosadmin ny using the
below command (use username as “nagiosadmin”, if you want to use other user
make changes in nagios configuration).
$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Note: Give password as “nagiosadmin” and use this password while
logging into Nagios dashboard.
Now enable Apache configuration and restart Apache service to make the new
settings take effect.
$ sudo a2enconf nagios
$ sudo a2enmod cgi rewrite
6. Open ports.conf under /etc/apache2 and ensure below is present
Listen 9090
$ sudo nano /etc/apache2/ports.conf
If it is not present add Listen 9090 directive to the existing ports.conf.
Example: If Listen 80 is present and not available Listen 9090 then add as shown in
the below and save it
7. Then restart apache service
$ sudo service apache2 restart
8. Installing Nagios Plugins
After installing and configuring Nagios core service, download latest nagios-plugins
and install using following commands.
$ cd /opt
$ sudo wget http://www.nagios-plugins.org/download/nagios-plugins-
2.4.9.tar.gz
$ sudo tar xzf nagios-plugins-2.4.9.tar.gz
$ cd nagios-plugins-2.4.9
Now compile and install Nagios plugins
$ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
$ sudo make
$ sudo make install
9. Verify Settings
Use the below Nagios commands to verify the Nagios installation and configuration
file. After successful installation start the Nagios core service.
$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
$ service nagios start
Also configure Nagios to auto start on system boot. (It may ask for user password, if
yes enter your password to start the service nagios)
$ sudo systemctl enable nagios
10. Access Nagios Web Interface
Access your nagios setup by access nagios server using hostname or IP address
followed by /nagios.
http://localhost:9090/nagios/
username: nagiosadmin
Note: Use the password set in step 4.
Exercise 15: Graphite & Grafana Installation
In this exercise, you will learn to install Graphite & Grafana.
1. Install Docker (as in Exercise 8)
2. Install Docker Compose
Download the latest version of Docker Compose. Check the releases page and
replace 1.21.2 in the command below with the version tagged as latest release:
$ sudo curl -L
https://github.com/docker/compose/releases/download/1.21.2/doc
ker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-
compose
Set file permissions:
$ sudo chmod +x /usr/local/bin/docker-compose
3. Docker Compose Configuration
Create a directory:
$ mkdir ~/grafana && cd ~/grafana
Create “docker-compose.yml” and add the following content:
version: "3"
services:
grafana:
image: grafana/grafana
container_name: grafana
restart: always
ports:
- 3000:3000
networks:
- grafana-net
volumes:
- grafana-volume
graphite:
image: graphiteapp/graphite-statsd
container_name: graphite
restart: always
networks:
- grafana-net
networks:
grafana-net:
volumes:
grafana-volume:
external: true
This Compose file uses the official Docker images for both Graphite and Grafana. It
also specifies a network to connect the containers.
Since the data volume is external, you will need to create it manually:
$ sudo docker volume create --name=grafana-volume
Bring up the configuration:
$ sudo docker-compose up -d
Check that both containers started successfully:
$ docker ps
4. Use the below URL to navigate to Grafana console (use port 3000 which is
configurable in docker-compose.yml file)
URL - http://localhost:3000
Default username and password will be admin. Once you login, it asks for a new
password(Ex:Welcome2ibm!)
5. You need to create a data source. Click on Create your first data source.
Do necessary configuration:
Name: Graphite
URL: http://graphite:8080
Access: Server (Default)
Version: Select the newest available. 1.1.3 in this example.
Click “Save & Test”.
6. Click “New dashboard” to create and customize a new panel:
To import a sample Dashboard, try the Internal Grafana Stats
- Click “New dashboard” at the top, then “Import dashboard”.
- Type 55 into the Grafana.com Dashboard box and click “Load”.
- Select Graphite in the data source dropdown and click “Import”.
- Save the changes made in the dashboard.
7. Graphite does not collect data by itself. To collect the data for graphite we need to
install some third-party utility like collectd.
Install collectd
$ sudo apt-get update
$ sudo apt-get install collectd collectd-utils
Configure Collectd
$ sudo nano /etc/collectd/collectd.conf
Set the hostname of the machine.
Hostname "graph_host"
8. Make sure FQDNLookup value is true in the collectd configuration file (located
at /etc/collectd/collectd.conf), if not, uncomment the Hostname entry in the same
file and provide your machine’s hostname.
Ensure the following plugins are there:
LoadPlugin apache
LoadPlugin cpu
LoadPlugin df
LoadPlugin entropy
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin processes
LoadPlugin rrdtool
LoadPlugin users
LoadPlugin write_graphite
9. For the df plugin, which tells us how full our disks are, we can uncomment the
plugin (if present) or add a simple configuration in “sudo vim
/etc/collectd/collectd.conf” file which looks like this:
<Plugin df>
Device "/dev/sda1"
MountPoint "/"
FSType "ext3"
</Plugin>
10. You should point the device to the device name of the drive on your system. You
can find this by typing the command in the terminal:
$ df
11. Choose the networking interface you wish to monitor and uncomment or add (if
not present) in “sudo vim /etc/collectd/collectd.conf” file:
<Plugin interface>
Interface "eth0"
IgnoreSelected false
</Plugin>
Finally, we come to the Graphite plugin. This will tell collectd how to connect to our
Graphite instance. Make the section look something like this:
<Plugin write_graphite>
<Node "example">
Host "172.18.0.3"
Port "2003"
Protocol "tcp"
LogSendErrors true
Prefix "collectd."
StoreRates true
AlwaysAppendDS false
EscapeCharacter "_"
</Node>
</Plugin>
Note: Change the Host address to the Graphite docker container’s IP
address. This tells our daemon how to connect to Carbon to pass off its
data. We specify that it should look to the local computer on port 2003,
which Carbon uses to listen for TCP connections.
12. Save and close the file when you are finished.
$ sudo service collectd stop
$ sudo service collectd start
sudo systemctl status collectd
13. Open Dashboard