Monday, March 27, 2017

How to configure Postfix SMTP relay office365 on Centos 7.x

Postfix:

Postfix is a flexible mail server that is available on most Linux distribution. Though a full featured mail server, Postfix can also be used as a simple relay host to another mail server, or smart host. This tutorial will describe how to configure Postfix as a relay through Office365.

Requirement:

CentOS 7 or Red Hat Enterprise Linux 7
Valid Office365 email credentials.

Installation:

Install Postfix using command below

[root@localhost ~]# yum install postfix cyrus-sasl-plain mailx

Configuration changes:

Postfix main configuration file is main.cf, let's make the required change as follow:
[root@localhost ~]# vi /etc/postfix/main.cf
 Append the following line
relayhost = [smtp.office365.com]:587
mynetworks = 127.0.0.0/8
inet_interfaces = loopback-only
smtp_use_tls = yes
smtp_always_send_ehlo = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
smtp_generic_maps = hash:/etc/postfix/generic
#smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Save and exit from the file.

The configuration of postfix SASL credentials:

[root@localhost ~]# vi /etc/postfix/sasl_passwd
Add a line below
[smtp.office365.com]:587 user@domainname:password
Save and exit from file

A Postfix lookup table must now be generated from the sasl_passwd text file by running the following command.
[root@localhost ~]# postmap /etc/postfix/sasl_passwd
Now change permission for this file
[root@localhost ~]# chown root:postfix /etc/postfix/sasl_passwd
[root@localhost ~]# chmod 640 /etc/postfix/sasl_passwd

Next, we need to configure generic file in order to be able to send emails as a valid user (this is required for Office365).
[root@localhost ~]# vi /etc/postfix/generic

Go the end of file and append following lines.
root@localhost.localdomain UserName@Domain.com

Save and exit from file.

Next let's correct the file permission.
[root@localhost ~]# chown root:root /etc/postfix/generic
[root@localhost ~]# chmod 0600 /etc/postfix/generic
[root@localhost ~]# postmap /etc/postfix/generic

Now Change alias root to your email address.

[root@localhost ~]# vi /etc/aliases
Make the changes like below:
mailer-daemon:  postmaster
postmaster:     root
root:           UserName@Domain.com
Save and exit from the file.
Run command newaliases to take effect.
[root@localhost ~]# newaliases

Let's restart Postfix service.
[root@localhost ~]# systemctl restart postfix

Now try to send a test email using the command below:
FOR  Centos:

echo "This is the body of the email"| mail -r"Sender-Display-Name<sender@domain.com>" -s "This is the subject(E-Mail from SMTP Relay) line" recipeat@gmail.com

FOR Ubuntu:
echo "This is the body of the email" | mail -s "This is the subject(E-Mail from SMTP Relay) line" recipeat@gmail.com -a "FROM:Amar Singh<asingh@domain.com>"

You will get an email at recipeant@gmail.com 













Change root display name to Actual user name:

Bydefault when we send an email display name will be root let's modify root user's description by using the command below:

[root@localhost ~]# usermod -c "Amar Singh" root

Now sender name has been changed to the actual user name.

SMTP Relay Office365 has been configured successfully.


Friday, March 24, 2017

How to Install and configure Pnp4Nagios Bulk+NPCD Mode with Nagios4.x Centos 7.x

PNP4NAGIOS:-

Pnp4Nagios works with Nagios to generate the graph of services that are being monitored by Nagios server. With the help of Pnp4Nagios, we can see the graph anytime whenever needed,  It record graph for all the configured services, We can view usage like CPU, RAM, Disk Space etc.

Prerequisites:  

1- RRDTOOL, rrdtool-perl
2- Perl
3- Php-gd
4- perl-time-HiRes

Step 1-  Installation
To Install prerequisites run below command
[root@localhost ~]# yum install rrdtool perl-Time-HiRes rrdtool-perl php-gd

Once prerequisites installation done, download pnp4nagios.
Step 2- Download PNP4Nagios, Extract and Install
[root@localhost ~]# wget https://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.25.tar.gz
Once download get finished, extract package using command below
[root@localhost ~]# tar zxfv pnp4nagios-0.6.25.tar.gz
Go to the Extracted directory and configure it.
[root@localhost ~]# cd pnp4nagios-0.6.25
Configure pnp4nagios and install using command below
[root@localhost pnp4nagios]# ./configure
[root@localhost pnp4nagios]# make all
[root@localhost pnp4nagios]# make fullinstall

