How to Monitor Server Logs in Real-Time with Tool on RHEL 7 /CentOS 7


1.Introduction is a small simple but effective application build on top of Node.js and, which allows to monitor Linux servers log files in real time through web interface screen widgets. This guide will help you to monitor server log with on CentOS 7 / RHEL 7.

2.Operating System

This article is based on RHEL 7 / CentOS 7 .


3.1 Add Epel Repositories

Install Epel repositories by running the following command.

# yum install

After you added Epel Repos, do a system upgrade by running the following command.

# yum update

Install Node.js and NPM Packages

Node.js is a Java-script server-side programming platform which allows you to create an applications with back-end functionality. NPM (Node Package Manager) is package manager for Node.js, So the next step is to install Node.js and NPM binaries on your system through the following command.

# yum install npm nodejs 

3.3 Install and Configure Application application must be installed on your system through NPM by specifying a valid system user, through which the installation must take place. So here we can install the application as root user. For installing run the below command.

# npm install -g --user “root”

After installation has been completed change the working directory to folder, which is hidden under the “/root” directory.

[root@sapin-centos7 ~]# pwd
[root@sapin-centos7 ~]# cd
[root@sapin-centos7]# ll
total 12
-rw-r--r-- 1 root root 225 Jan 18 17:21 harvester.conf
-rw-r--r-- 1 root root  56 Jan 18 16:24 log_server.conf
-rw-r--r-- 1 root root 516 Jan 18 17:22 web_server.conf

Now it’s time to configure to monitor local log files in real time.
There are mainly three configuration files and are listed below.

> harvester.conf
> log_server.conf
> web_server.conf


This the configuration file for harvester, it is nothing but a log forwarder which keeps on watching log files for changes, send new log to the server. We can configure nodeName, what are all logs to watched and where to send a log. By default it only monitors Apache log files such us “access_logs and error_logs”, Here we have to replace the nodeName statement to match your hostname and also you have to add the logStreams statements with what internal log files that you want to monitor.

