How to install Nagios core 4.3.4 using nginx on Centos 7.4
To install and configure Nagios core with Nginx on CentOS 7.4
Nagios is a popular open source monitoring tool which in turn monitor the services running on the remote machine via the web interface. In this session, we will see the installation and configuration of Nagios on CentOS 7.4 with Nginx.
Installation
Let' s first, install epel-release using the following command.
[root@localhost ~]# yum install epel-release -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.xeonbd.com
* extras: mirror.xeonbd.com
* updates: mirrors.viethosting.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-9 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
.
.
.
.
Running transaction
Installing : epel-release-7-9.noarch 1/1
Verifying : epel-release-7-9.noarch 1/1
Installed:
epel-release.noarch 0:7-9
Complete!
Next, install the Development tools.
[root@localhost ~]# yum groupinstall " Development Tools" -y
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
epel/x86_64/metalink | 6.3 kB 00:00
epel | 4.7 kB 00:00
(1/3): epel/x86_64/group_gz | 266 kB 00:00
(2/3): epel/x86_64/updateinfo | 908 kB 00:03
(3/3): epel/x86_64/primary_db | 6.3 MB 00:10
Loading mirror speeds from cached hostfile
* base: mirror.xeonbd.com
* epel: epel.scopesky.iq
* extras: mirror.xeonbd.com
* updates: mirrors.viethosting.com
Resolving Dependencies
.
.
.
.
perl-TermReadKey.x86_64 0:2.30-20.el7
perl-Test-Harness.noarch 0:3.28-3.el7
perl-Thread-Queue.noarch 0:3.02-2.el7
perl-XML-Parser.x86_64 0:2.41-10.el7
perl-srpm-macros.noarch 0:1-8.el7
subversion-libs.x86_64 0:1.7.14-11.el7_4
systemtap-client.x86_64 0:3.1-5.el7_4
systemtap-devel.x86_64 0:3.1-5.el7_4
Complete!
And then add the required repository to install PHP 5.6 and its dependent modules.
[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm warning: /var/tmp/rpm-tmp.4Vl4T5: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:epel-release-7-11 ################################# [ 50%] Cleaning up / removing... 2:epel-release-7-9 ################################# [100%] [root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm warning: /var/tmp/rpm-tmp.qu1uUh: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:webtatic-release-7-3 ################################# [100%]
Then install required packages.
[root@localhost ~]# yum install nginx php56w-fpm php56w-common gcc glibc glibc-common gd gd-devel make net-snmp unzip -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.xeonbd.com
* epel: ftp.jaist.ac.jp
* extras: mirror.xeonbd.com
* updates: mirrors.viethosting.com
* webtatic: sp.repo.webtatic.com
.
.
.
.
nginx-filesystem.noarch 1:1.12.2-2.el7
nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7
nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7
nginx-mod-http-perl.x86_64 1:1.12.2-2.el7
nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7
nginx-mod-mail.x86_64 1:1.12.2-2.el7
nginx-mod-stream.x86_64 1:1.12.2-2.el7
xorg-x11-proto-devel.noarch 0:7.7-20.el7
zlib-devel.x86_64 0:1.2.7-17.el7
Complete!
Now you have to Start and enable nginx service.
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Now let' s Create a Virtualhost for Nagios.
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vi nagios.conf
server {
listen 80
server_name nagios.linuxhelp1.com
access_log /var/log/nginx/nagios-access.log
error_log /var/log/nginx/nagios-error.log info
root /usr/local/nagios/share
index index.php
auth_basic " Nagios Restricted Access"
auth_basic_user_file /usr/local/nagios/passwd
location /stylesheets {
alias /usr/local/nagios/share/stylesheets
}
location ~ .cgi$ {
root /usr/local/nagios/sbin/
include fastcgi_params
rewrite ^/nagios/cgi-bin/(.*).cgi /$1.cgi break
fastcgi_param AUTH_USER $remote_user
fastcgi_param REMOTE_USER $remote_user
fastcgi_pass unix:/var/run/fcgiwrap.socket
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name
fastcgi_param PATH_INFO $fastcgi_script_name
}
location ~ .php$ {
include fastcgi_params
fastcgi_pass unix:/var/run/php-fpm/nagios.socket
fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/share$fastcgi_script_name
fastcgi_param PATH_INFO $fastcgi_script_name
}
location ~ (.*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf))$ {
root /usr/local/nagios/share/
rewrite ^/nagios/(.*) /$1 break
access_log off expires max
}
}
Save and exit from the file. Restart the Nginx service.
[root@localhost conf.d]# systemctl restart nginx
Now add the port 80 in firewall.
[root@localhost conf.d]# firewall-cmd --permanent --add-port=80/tcp --zone=public success [root@localhost conf.d]# firewall-cmd --reload Success
Next, create a Nagios user and add it to the nginx webserver group “ nginx”
[root@localhost conf.d]# useradd nagios
[root@localhost conf.d]# usermod -aG nagios nginx
Now configure php-fpm for Nagios by editing nagios.conf file
[root@localhost conf.d]# vim /etc/php-fpm.d/nagios.conf
[nagios]
listen = /var/run/php-fpm/nagios.socket
listen.owner = nginx
listen.group = nginx
listen.mode=0660
listen.allowed_clients = 127.0.0.1
user = nagios
group = nagios
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/php-fpm/nagios-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
Next, restart and enable php-fpm
[root@localhost php-fpm.d]# systemctl restart php-fpm
[root@localhost php-fpm.d]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
Next download the nagios 4.3.4 in any archive format by wget command
[root@localhost ~]# wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.3.4.tar.gz
--2018-04-06 17:07:16-- https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.3.4.tar.gz
Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/NagiosEnterprises/nagioscore/tar.gz/nagios-4.3.4 [following]
--2018-04-06 17:07:18-- https://codeload.github.com/NagiosEnterprises/nagioscore/tar.gz/nagios-4.3.4
Resolving codeload.github.com (codeload.github.com)... 192.30.253.121, 192.30.253.120
Connecting to codeload.github.com (codeload.github.com)|192.30.253.121|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘ nagioscore.tar.gz’
[ < => ] 11,102,207 562KB/s in 34s
2018-04-06 17:07:53 (318 KB/s) - ‘ nagioscore.tar.gz’ saved [11102207]
Extract the package and move into the extracted directory
[root@localhost ~]# tar -zxf nagioscore.tar.gz
[root@localhost ~]# cd nagioscore-nagios-4.3.4/
Next, configure, compile and install them similar to config files init script
root@localhost nagioscore-nagios-4.3.4]# ./configure & & make all & & make install & & make install-init & & make install-config & & make install-commandmode
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
.
.
.
.
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***
Remember, these are *SAMPLE* config files. You' ll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
Next, run the pre-flight check by using the following command
[root@localhost nagioscore-nagios-4.3.4]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.3.4
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2017-08-24
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
.
.
.
.
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
Now you have to install Nagios plugins by using the following command,
[root@localhost nagioscore-nagios-4.3.4]# yum install nagios-plugins-all -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.xeonbd.com
* epel: epel.scopesky.iq
* extras: mirror.xeonbd.com
* updates: mirrors.viethosting.com
* webtatic: sp.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package nagios-plugins-all.x86_64 0:2.2.1-4git.el7 will be installed
--> Processing Dependency: nagios-plugins-breeze for package: nagios-plugins-all-2.2.1-4git.el7.x86_64
--> Processing Dependency: nagios-plugins-by_ssh for package: nagios-plugins-all-2.2.1-4git.el7.x86_64
--> Processing Dependency: nagios-plugins-dhcp for package: nagios-plugins-all-2.2.1-4git.el7.x86_64
--> Processing Dependency: nagios-plugins-dig for package: nagios-plugins-all-2.2.1-4git.el7.x86_64
--> Processing Dependency: nagios-plugins-disk for package: nagios-plugins-all-2.2.1-4git.el7.x86_64
.
.
.
.
nagios-plugins-mrtg.x86_64 0:2.2.1-4git.el7 nagios-plugins-mrtgtraf.x86_64 0:2.2.1-4git.el7 nagios-plugins-mysql.x86_64 0:2.2.1-4git.el7
nagios-plugins-nagios.x86_64 0:2.2.1-4git.el7 nagios-plugins-nt.x86_64 0:2.2.1-4git.el7 nagios-plugins-ntp.x86_64 0:2.2.1-4git.el7
nagios-plugins-ntp-perl.x86_64 0:2.2.1-4git.el7 nagios-plugins-nwstat.x86_64 0:2.2.1-4git.el7 nagios-plugins-oracle.x86_64 0:2.2.1-4git.el7
nagios-plugins-overcr.x86_64 0:2.2.1-4git.el7 nagios-plugins-perl.x86_64 0:2.2.1-4git.el7 nagios-plugins-pgsql.x86_64 0:2.2.1-4git.el7
nagios-plugins-ping.x86_64 0:2.2.1-4git.el7 nagios-plugins-procs.x86_64 0:2.2.1-4git.el7 nagios-plugins-real.x86_64 0:2.2.1-4git.el7
nagios-plugins-rpc.x86_64 0:2.2.1-4git.el7 nagios-plugins-sensors.x86_64 0:2.2.1-4git.el7 nagios-plugins-smtp.x86_64 0:2.2.1-4git.el7
nagios-plugins-snmp.x86_64 0:2.2.1-4git.el7 nagios-plugins-ssh.x86_64 0:2.2.1-4git.el7 nagios-plugins-swap.x86_64 0:2.2.1-4git.el7
nagios-plugins-tcp.x86_64 0:2.2.1-4git.el7 nagios-plugins-time.x86_64 0:2.2.1-4git.el7 nagios-plugins-ups.x86_64 0:2.2.1-4git.el7
nagios-plugins-users.x86_64 0:2.2.1-4git.el7 nagios-plugins-wave.x86_64 0:2.2.1-4git.el7 net-snmp-utils.x86_64 1:5.7.2-28.el7_4.1
ntp.x86_64 0:4.2.6p5-25.el7.centos.2 postgresql-libs.x86_64 0:9.2.23-3.el7_4 qstat.x86_64 0:2.11-13.20080912svn311.el7
samba-client.x86_64 0:4.6.2-12.el7_4 samba-common-libs.x86_64 0:4.6.2-12.el7_4
Complete!
Remove the following location and create the soft link from /usr/lib64/nagios/plugins /usr/local/nagios/libexec Where all plugins got installed
[root@localhost libexec]# rm -rf /usr/local/nagios/libexec
[root@localhost ~]# ln -s /usr/lib64/nagios/plugins /usr/local/nagios/libexec
[root@localhost ~]# chown -R nagios:nagios /usr/local/nagios/libexec
Start and enable your Nagios service
[root@localhost ~]# systemctl start nagios
[root@localhost ~]# systemctl enable nagios
Next, create Nagios admin credentials.
[root@localhost ~]# htpasswd -c /usr/local/nagios/passwd nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin Creating directory for user and creating links [root@localhost ~]# mkdir /usr/local/nagios/share/nagios [root@localhost ~]# cd /usr/local/nagios/share/nagios/ [root@localhost nagios]# ln -s /usr/local/nagios/share/stylesheets/ stylesheets [root@localhost nagios]# ln -s /usr/local/nagios/share/js js
Next, install spawn-fcgi and fcgi-devel
[root@localhost nagios]# yum install fcgi-devel spawn-fcgi -y
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirror.xeonbd.com
* epel: epel.scopesky.iq
* extras: mirror.xeonbd.com
* updates: mirrors.viethosting.com
* webtatic: sp.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package fcgi-devel.x86_64 0:2.4.0-25.el7 will be installed
--> Processing Dependency: fcgi = 2.4.0-25.el7 for package: fcgi-devel-2.4.0-25.el7.x86_64
--> Processing Dependency: libfcgi++.so.0()(64bit) for package: fcgi-devel-2.4.0-25.el7.x86_64
--> Processing Dependency: libfcgi.so.0()(64bit) for package: fcgi-devel-2.4.0-25.el7.x86_64
---> Package spawn-fcgi.x86_64 0:1.6.3-5.el7 will be installed
--> Running transaction check
---> Package fcgi.x86_64 0:2.4.0-25.el7 will be installed
--> Finished Dependency Resolution
.
.
.
.
Verifying : fcgi-devel-2.4.0-25.el7.x86_64 1/3
Verifying : fcgi-2.4.0-25.el7.x86_64 2/3
Verifying : spawn-fcgi-1.6.3-5.el7.x86_64 3/3
Installed:
fcgi-devel.x86_64 0:2.4.0-25.el7 spawn-fcgi.x86_64 0:1.6.3-5.el7
Dependency Installed:
fcgi.x86_64 0:2.4.0-25.el7
Complete!
Installing fcgiwrap and installing by compiling binaries
[root@localhost nagios]# cd /usr/local/src/ & & git clone https://github.com/gnosek/fcgiwrap.git & & cd fcgiwrap & & autoreconf -i & & ./configure & & make & & make install
Cloning into ' fcgiwrap' ...
remote: Counting objects: 270, done.
remote: Total 270 (delta 0), reused 0 (delta 0), pack-reused 270
Receiving objects: 100% (270/270), 63.35 KiB | 0 bytes/s, done.
Resolving deltas: 100% (139/139), done.
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for FCGX_Init in -lfcgi... yes
checking for systemd... no
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
.
.
.
.
config.status: creating Makefile
config.status: creating config.h
cc -std=gnu99 -Wall -Wextra -Werror -pedantic -O2 -g3 fcgiwrap.c -lfcgi -o fcgiwrap
install -d -m 755 /usr/local/sbin
install -m 755 fcgiwrap /usr/local/sbin
install -d -m 755 /usr/local/man/man8
install -m 644 fcgiwrap.8 /usr/local/man/man8
After this finally, add the following in the spawn-fcgi file
[root@localhost fcgiwrap]# vim /etc/sysconfig/spawn-fcgi
FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=nginx
FCGI_GROUP=nginx
FCGI_EXTRA_OPTIONS=" -M 0700"
OPTIONS=" -u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"
Start and enable spawn-fcgi
[root@localhost system]# systemctl start spawn-fcgi
[root@localhost system]# systemctl enable spawn-fcgi
spawn-fcgi.service is not a native service, redirecting to /sbin/chkconfig.
Next, navigate to your browser and type http://yourdomainname
With this, the method to install and configure Nagios core with Nginx on Centos 7.4 comes to an end.
Comments ( 0 )
No comments available