Enable NPCD service to start at boot time and start it now.
[root@localhost ~]# chkconfig --add npcd && chkconfig --level 35 npcd on

Let's reboot httpd service.
[root@localhost ~]# systemctl restart httpd

Step 2- Let's check PNP4Nagios installation.

Open browser and type URL:- 192.168.102.11/pnp4nagios/











































After successful PNP4Nagios installation, you will get the window like above.

Step 3- Let's rename install.php to install.php-bak
[root@localhost ~]# mv  /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php-bak

Step 4-  Make the required changes in Nagios configuration to integrate PNP4Nagios to generate graph.

Make the changes in nagios.cfg configuration file.
[root@localhost ~]# vi /usr/local/nagios/etc/nagios.cfg
Change the Process_performance_data=1 and append below mentions line.
# Bulk / NPCD mode
process_performance_data=1
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECH$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file

host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
Save and exit from file.
Now make the required changes in command.cfg file
[root@localhost ~]# vi /usr/local/nagios/etc/objects/commands.cfg
Go to the end of file and append the red line below and comment all the black line.
# 'process-host-perfdata' command definition
#define command{
#       command_name    process-host-perfdata
#       command_line    /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /usr/local/nagios/var/host-perfdata.out
#       }


# 'process-service-perfdata' command definition
#define command{
#       command_name    process-service-perfdata
#       command_line    /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /usr/local/nagios/var/service-perfdata.out
#       }

# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$$
}

# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$$
}

define command{
command_name process-service-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}

define command{
command_name process-host-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}



Let's make change in template.cfg file 
[root@localhost ~]# vi /usr/local/nagios/etc/objects/templates.cfg
Append the red line in the below of file.
# PNP4NAGIOS #
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
register 0
}

define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
Save and Exit from file

Now make the change in the host configuration fiel
[root@localhost ~]# vi /usr/local/nagios/etc/objects/localhost.cfg

Append the following lines in the end of file.
# Define a host for the local machine

define host{
        use                     linux-server,host-pnp            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }

# Define a service to "ping" the local machine
define service{
        use                             local-service,srv-pnp         ; Name of service template to use
        host_name                       localhost
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }
Save and exit from file.

All the configuration changed completed successfully.

Step 5-  Now restart httpd, Nagios and Npcd service using command below.
[root@localhost ~]# systemctl restart httpd && systemctl restart nagios && systemctl restart npcd

Step 6- Verify integration of PNP4Nagios

Open Nagios server URL:-  http://192.168.102.11/nagios/

After successful integration of PNP4nagios you get a graph symbol for each service like in below image:







And you will see graph for individual service image like below:























Congratulation!!! Installation and Integration of PNP4Nagios with Nagios server completed successfully done with Bulk+NPCD mode.

How to Install and configure Nagios 4.x on Centos 7.x


What Is Nagios Core:-

Nagios Core is an Open Source system and network monitoring application. It watches hosts and services that you specify, alerting you when things go bad and when they get better.

System Requirments:-


1- Linux machine (In my case I am using Centos7.X)
2- HTTPd, PHP with gd and CGI.

Nagios Installation:-

Step 1- Install and setup prerequisites 
 Install Deployment tool 
[root@localhost ~]# yum groupinstall "Development Tools"

Install PHP, HTTPD, Pearl and wget
[root@localhost ~]# yum install wget perl httpd php gcc glibc glibc-common gd gd-devel make net-snmp libpng-devel libjpeg-turbo-devel

Create nagios User and group:
[root@localhost ~]# useradd nagios && passwd nagios      ##Command to add user and set password ##
[root@localhost ~]# groupadd nagcmd                      ## Command to add group ##
[root@localhost ~]# usermod -a -G nagcmd nagios          ## command to add nagios user in group nagcmd ##
[root@localhost ~]# usermod -a -G nagcmd apache          ## Command to add apache user in group nagcmd ##

Step 2- Install and configure Nagios
Download Nagios stable release 
[root@localhost ~]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.4.tar.gz
 Extract and Configure
[root@localhost ~]# tar zxfv nagios-4.2.4.tar.gz
Now go to extracted directory
[root@localhost ~]# cd nagios-4.2.4

Configure Nagios for installation
[root@localhost nagios-4.2.4]# ./configure -with-command-group=nagcmd

