Download pflogsumm
  •  wget http://jimsun.linxnet.com/downloads/pflogsumm-1.1.1.tar.gz
  •  tar -zxf pflogsumm-1.1.1.tar.gz
  • cd pflogsumm-1.1.1

Generate the statistics  :-
#  cat /var/log/maillog | ./pflogsumm.pl

 Grand Totals
------------
messages

   8596   received
   8606   delivered
      0   forwarded
      0   deferred
      0   bounced
      0   rejected (0%)
      0   reject warnings
      0   held
      0   discarded (0%)

  77044k  bytes received
  77324k  bytes delivered
      7   senders
      2   sending hosts/domains
     13   recipients
      4   recipient hosts/domains


Per-Day Traffic Summary
    date          received  delivered   deferred    bounced     rejected
    --------------------------------------------------------------------
    Mar 24 2018         3          3
    Mar 25 2018       215        208
    Mar 26 2018       302        298
    Mar 27 2018       289        307
    Mar 28 2018      7787       7790
For server configuration
 
wget https://www.stunnel.org/downloads/stunnel-5.44.tar.gz
tar -zxvf stunnel-5.44.tar.gz
cd stunnel-5.44
yum install gcc
yum install openssl openssl-devel gcc
./configure
make
make install
cd /usr/bin/
ln -s /usr/local/bin/stunnel stunnel
cd /etc/
ln -s /usr/local/etc/stunnel stunnel

cd stunnel-5.44/tools
./makecert.sh

cd /usr/local/etc/stunnel
cp stunnel-5.44/tools/stunnel.pem .

vi /etc/hosts
server ip  localhost localhost.localdomain localhost4 localhost4.localdomain4

start at server
vi /usr/local/etc/stunnel/stunnel.conf
debug = 7
output = stunnel.log
cert = stunnel.pem
[mysql]
accept = localhost:10001
connect = 127.0.0.1:3306

[apache]
accept = localhost:8080
connect = 127.0.0.1:80

/usr/bin/stunnel /usr/local/etc/stunnel/stunnel.conf

Open port 10001 & 8080 in firewall


For client configuration

wget https://www.stunnel.org/downloads/stunnel-5.44.tar.gz
tar -zxvf stunnel-5.44.tar.gz
cd stunnel-5.44
yum install gcc
yum install openssl openssl-devel gcc
./configure
make
make install
cd /usr/bin/
ln -s /usr/local/bin/stunnel stunnel
cd /etc/
ln -s /usr/local/etc/stunnel stunnel
copy paste stunnel.pem file from server
start at client end
vi /usr/local/etc/stunnel/client.conf

debug = 7
output = stunnel-server.log
cert = stunnel.pem
client = yes
[mysql]
accept = 127.0.0.1:6004
connect = EIP server ip :10001

[apache]
accept = 127.0.0.1:80
connect = EIP server ip:8080

/usr/bin/stunnel  /usr/local/etc/stunnel/client.conf

For testing
mysql -u root -p -h 127.0.0.1 -P 6004

elinks : http://127.0.0.1

Monday, February 26, 2018

redirect-http-https-on AWS ELB

Apache

The rewrite rule for an Apache backend is similar to the following in .htaccess:




RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

 
 
Nginx

The rewrite rule for an Nginx backend in the ngnix.conf file is similar to the following:
Note: Applies to versions nginx/1.10.3 (Ubuntu) and nginx/1.12.1 (Amazon Linux).


server {
      listen         80;
      server_name    www.example.org;
      if ($http_x_forwarded_proto = 'http') {            
  return 301 https://$server_name$request_uri$http_x_forwarded_proto;
        }
}
Ec2-instance-AutoEIP-Assign-for-whitelistip

#!/bin/sh
# Region in Which instance is running
EC2_REGION='us-east-1'
AWS_ACCESS_KEY='XXXXXXXXXXX'
AWS_SECRET_ACCESS_KEY='XXXXXXXXXXXXXXXXXXX'

