Posts

Showing posts from April, 2014

Script to create daily AMI of AWS server and delete AMI older than n no of days..

Following Script can be used to create AMI of AWS server daily to keep the backup and delete the AMI older than n no of days including snapshots associated with it..

#!/bin/bash #Script to create AMI of server on daily basis and deleting AMI older than n no of days #By Ravi Gadgilecho -e "----------------------------------\n   `date`   \n----------------------------------"#To create a unique AMI name for this script echo "instance-`date +%d%b%y`" > /tmp/aminame.txtecho -e "Starting the Daily AMI creation: `cat /tmp/aminame.txt`\n"#To create AMI of defined instance aws ec2 create-image --instance-id i-1xxxxx34 --name "`cat /tmp/aminame.txt`" --description "This is for Daily auto AMI creation" --no-reboot | grep -i ami | awk '{print $4}' > /tmp/amiID.txt#Showing the AMI name created by AWS echo -e "AMI ID is: `cat /tmp/amiID.txt`\n"echo -e "Looking for AMI older than 3 days:\n "#Finding AMI older than 3 …

Script to know the servers running in AWS auto scaling group..

Following script can be used to know the servers which are running under AWS auto scaling group..

#!/bin/bash #Script to know thw servers running in AWS auto scaling group #By Ravi Gadgil
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name autoscaling-group | grep i- | awk '{print $6}' > /tmp/instances.txt
echo "-----------------------------------------------------------------------------------------"
for inc in `cat /tmp/instances.txt`; do aws ec2 describe-instances --instance-ids $inc | grep -ir 'publicdns\|keyname'; echo "-----------------------------------------------------------------------------------------" ;done
In following script we are just looking for hostname and respective login key but it can be further increased according to your need by increasing the parameters in grep..

Following will be the output of the script output:

[root@server auto-data]# ./autoscaleserver.sh -----------------------------------------------…

How to install and Configure lsyncd

Lsyncd is a service which is used to sync data between the directories with in a server or between the servers. It is very useful tool if you want to keep redundancy between the servers. It has bit of delay while it copies data from source to target destination but its very simple to configure and light on server.

There should be password less authentication set between the servers so that they can sync data..

If your looking to get it configured it via yum following will be steps:


[root@server downloads]# yum -y install lua lua-devel pkgconfig gcc asciidoc [root@server downloads]# yum --enablerepo=dag -y install lsyncd   # install from DAG
Create the configuration file:

[root@server downloads]# cp /usr/share/doc/lsyncd/lrsync.lua /etc/lsyncd.conf[root@server downloads]# vi /etc/lsyncd.conf
Following entry needs to be done in the Configuration file:

settings = { statusFile = "/tmp/lsyncd.stat", statusInterval = 1, }sync{ default.rsync, # source directory source="/var/www/ht…

How to install and configure Google Page Speed Module for Nginx

Google Page speed module is very good tool to optimize sites performance by arranging CSS, images, java scripts etc in a better way which results in better performance from site..

Download the Page Speed Module and unzip it

[root@server downloads]# wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.7.30.4-beta.zip
[root@server downloads]# unzip release-1.7.30.4-beta
[root@server downloads]# cd ngx_pagespeed-release-1.7.30.4-beta/
We also need posl to make module work so download and untar it in page speed module directory..

[root@server downloads]# wget https://dl.google.com/dl/page-speed/psol/1.7.30.4.tar.gz
[root@server downloads]# tar -xzvf 1.7.30.4.tar.gz
Now compile the nginx with page speed module enable in it. Go in to the directory where you have your nginx setup available and configure it with including the page speed module.

[root@theteamie nginx-1.5.7]# ./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin/nginx --pid-path=/tmp/ng…

Script to automatically create an AMI of server than add it to Auto Scaling Configuration and Group

Following script can help you to create an AMI of running server, than automatically create a auto scaling configuration from newly created AMI and updating the auto scaling group with new auto scaling configuration.

Note: To run this script AWS cli needs to be configured correctly and this script should be run in the server of whom you want to create AMI.

If in case your AWS cli is not configured follow the following steps..

Script:

#!/bin/bash #Script to create ami of running instance, make launch Conf from it and than add it to Auto Scaling group #By Ravi Gadgil#To get the current Instance ID wget -q -O - http://169.254.169.254/latest/meta-data/instance-id > /tmp/instanceID.txt#To get the current Instance Type wget -q -O - http://169.254.169.254/latest/meta-data/instance-type > /tmp/instanceType.txt#To create a unique AMI name for this script echo "test-ami-`date +%d%b%y%H%M`" > /tmp/aminame.txt#To create a unique Launch Conf name for this script echo "test-…

How to install and Configure Amazon Web Services(AWS) cli

Amazon Web Services(AWS) has its own set of command line interface tool which has all the necessary tools to run all AWS commands and is managed by them so updated frequently..

Download the zip folder containing all the required packages:

[root@server downloads]# wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip --2014-04-03 19:39:18--  https://s3.amazonaws.com/aws-cli/awscli-bundle.zip Resolving s3.amazonaws.com... 207.171.185.200 Connecting to s3.amazonaws.com|207.171.185.200|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 6063815 (5.8M) [application/zip] Saving to: “awscli-bundle.zip”
100%[=============================================================>] 6,063,815   1.52M/s   in 8.3s   
2014-04-03 19:39:28 (717 KB/s) - “awscli-bundle.zip” saved [6063815/6063815]
Unzip the folder downloaded:

[root@server downloads]# unzip awscli-bundle.zip Archive:  awscli-bundle.zip   inflating: awscli-bundle/install     inflating: awscli-bundle/packages/argparse-1.…