Make and install all the configuration files
[root@localhost nagios-4.2.4]# make all
[root@localhost nagios-4.2.4]# make install
[root@localhost nagios-4.2.4]# make install-init
[root@localhost nagios-4.2.4]# make install-commandmode
[root@localhost nagios-4.2.4]# make install-config
[root@localhost nagios-4.2.4]# make install-webconf
Copy eventhandlers and set permission
[root@localhost nagios-4.2.4]# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

[root@localhost nagios-4.2.4]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Copy Check Nagios configuration and add Nagios login credentials 
[root@localhost nagios-4.2.4]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 4.2.4
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 12-07-2016
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.
        Checked 1 hosts.
        Checked 1 host groups.
        Checked 0 service groups.
        Checked 1 contacts.
        Checked 1 contact groups.
        Checked 26 commands.
        Checked 5 time periods.
        Checked 0 host escalations.
        Checked 0 service escalations.
Checking for circular paths...
        Checked 1 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Setup Nagios login credentials
[root@localhost nagios-4.2.4]#  htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:   *********
Re-type new password:   *********

Adding password for user nagiosadmin

Install Nagios Plugins and NRPE client
[root@localhost nagios-4.2.4]# yum install nagios-plugins-all nagios-plugins-nrpe

Update Firewall-cmd and allow http access
[root@localhost nagios-4.2.4]# firewall-cmd --permanent --add-service=http

[root@localhost nagios-4.2.4]# firewall-cmd --reload

Change plugins access user from this file "usr/local/nagios/etc/resource.cfg"
[root@localhost nagios-4.2.4]# vi /usr/local/nagios/etc/resource.cfg
Made changes as follow
# Sets $USER1$ to be the path to the plugins
#$USER1$=/usr/local/nagios/libexec
$USER1$=//usr/lib64/nagios/plugins
# Sets $USER2$ to be the path to event handlers
#$USER2$=/usr/local/nagios/libexec/eventhandlers
Enable Nagios and httpd service to start at boot time 
[root@localhost nagios-4.2.4]# systemctl enable httpd && systemctl enable nagios
Now reload httpd and nagios service
[root@localhost nagios-4.2.4]# systemctl restart httpd && systemctl restart nagios

Installation and configuration part completed successfully.
Let's check through URL: http://192.168.102.11/nagios/



















!!! Congrats Nagios 4.x installation and configuration part completed successfully !!!


In the next blog we will learn how to configure pnp4nagios to generate graph and view usage of resource whenever needed.



Friday, March 17, 2017

How to Install Nagios 3.x on Centos 6.7 final release

What Is Nagios Core:-

Nagios Core is an Open Source system and network monitoring application. It watches hosts and services that you specify, alerting you when things go bad and when they get better.

System Requirments:-

1- Linux machine (In my case I am using Centos 6.7)
2- HTTPd, PHP with gd and CGI.

Nagios Installation:-

 Step 1- 
Add repository first to install Nagios
[root@odoo ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.2nIBRS: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]
[root@odoo ~]#

[root@odoo ~]# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Retrieving http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
warning: /var/tmp/rpm-tmp.f5McIF: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing...                ########################################### [100%]
   1:remi-release           ########################################### [100%]

 Step 2- Complete installation & configuration part:

Run yum update
[root@odoo ~]# yum update
Install HTTPd server
[root@odoo ~]# yum install httpd
Install PHP
[root@odoo ~]# yum install php php-cli php-gh php-common

Install Nagios
[root@odoo ~]# yum install nagios nagios-plugins-all nagios-plugins-nrpe nrpe
Check Nagios version
[root@odoo ~]# nagios -v
Enable httpd and Nagios service to start auto during system boot or restart
[root@odoo ~]# chkconfig httpd on && chkconfig nagios on
Start httpd & Nagios service
[root@odoo ~]# service httpd start && service nagios start
Open Port 80 through iptables
[root@odoo ~]# vi /etc/sysconfig/iptables
Modify config file like below
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

Save and exit from file & restart iptables service
[root@odoo ~]# service iptables restart
 Step 3- Setup Nagios login details
 Set Nagios user name and password
[root@odoo ~]# htpasswd -c /etc/nagios/passwd nagiosadmin
New password: *******
Re-type new password:  ******
Adding password for user nagiosadmin

 Step 4- Validate authentication & installation.
Check Nagios login using URL below















After successful authentication, you will get the window like below.













!!!!!!!! Installation of Nagios completed successfully !!!!!!!!