#Instance ID captured through Instance meta data
InstanceID=$(/usr/bin/curl -s http://169.254.169.254/latest/meta-data/instance-id)

#Query free Elastic IP and write all allocated ID  aws ec2 describe-addresses --query 'Addresses[?AssociationId==null]' --output text | perl -lne 'print if /(\w+\-){1}\w+/'

aws ec2 describe-addresses --query 'Addresses[?AssociationId==null]' --output text | perl -lne 'print $& if /(\w+\-){1}\w+/' > /opt/EIP/output.txt
Allocate_ID=$(head -n 1 /opt/EIP/output.txt)

#Assigning Elastic IP to Instance
aws ec2 associate-address --instance-id $InstanceID --allocation-id $Allocate_ID
Wednesday, December 20, 2017

AWS Cli IMP commands

Describe Load Balancer

aws elb describe-load-balancers --load-balancer-names lbname --output text|grep INSTANCES|awk '{print $2}' > filename.txt

Describe intance  with particular instnace type

aws ec2 describe-instances --filters "Name=instance-type,Values=m5.large"

aws ec2 describe-instances

Describe aws account all volume  and there information

aws ec2 describe-volumes --query 'Volumes[*].{ID:VolumeId,Tag:Tags}'

Get Instance ID information
wget -q -O - http://169.254.169.254/latest/meta-data/instance-id

Get instance public ip

aws ec2 describe-instances --instance-id $p | grep PublicIpAddress | grep -o -P "\d+\.\d+\.\d+\.\d+" | grep -v '^10\.' >> filename.txt










Configure httpd server status enable and configure on 800 port.

Then while use aws cli configure shell script and set in cron which send data to cloudwatch after every few min.

#!/bin/bash

logger "Apache Status Started"

export AWS_CREDENTIAL_FILE=/opt/aws/credential-file-path.template
export AWS_CLOUDWATCH_HOME=/opt/aws/apitools/mon
export AWS_PATH=/opt/aws
export AWS_AUTO_SCALING_HOME=/opt/aws/apitools/as
export AWS_ELB_HOME=/opt/aws/apitools/elb
export AWS_RDS_HOME=/opt/aws/apitools/rds
export EC2_AMITOOL_HOME=/opt/aws/amitools/ec2
export EC2_HOME=/opt/aws/apitools/ec2
export JAVA_HOME=/usr/lib/jvm/jre
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin

SERVER=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
#echo SERVER=$SERVER
BUSYWORKERS=`wget -q -O - http://localhost:800/server-status?auto | grep BusyWorkers | awk '{ print $2 }'`
#echo BUSYWORKERS=$BUSYWORKERS
IDLEWORKERS=`wget -q -O - http://localhost:800/server-status?auto | grep IdleWorkers | awk '{ print $2 }'`
#echo IDLEWORKERS=$IDLEWORKERS

/opt/aws/bin/mon-put-data --metric-name httpd-busyworkers --namespace "EC2: HTTPD" --dimensions "InstanceId=$SERVER" --unit Count --value $BUSYWORKERS

/opt/aws/bin/mon-put-data --metric-name httpd-idleworkers --namespace "EC2: HTTPD" --dimensions "InstanceId=$SERVER" --unit Count --value $IDLEWORKERS

logger "Apache Status Ended with $SERVER $BUSYWORKERS $IDLEWORKERS"


we can setup Alaram for scale server once Busyworks reach at MinSpareServers or above more than 5 min.  as well as scale down once Busyworks less down MinSpareServers more than 5 min.

Detail and brief information we can found on

http://blog.domenech.org/2012/11/aws-cloudwatch-custom-metric-for-apache.html
While try to convert  C4,M4,T2,R3 instance in C5 instance basically we get below error.

Error starting instances
Enhanced networking with the Elastic Network Adapter (ENA) is required for the 'c5.xlarge' instance type. Ensure that your instance 'i-0de56fe4bb5f3ba27' is enabled for ENA.

So we have to follow below steps.

modinfo ena   this will show ena support is on or not if not then do yum update and reboot instance

ethtool -i eth0        check ena module is loaded

configure aws cli on another instance from that instance your can query your instance status

aws ec2 describe-instances --instance-ids i-040b1236aXXXXX --query 'Reservations[].Instances[].EnaSupport'

configure aws cli on another instance from that instance your can query your AMI status 

aws ec2 describe-images --image-id ami-2XXXXX --query 'Images[].EnaSupport'

command to enable ena support

aws ec2 modify-instance-attribute --instance-id i-040bXXXX--ena-support

Backup your instance and create AMI for safer side.

First run yum update on your instance which help to install ena support driver then shutdown instance and query for ena support if value come null means need to modify instance and enable ena support.  if value come true means you can upgrade instance as C5.

For ena support AMI first create instance and make ena support and then take new AMI.