
Nagios is an open-source monitoring tool, can be deployed on Ubuntu, centos/rhel machines. In this tutorial, we will be deploying Nagios Core on Centos 7.4 cloud vm hosted at Google Cloud Platform, and run it behind Nginx web server.
Guide:
Step-1: Creating a Cloud Instance on GCP [ Google Cloud Platform ], following image illustrates building a Centos 7.x image

Centos 7 VM creation on Google Cloud PlatformStep-2: Following is the image which shows the instance details

GCP Instance details
Step-3: Adding the DNS and settings FQDN on cloud flare
DNS and FQDN Settings on cloudflare

Step-4: Adding the DNS and settings FQDN on vm instance
$ sudo vi /etc/hosts
IPV4_ADDRESS FQDN SHORT_HOSTNAME
Step-5: Verifying FQDN
$ hostname
$ hostname -i
$ hostname -f
Step-6: Setting Locale
$ sudo timedatectl set-timezone Asia/Kolkata
Step-7: Set SELinux in permissive mode
$ sudo su -
$ setenforce 0
Step-8: Install Dev Tools, PHP, Nginx
$ sudo yum install nginx php php-fpm php-common gcc glibc glibc-common gd gd-devel make net-snmp unzip -y
$ sudo yum groupinstall 'Development Tools' -y
Step-9: Nginx – Nagios Configuration
$ cd /etc/nginx/conf.d
$ sudo vi nagios.conf
server {
listen 80;
server_name nagios.yebbare.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;
}
}
Step-10: Firewall Configuration
sudo firewall-cmd --permanent --add-port=80/tcp --zone=public
sudo firewall-cmd --reload
Step-11: Creating User
useradd nagios
usermod -aG nagios nginx
Step-12: create nagios.conf for PHP-FPM
sudo vi /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
Step-13: Restarting PHP-FPM and Enabling at start-up
sudo systemctl restart php-fpm
sudo systemctl enable php-fpm
Step-14: Download Nagios Core
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.3.4.tar.gz
Step-15: Extracting the Binaries
tar zxf nagios-4.3.4.tar.gz
cd nagios-4.3.4
Step-16: Compiling the binaries and installing Nagios
sudo su -
cd nagios-4.3.4
./configure
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
Step-17: Verifying Nagios Configuration
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Step-18: Installing Extra Plugins
yum install nagios-plugins-all -y
Step-19: creating soft link for new pluginas and also remove the default plugins
rm -rf /usr/local/nagios/libexec
ln -s /usr/lib64/nagios/plugins /usr/local/nagios/libexec
chown -R nagios:nagios /usr/local/nagios/libexec
Step-20: Start Nagios and Enable nagios for startup at boot
systemctl start nagios
systemctl enable nagios
Step-21: Creating password for nagiosadmin user
htpasswd -c /usr/local/nagios/passwd nagiosadmin
Step-22: Creating directory for user and creating links
mkdir /usr/local/nagios/share/nagios
cd /usr/local/nagios/share/nagios/
ln -s /usr/local/nagios/share/stylesheets/ stylesheets
ln -s /usr/local/nagios/share/js js
Step-23: Installing spawn-fcgi
yum install fcgi-devel spawn-fcgi -y
Step-24: Installing fcgiwrap and installing by compiling binaries
cd /usr/local/src/
git clone https://github.com/gnosek/fcgiwrap.git
cd fcgiwrap
autoreconf -i
./configure
make
make install
Step-25: Adding the spawn-fcgi configuration
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"
Step-26: Starting and Enabling Spawn-fcgi
systemctl start spawn-cgi
systemctl enable spawn-cgi
No comments:
Post a Comment
If you have any doubts or questions, please let us know.