exports.config = {
  nodeName: "",
  logStreams: {
    apache: [
  server: {
    host: '',
    port: 28777

Also if you don’t need harvester output to be sent to a remote server change the line host on server statement to only send its output locally by modifying address with loopback address (


For security reasons, if you are not expecting remote harvesters output to your local server, Open log_server.conf file and replace address with loopback address (

exports.config = {
  host: '',
  port: 28777


This the configuration file of web interface, this alters the functionality of the web portal. By-default, web portal is accessible on port no 28778 and on all interface. This file offers a way to increase the security by putting HTTP authentication,securing the web interface with SSL, disallowing logs from specific ip address and restricting the web interface access to the specific ip.

exports.config = {
  host: '',
  port: 28778,

  // Enable HTTP Basic Authentication
  auth: {
    user: "admin",
    pass: "adminlogin"

  // Enable HTTPS/SSL
  ssl: {
    key: '/path/to/privatekey.pem',
    cert: '/path/to/certificate.pem'

  // Restrict access to websocket (
  // Uses 'origins' syntax
  restrictSocket: '*:*',

  // Restrict access to http server (express)
  restrictHTTP: [


3.4 Add Firewall Rule and Start Application

For web access to server add a rule on RHEL/CentOS 7 Firewall to open TCP 28778 port by issuing the following command.

firewall-cmd --add-port=28778/tcp --permanent
firewall-cmd --reload

3.5 Start Application

For start log monitoring application assure that your current working directory is “/root” and use the following commands in the following order to start application.

> First start server, put it in background and press Enter key & 

> Start log harvester in background & 
[root@sapin-centos7]# &
[1] 16427
[root@sapin-centos7]#    info  - started

[root@sapin-centos7]# &
[2] 16431

4. Access Web Interface

Then open your web browser and visit http://your-ip-address:28778. You will get the following page with logs.

5. Conclusion

We have successfully installed and configured a real-time log monitoring tool “” on CentOS 7 / RHEL 7. is an excellent and effective web application to monitor local or remote servers log files is real time and get an outlook on what is going internally in the systems and especially to debug server problems when systems tend to become unresponsive or crashes, without the need to use a console.


Scheduling Shutdown Automatically in centos 7

Shut down


Shutdown automatically in a centos 7 server is a very easy task. It is possible to set shutdown operation at any time as per your need. It is very helpful task while running any installtion or other processes in the system that could be finished during night time or unavailable time for the client.This article shows you how to set shutdown automatically.

Execute shutdown command

Execute following command to shutdown the system at 15:00, never forget timing will set in 24hr format.

# shutdown 15:00

Cancel scheduled shutdown task

To cancel scheduled shutdown task, run following command

# shutdown -c 
Broadcast message from (Mon 2016-01-18 23:24:16 MSK):
The system shutdown has been cancelled at Mon 2016-01-18 23:25:16 MSK!

Using Cron job

Also by setting cronjob, it is possible to shutdown the system automatically.

# crontab -e

Add the following cron job

0 15 * * * /sbin/shutdown 

Restart crond service

# /bin/systemctl restart crond.service

Please make sure to remove the cronjob too.

How to Install Varnish on CentOS 7 or RHEL 7

Varnish cache

1. Introduction

Varnish is a proxy and cache, or HTTP accelerator, designed to improve performance for busy, dynamic web sites. By redirecting traffic to static pages, varnish reduces the number of dynamic page calls, thus reducing load. Varnish is designed for content-heavy dynamic web sites as well as heavily consumed APIs. In contrast to other web accelerators, such as Squid, or Apache and nginx, which are primarily origin servers, Varnish was designed as an HTTP accelerator.

2. Varnish Cache Performance Parameters

Once installed, Varnish Cache allows us to use several apps to evaluate the server by means of statistics. These apps are the ones mentioned below.

  • varnishtop: grouped list with the most usual entries from different logs.
  • varnishhist: a histogram that shows the time taken for the requests processing.
  • varnishsizes: it performs the same task as “varnishhist” but showing the size of the objects.
  • varnishstat: it shows many contents on cache hits, resource consumption, etc..
  • varnishlog: it allows us to see all the requests made to the web backend server.

3. Requirements

You may need an operating system RHEL 7 or Centos 7 in your dedicated or vps server. Please make sure to set a hostname for your server and its dns is pointing to the IP address of the server.

4. Installation Steps

Before you begin please install LAMP(Linux Apache Mysql PHP) in your server. To install LAMP, Please refer the documentation from here

Update your server with latest packages.

# yum update

Now install varnish on Centos.

# yum install varnish

4.1 How to setup Varnish 4 for Apache

# vi /etc/varnish/varnish.params

Change Listen Port to 80 as we are going to run Varnish in front of Apache:


Now edit Apache configuration file:

# vi /etc/httpd/conf/httpd.conf

Then look for the line that says “Listen 80” and change it to “Listen 8080”

Now restart Apache at first so the webserver run on port 8080 leaving port 80 being usable by Varnish:

# systemctl restart httpd.service
# systemctl restart varnish.service

# systemctl enable varnish.service

You can see varnish running on port 80 using the following command:

# netstat -tunlp | grep :80
tcp        0      0  *               LISTEN      22368/httpd
tcp        0      0    *               LISTEN      22145/varnishd

5. Testing varnish

# varnishd -V

Gives you an output something like this:

varnishd (varnish-3.0.7 revision f544cd8)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2014 Varnish Software AS

You can check it like this

# curl -I 
# curl -I
HTTP/1.1 403 Forbidden
Date: Sun, 17 Jan 2016 10:42:54 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
Last-Modified: Thu, 16 Oct 2014 13:20:58 GMT
ETag: "1321-5058a1e728280"
Accept-Ranges: bytes
Content-Length: 4897
Content-Type: text/html; charset=UTF-8
X-Varnish: 13
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive

How to install Nagios and NRPE in Centos 7 or RHEL 7

1. Introduction

Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.
Nagios runs periodic checks on user-specified resources and services.

Resources that can be monitored include:
Memory usage
Disk usage
Microprocessor load
The number of currently running processes
Log files.

Services that can be monitored include:
Simple Mail Transfer Protocol (SMTP)
Post Office Protocol 3 (POP3)
Hypertext Transfer Protocol (HTTP) and other common network protocols.

A user-friendly Web-based graphical user interface is provided. An authorization system allows the administrator to restrict access as necessary.

2. Features

  • Monitor your entire IT infrastructure;
  • Identify problems before they occur;
  • Know immediately when problems arise;
  • Share availability data with stakeholders.hypothetical question;
  • Detect security breaches;
  • Plan and budget for IT upgrades;
  • Reduce downtime and business losses.

3. Prerequisition

Nagios server:

Operating system : CentOS 7
IP Address :

Nagios client:

Operating System : ubuntu 15.10
IP Address :

If you have a fresh server you should configure lamp stack on the same.

Also install the following prerequisites too. All commands should be run as root user.

# yum install gd gd-devel gcc glibc glibc-common wget

Nagios user and group

 #useradd -m nagios
 #passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

   # groupadd nagcmd
   #usermod -a -G nagcmd nagios
   #usermod -a -G nagcmd apache

4. Download Nagios And Plugins

By using wget utility we can retrieve files for the installation of latest version of Nagios.

For a good practise download the files in to “/usr/local/src”.

#cd /usr/local/src


Download nagios plugins too. Nagios plugins allow you to monitor hosts, devices, services, protocols, and applications with Nagios.


5. Install Nagios And Plugins

5.1 Install nagios:

Change directory to “/usr/local/src” and extract nagios.

#tar xzf nagios-4.1.1.tar.gz

change to the nagios directory then compile and install.

#cd nagios-4.1.1/
#sudo ./configure --with-command-group=nagcmd
#make all
#make install
#make install-init
#make install-config
#make install-commandmode

5.2 Install Nagios Web interface

Enter the following commands to compile and install nagios web interface.

 #make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account. You’ll need it while logging in to nagios web interface..

# sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache to make the new settings take effect.

#systemctl restart httpd

5.3 Install Nagios plugins

Go to the directory /usr/local/src where you downloaded the nagios plugins, and extract it.

#cd /usr/local/src
#tar xzf nagios-plugins-2.0.3.tar.gz

After extracting down loaded file change directory to nagios-plugins by using cd commandand compile and install plugins

#cd nagios-plugins-2.0.3
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make install

6.Access Nagios Web Interface

Open nagios administrator console with URL http://nagios-server-ip/nagios and enter the username as “nagiosadmin” and its password which we created in the earlier steps.

Now we can see home page of Nagios, there is an option “Hosts”on the left panel ,by clicking on that we can see hosts currently monitoring by the Nagios server.

Here we can see that Host status and details of host.

In left panel there is an option “Services” which shows that the current status of all services of the localhost.

7.Add Monitoring targets to Nagios server

Now nagios server is ready to monitor so, the next step is to add Nagios clients to monitor, Here Ubuntu 15.10 server has been taken as nagios client.

nrpe and nagios-plugins are need to add in our monitoring targets.

#apt-get install nagios-nrpe-server nagios-plugins

7.1 Configure nagios Client

Then add the nagios server IP to which nagios client should be listen.

Edit /etc/nagios/nrpe.cfg file,Add your Nagios server ip address:

# vi /etc/nagios/nrpe.cfg

Start nrpe service on Ubuntu client:

/etc/init.d/nagios-nrpe-server restart

Now, go back to your Nagios server, and add the clients in the configuration file.

open “/usr/local/nagios/etc/nagios.cfg” and uncomment below line:

# vi /usr/local/nagios/etc/nagios.cfg


Create a directory called “servers” under “/usr/local/nagios/etc/”.

# mkdir /usr/local/nagios/etc/servers

Create config file to the client to be monitored and make changes as follows

$vi /usr/local/nagios/etc/servers/clients.cfg

define host{
use                             linux-server
host_name                       arunima-ubuntu15 
alias                           arunima-ubuntu15 
max_check_attempts              5
check_period                    24x7
notification_interval           30
notification_period             24x7

Here my nagios client ip is “” and hostname arunima-ubuntu15 .

Then restart nagios server

#systemctl restart nagios

Wait for few seconds, and refresh nagios admin console in the browser and navigate to “Hosts” section in the left pane. You will see the newly added client will be visible there. Click on the host to see if there is anything wrong or any alerts it has.


Define services

We have just defined the monitoring host. Now, let us add some services of the monitoring host. Here i have added ssh, ftp and http services to monitor.

# vi /usr/local/nagios/etc/servers/clients.cfg

define service {
        use                             generic-service
        host_name                       arunima-ubuntu15
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
define service {
        use                             generic-service
        host_name                       arunima-ubuntu15
        service_description             VSFTPD
        check_command                   check_ftp
        notifications_enabled           0
define service {
        use                             generic-service
        host_name                       arunima-ubuntu15
        service_description             HTTPD
        check_command                   check_http
        notifications_enabled           0

Before adding services to monitor make sure that all are currently running in nagios client.

#systemctl restart nagios

Navigate your browser to http://IP-Address/nagios and enter the Username and Password then click “Hosts”, Here you can see the new linux host and status of services which has been added.

nagios screen shorts

How to install and Configure PostgreSQL with phpPgAdmin on CentOs 7

1. Introduction

PostgreSQL is an powerful open-source relational database management system that provides an implementation of the SQL querying language. phpPgAdmin is web-based client written in php for accessing and managing PostgreSQL databases. This article will help you to install PostgreSQL with phpPgAdmin on centos 7.

2. Requirements

Before installing it make sure you have Apache installed on server.

3. Install PostgreSQL

In order to install the latest version of PostgreSQL we need to download postgresql repository in our system. So you may run the following command:

# wget

Then you have to install this rpm repository using:

# rpm -i pgdg-redhat94-9.4-1.noarch.rpm

Now install PostgreSQL using yum:

# yum install postgresql94-server postgresql94-contrib

You have to initialise the database after the installation is completed using the below command:

# /usr/pgsql-9.4/bin/postgresql94-setup initdb

Start the PostgreSQL service and make it to start automatically at every reboot.

# systemctl start postgresql-9.4
# systemctl enable postgresql-9.4

3.1 Login to postgresql

During the installation a user ‘postgres’ will be created by default. Switch to user postgres:

# su - postgres

Run the command below to login to PostgreSQL

psql (9.4.0)
Type "help" for help.

You can change the default password of postgres using following command:

postgres=# \password postgres
postgres=# \q

Create a user and database in PostgreSQL command line and itself. Also grant access to the database for the created user.

-bash-4.2$ createuser alice
-bash-4.2$ createdb db
-bash-4.2$ psql
postgres=# alter user alice with encrypted password 'alice123';
postgres=# grant all privileges on database db to alice;
postgres=# \q
-bash-4.2$ exit

4. Install phpPgAdmin

Install phpPgAdmin using the command:

# yum install phpPgAdmin

5. Configure phpPgAdmin

Edit the file /etc/httpd/conf.d/phpPgAdmin.conf and make changes accordingly.

Alias /phpPgAdmin /usr/share/phpPgAdmin

        # Apache 2.4
        Require all granted
        #Require host
        # Apache 2.2
        Order deny,allow
        Allow from all
        Allow from
        Allow from ::1
        # Allow from

# vi /etc/phpPgAdmin/

Also edit the php file as follows:

$conf['servers'][0]['host'] = 'localhost';

$conf['servers'][0]['port'] = 5432;

$conf['owned_only'] = true;

6. Configure PostgreSQL

Configure PostgreSQL-MD5 Authentication by editing the file /var/lib/pgsql/9.4/data/pg_hba.conf

# vi /var/lib/pgsql/9.4/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all               md5
host    all             all             md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

Configure TCP/IP

# vi /var/lib/pgsql/9.4/data/postgresql.conf

Edit the file and make following changes 
listen_addresses = 'localhost'
port = 5432

Save the file and restart the services:

# systemctl restart postgresql-9.4

# systemctl restart httpd

Now open your browser and navigate to http://ip-address/phpPgAdmin.

How to install zend optimizer in Centos 7


Zend Optimizer is a free application that allows PHP to run files encoded by Zend Guard. Zend Optimizer greatly enhances the performance of PHP applications.
The Zend Optimizer goes over the code generated by the standard Zend run-time compiler and optimizes it for faster execution. The standard Zend run-time compiler used by PHP is indeed very fast, generating code that is usually 2 to 10 times faster. But an application that uses Zend Optimizer can execute scripts another 40% to 100% faster.


The following are the software requirement for this installation.

  • Operating System : Centos 7/64bit
  • Web server : Apache 2.4
  • PHP version : 5.4
  • Databae : MariaDB 5.5

You should have a dedicated or VPS centos server with LAMP or LEMP stack.

Install Zend Optimizer

Zend Guard optimization depends on both operating system (64/32 bit) and Php version of the server.

Before starting optimization check the current version of the PHP running in the server.

# arch

# php -v
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Now we can download the appropriate Zend Guard package for the operating system (centos7/64 bit) and PHP version (PHP 5.4) on the server.

Zend Guard Loader (Runtime for PHP 5.4) 64-bit:

# cd /usr/local/src
# wget

Extract the down loaded package by using tar (tape Archeive)command:

[root@arunima-centos7 src]# tar xzvf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz
[root@arunima-centos7 src]# cd ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/

The new folder extracted contains file and copy it to /etc/php.d/ZendGuard.ini. See example below (use cd command)

# cd php-5.4.x
[root@arunima-centos7 php-5.4.x]# ll
total 1044
-rwxrwxrwx 1 894 nobody 1068334 May  8  2013

# cp /usr/lib64/php/modules

Now create ZendGuard.ini file inside /etc/php.d directory:

# vi /etc/php.d/ZendGuard.ini

Server is 64-bit then add below lines to the file /etc/php.d/ZendGuard.ini

; Enable Zend Guard extension

Restart apache service to update changes

# systemctl restart httpd.service

Now check it bye using php -v you can see that php is optimized with zend guard

[root@arunima-centos7 modules]# php -v
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies


Thus we have optimized our php scripts with apache in simple steps.
Note: In case of 32-bit server: zend_extension wil be /usr/lib/php/modules/ .

How To Install Ruby on Rails with rbenv on CentOS 7 or RHEL 7

1. Introduction

This article helps you install and configure Ruby on Rails on CentOS 7. By following some simple steps you can start riding on rails. Please feel free to let us know if you got struck anywhere, we will help you fix it.

2. Prerequisites

Here, We assume that you are having a CentOS 7 installed server with root access. Before continuing the installation we need to install LAMP/LEMP. You can follow the link to install LAMP and then proceed with the installation.

3. Installation

First of all, let me provide you a very short description about Ruby on Rails. Ruby is a programming language and while rails is just a Web application frame work which works on the principle (Model-View-Controller) MVC. Ruby on Rails is nothing but simply a web application framework written in Ruby. You can check there official link to know more.

3.1. Installation of Rbenv

Rbenv is a ruby version management tool. We will use this to install and manage our Ruby installation. So let’s start the installation of rbenv.

Installing the dependencies of Rbenv and Ruby. Use the following commands to install the dependencies.

# yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel

Now we are going to edit the bash profile file of the user who is going to use ruby. So make sure to take a backup of the .bash_profile at first . Then you may execute the following commands as the same user.

# cd
# git clone git:// .rbenv
# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
# echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# source ~/.bash_profile
# git clone git:// ~/.rbenv/plugins/ruby-build
# echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
# source ~/.bash_profile

Your bash profile look like the screen shot given below.

Thus you have installed rbenv. After completing this step, please open a new terminal to start using rbenv otherwise it will show “rbenv not found error”. Now we are ready to install Ruby.

3.2 Installation of Ruby

Before starting the installation, Check which version of ruby you want to install. Here, We are installing Ruby 2.2.1.
You may execute the commands below to install Ruby.

# rbenv install -v 2.2.1

The next step is to sets the default version of Ruby that all of your shells will use. If you want to install and use a different version, simply run the rbenv commands with a different version number.

# rbenv global 2.2.1

You can verify the installation using the command below. It will show you the version and details of the installation.

[root@hostname-centos7 ~]# ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]

Most of us do not want the documentation of each gems we install. If you would like to disable this, you may execute the command as below.

# echo "gem: --no-document" > ~/.gemrc

Now, Install the bundler gem which is used to manage your application dependencies using the following commands.

# gem install bundgem install bundlerler

Thus the Ruby is installed. Now we can move on to the installation of Rails.

3.3 Installation of Rails

As the same user who installed Ruby, execute the command below to install Rails. Here, We are installing Rails 4.2.0 version.

# gem install rails -v 4.2.0

We need to run rbenv rehash command whenever we use gem. to install/uninstall. The rbenv normally runs rbenv rehash automatically when you install/uninstall using gem. But to make sure, you may execute following command every time you use gem command.

# rbenv rehash

To check the version of Rails, you can execute the command below.

[root@hostname-centos7 ~]# rails -v
Rails 4.2.0

Thus, We have completed the installation of Ruby on Rails.

4. Apache Configuration (Configuring Ruby to run on Port 80)

Normally, The Ruby on Rails application run on port 3000. So, we need to specify the port all the time we access any of the ruby application. To avoid this, We made here a very simple proxy setup in apache configuration. The configuration is as follows.

ProxyPreserveHost On
ProxyPass / http://yourip:3000/
ProxyPassReverse / http://yourip:3000/

In the above configuration, you need to specify your IP address instead “yourip” and save the file. After that, you may just restart the apache to reflect the changes.

# systemctl restart httpd

Thus the proxy setup via apache configuration is completed. Now we can test its working by creating an application.

5. Create a Test Application

To make sure that the Ruby on Rails installation completed successfully, We can create a test application by following the steps below.

Create an application in your home directory as follows:

# cd ~
# rails new testapp

Now, move on to the application directory:

# cd testapp

Then, create a sqlite3 database:

# rake db:create

Thus the configuration has been completed. Now, you can start your application by following the commands. Look at the screenshot below.

# rails server --binding=server_public_IP

If it is running properly, You will get a welcome aboard page by visiting the URL below.


You will see a welcome aboard page. It is the smoke test for a new Rails application. it makes sure that you have your software configured correctly enough to serve a page.


6. Conclusion

Thus you are ready to start developing your new Ruby on Rails application. Enjoy !!