Step by step guide to install and configure Nagios on Ubuntu 18.04
Nagios is server monitoring tool freely available.
OS: Ubuntu 18.04
Nagios: nagios-4.4.5
Nagios Plugin: nagios-plugins-2.3.3
if test "nagios-plugins" = "gettext-tools"; then \
/bin/mkdir -p /usr/local/nagios/share/gettext/po; \
for file in Makefile.in.in remove-potcdate.sin Makevars.template; do \
/usr/bin/install -c -o nagios -g nagcmd -m 644 ./$file \
/usr/local/nagios/share/gettext/po/$file; \
done; \
for file in Makevars; do \
rm -f /usr/local/nagios/share/gettext/po/$file; \
done; \
else \
: ; \
fi
1. We are going to build nagios from source code. First install the build dependencies on your system.
root@sam:~# apt-get install build-essential libgd-dev openssl libssl-dev unzip wget
2. Install apache, php
root@sam:~# apt-get install apache2 php libapache2-mod-php php-gd libgd-dev
3. Create nagios user
root@sam:~# groupadd nagcmd
root@sam:~# useradd -G nagcmd nagios
root@sam:~# id nagios
uid=1001(nagios) gid=1002(nagios) groups=1002(nagios),1001(nagcmd)
4. Installing Nagios
A. Installing Nagios Binary
B. Installing Nagios using source code
A. Nagios Binary installation
a. Go to github and download the software
https://www.nagios.org/downloads/nagios-core/thanks/?skip=1&t=1524771419
or
https://github.com/NagiosEnterprises/nagioscore/releases
root@sam:~# wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.4.5/nagios-4.4.5.tar.gz
b. Extract the package
root@sam:~# tar xpf nagios-4.4.5.tar.gz
root@sam:~# ls
mysleep.sh nagios-4.4.5 nagios-4.4.5.tar.gz releases
root@sam:~# cd nagios-4.4.5/
root@sam:~/nagios-4.4.5# ./configure --with-command-group=nagcmd --with-nagios-group=nagios
may take a while to complete. Review the error if you get any.
Now, make it with the number of processor. I have 4 CPU core which will speed up the process..
# make -j4 all
You successfully compile your software. Now its time to install the software component.
root@sam:~/nagios-4.4.5# make install
root@sam:~/nagios-4.4.5# make install-init
root@sam:~/nagios-4.4.5# make install-daemoninit
root@sam:~/nagios-4.4.5# make install-config
root@sam:~/nagios-4.4.5# make install-commandmode
root@sam:~/nagios-4.4.5# make install-exfoliation
Now, copy event handlers script to libexec directory which provides multiple event triggers for Nagios web interface.
root@sam:~/nagios-4.4.5# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
root@sam:~/nagios-4.4.5# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Now, copy apache configuration to apache sites-available directory. After that add apache user to nagcmd group
root@sam:~/nagios-4.4.5# /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
root@sam:~/nagios-4.4.5# usermod -a -G nagcmd www-data
3. Install the plugins
Nagios plugins enhance the functionality and add extra value to the product. Download from
https://www.nagios.org/downloads/nagios-plugins/
root@sam:~# wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
root@sam:~# tar -xpf nagios-plugins-2.3.3.tar.gz; cd nagios-plugins-2.3.3/
Configure nagios with open ssh support
check for errors
root@sam:~/nagios-plugins-2.3.3# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --with-openssl
Now, same way before, run make command and install the plugins
# make -j 4
# make install
Some configuration change to let nagios to process all config files with .cfg at specified location.
So, just uncomment the line cfg_dir=/usr/local/nagios/etc/servers
Open nagios config file and uncomment the
root@sam:~/nagios-plugins-2.3.3# vi /usr/local/nagios/etc/nagios.cfg
root@sam:~/nagios-plugins-2.3.3# mkdir /usr/local/nagios/etc/servers
If you like, you can change the email address so that you get notification by editing the file below,
root@sam:~/nagios-plugins-2.3.3# vi /usr/local/nagios/etc/objects/contacts.cfg
Change email to your email
email nagios@localhost to email your@companyemail.com
Set up Apache with an authentication gateway
Now, set up apache virtual host for nagios and authentication gateway to prevent unauthorized access to your system.
Add following apache configuration to /etc/apache2/conf-available/nagios.conf
root@sam:~/nagios-plugins-2.3.3# 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>
Set up authentication gateway to authenticate with user nagiosadmin. You can use different user but but you have to make other configuration changes. This is going ot be Nagios admin user.
root@sam:~/nagios-plugins-2.3.3# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Now enable the Apache modules and restart apache.
root@sam:~/nagios-plugins-2.3.3# a2enconf nagios
root@sam:~/nagios-plugins-2.3.3# a2enmod cgi rewrite
root@sam:~/nagios-plugins-2.3.3# systemctl restart apache2
root@sam:~/nagios-plugins-2.3.3# echo $?
0
Now, Verify and start Nagios and enable to start @boot
before you use it, verify the configuration.
root@sam:~/nagios-plugins-2.3.3# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Got the output as ...
Things look okay - No serious problems were detected during the pre-flight check
root@sam:~/nagios-plugins-2.3.3# systemctl status nagios
root@sam:~/nagios-plugins-2.3.3# systemctl start nagios
root@sam:~/nagios-plugins-2.3.3# systemctl status nagios
root@sam:~/nagios-plugins-2.3.3# systemctl enable nagios
If you need to create nagios service, copy the following content to nagios.service since it does not start automatically.
root@sam:~/nagios-plugins-2.3.3# cat /etc/systemd/system/abc123nagios.service.bk
[Unit]
Description=Nagios
BindTo=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=nagios
group=nagcmd
# Remove line below to enable
#ExecStart=/usr/local/nagios/bin/nagios /use/local/nagios/etc/nagios.cfg
once you save it, enable the service
# systemctl enable /etc/systemd/system/nagios.service
# systemctl start nagios
Now, its time to access nagios through the web. It will prompt you for passwd, just use nagiosadmin user and the password you set it for the account
http://your_ip/nagios
Got help from,
https://draculaservers.com/tutorials/install-nagios-ubuntu/
https://linuxconfig.org/install-nagios-on-ubuntu-18-04-bionic-beaver-linux
Nagios is server monitoring tool freely available.
OS: Ubuntu 18.04
Nagios: nagios-4.4.5
Nagios Plugin: nagios-plugins-2.3.3
if test "nagios-plugins" = "gettext-tools"; then \
/bin/mkdir -p /usr/local/nagios/share/gettext/po; \
for file in Makefile.in.in remove-potcdate.sin Makevars.template; do \
/usr/bin/install -c -o nagios -g nagcmd -m 644 ./$file \
/usr/local/nagios/share/gettext/po/$file; \
done; \
for file in Makevars; do \
rm -f /usr/local/nagios/share/gettext/po/$file; \
done; \
else \
: ; \
fi
1. We are going to build nagios from source code. First install the build dependencies on your system.
root@sam:~# apt-get install build-essential libgd-dev openssl libssl-dev unzip wget
2. Install apache, php
root@sam:~# apt-get install apache2 php libapache2-mod-php php-gd libgd-dev
3. Create nagios user
root@sam:~# groupadd nagcmd
root@sam:~# useradd -G nagcmd nagios
root@sam:~# id nagios
uid=1001(nagios) gid=1002(nagios) groups=1002(nagios),1001(nagcmd)
4. Installing Nagios
A. Installing Nagios Binary
B. Installing Nagios using source code
A. Nagios Binary installation
a. Go to github and download the software
https://www.nagios.org/downloads/nagios-core/thanks/?skip=1&t=1524771419
or
https://github.com/NagiosEnterprises/nagioscore/releases
root@sam:~# wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.4.5/nagios-4.4.5.tar.gz
b. Extract the package
root@sam:~# tar xpf nagios-4.4.5.tar.gz
root@sam:~# ls
mysleep.sh nagios-4.4.5 nagios-4.4.5.tar.gz releases
root@sam:~# cd nagios-4.4.5/
root@sam:~/nagios-4.4.5# ./configure --with-command-group=nagcmd --with-nagios-group=nagios
may take a while to complete. Review the error if you get any.
Now, make it with the number of processor. I have 4 CPU core which will speed up the process..
# make -j4 all
You successfully compile your software. Now its time to install the software component.
root@sam:~/nagios-4.4.5# make install
root@sam:~/nagios-4.4.5# make install-init
root@sam:~/nagios-4.4.5# make install-daemoninit
root@sam:~/nagios-4.4.5# make install-config
root@sam:~/nagios-4.4.5# make install-commandmode
root@sam:~/nagios-4.4.5# make install-exfoliation
Now, copy event handlers script to libexec directory which provides multiple event triggers for Nagios web interface.
root@sam:~/nagios-4.4.5# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
root@sam:~/nagios-4.4.5# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Now, copy apache configuration to apache sites-available directory. After that add apache user to nagcmd group
root@sam:~/nagios-4.4.5# /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
root@sam:~/nagios-4.4.5# usermod -a -G nagcmd www-data
3. Install the plugins
Nagios plugins enhance the functionality and add extra value to the product. Download from
https://www.nagios.org/downloads/nagios-plugins/
root@sam:~# wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
root@sam:~# tar -xpf nagios-plugins-2.3.3.tar.gz; cd nagios-plugins-2.3.3/
Configure nagios with open ssh support
check for errors
root@sam:~/nagios-plugins-2.3.3# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --with-openssl
Now, same way before, run make command and install the plugins
# make -j 4
# make install
Some configuration change to let nagios to process all config files with .cfg at specified location.
So, just uncomment the line cfg_dir=/usr/local/nagios/etc/servers
Open nagios config file and uncomment the
root@sam:~/nagios-plugins-2.3.3# vi /usr/local/nagios/etc/nagios.cfg
root@sam:~/nagios-plugins-2.3.3# mkdir /usr/local/nagios/etc/servers
If you like, you can change the email address so that you get notification by editing the file below,
root@sam:~/nagios-plugins-2.3.3# vi /usr/local/nagios/etc/objects/contacts.cfg
Change email to your email
email nagios@localhost to email your@companyemail.com
Set up Apache with an authentication gateway
Now, set up apache virtual host for nagios and authentication gateway to prevent unauthorized access to your system.
Add following apache configuration to /etc/apache2/conf-available/nagios.conf
root@sam:~/nagios-plugins-2.3.3# 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>
Set up authentication gateway to authenticate with user nagiosadmin. You can use different user but but you have to make other configuration changes. This is going ot be Nagios admin user.
root@sam:~/nagios-plugins-2.3.3# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Now enable the Apache modules and restart apache.
root@sam:~/nagios-plugins-2.3.3# a2enconf nagios
root@sam:~/nagios-plugins-2.3.3# a2enmod cgi rewrite
root@sam:~/nagios-plugins-2.3.3# systemctl restart apache2
root@sam:~/nagios-plugins-2.3.3# echo $?
0
Now, Verify and start Nagios and enable to start @boot
before you use it, verify the configuration.
root@sam:~/nagios-plugins-2.3.3# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Got the output as ...
Things look okay - No serious problems were detected during the pre-flight check
root@sam:~/nagios-plugins-2.3.3# systemctl status nagios
root@sam:~/nagios-plugins-2.3.3# systemctl start nagios
root@sam:~/nagios-plugins-2.3.3# systemctl status nagios
root@sam:~/nagios-plugins-2.3.3# systemctl enable nagios
If you need to create nagios service, copy the following content to nagios.service since it does not start automatically.
root@sam:~/nagios-plugins-2.3.3# cat /etc/systemd/system/abc123nagios.service.bk
[Unit]
Description=Nagios
BindTo=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=nagios
group=nagcmd
# Remove line below to enable
#ExecStart=/usr/local/nagios/bin/nagios /use/local/nagios/etc/nagios.cfg
once you save it, enable the service
# systemctl enable /etc/systemd/system/nagios.service
# systemctl start nagios
Now, its time to access nagios through the web. It will prompt you for passwd, just use nagiosadmin user and the password you set it for the account
http://your_ip/nagios
Got help from,
https://draculaservers.com/tutorials/install-nagios-ubuntu/
https://linuxconfig.org/install-nagios-on-ubuntu-18-04-bionic-beaver-linux
No comments:
Post a Comment