Monday 26 October 2015

Getting a DESKTOP on centos!

Do a minimal install of centos 6.5 and start doing this:

# yum -y groupinstall "Desktop" "Desktop Platform" "X Window System" "Fonts" "General Purpose Desktop"

# init 5

To have CentOS boot into runlevel 5 “X11” instead of runlevel 3 “Full multiuser mode”, modify the /etc/inittab file to change start up level like this :

# nano /etc/inittab

id:3:initdefault:

to

id:5:initdefault:

Job Done!

Friday 2 October 2015

AWS Auto Scaling - Complete CLI Solution

#! /bin/bash

function ASG {
read -e -p "Enter Min no. of instances(Integer Value)...: " min
echo ""
read -e -p "Enter Max no. of instances(Integer Value)...: " max
echo ""
read -e -p "Enter Desired no. of instances(Integer Value)...: " desired
echo ""
aws autoscaling create-auto-scaling-group --auto-scaling-group-name $Cluster-$COMPONENT-ASG --launch-configuration-name RTB-$COMPONENT-ASG --min-size $min --max-size $max --desired-capacity $desired --availability-zones us-east-1e --health-check-type ELB --health-check-grace-period 240 --default-cooldown 300 --load-balancer-names "RTB" --vpc-zone-identifier subnet-fea1f0d5 ; check;
}

function config {
echo ""
aws autoscaling create-launch-configuration --launch-configuration-name $Cluster-$COMPONENT-ASG --image-id ami-b7f68bd2 --instance-type $COMPONENT --spot-price "0.27" --no-associate-public-ip-address  --security-groups sg-665df302 --user-data $File --key-name rtbservers --instance-monitoring Enabled=false --no-ebs-optimized --block-device-mappings "[{\"DeviceName\":\"/dev/xvda\",\"Ebs\":{\"SnapshotId\":\"snap-68dc2c09\",\"VolumeSize\":10,\"VolumeType\": \"gp2\",\"DeleteOnTermination\": true}},{\"DeviceName\": \"/dev/sdb\",\"VirtualName\":\"ephemeral0\"}]" ; check && ASG;
}

function check {
if [ $? -eq 0 ]
then
echo "Command Executed Successfully"
echo ""
else
echo "Error, Please try again!"
echo ""
exit 1
fi
}

function type {
echo ""
echo "Please select the desired Instance type"
echo ""

select COMPONENT in c3.2xlarge c3.4xlarge m3.2xlarge r3.2xlarge r3.4xlarge g2.2xlarge
do
case $COMPONENT in

c3.2xlarge) config;
            break;;
c3.4xlarge) config;
            break;;
m3.2xlarge) config;
            break;;
r3.2xlarge) config;
            break;;
r3.4xlarge) config;
            break;;
g2.2xlarge) config;
            break;;
esac
done
}

echo ""
echo "Please select the desired Cluster type"
echo ""

select Cluster in RTB RTB3 RTB4
do
case $Cluster in
RTB) File="file:///operations/users/naveed/bootscriptrtb.txt"
     type;
     break;;
RTB3) File="file:///operations/users/naveed/bootscriptrtb3.txt"
      type;
      break;;
RTB4) File="file:///operations/users/naveed/bootscriptrtb4.txt"
      type;
      break;;
esac
done

echo "Please configure AS Policy"
echo ""
read -e -p "Enter No. of Instance to be affected (Integer Value)...: " aff
echo ""

aws autoscaling put-scaling-policy --policy-name increase-policy --auto-scaling-group-name $Cluster-$COMPONENT-ASG --scaling-adjustment $aff --adjustment-type ChangeInCapacity --output text > increase.txt
inc=$(cat increase.txt)
aws autoscaling put-scaling-policy --policy-name decrease-policy --auto-scaling-group-name $Cluster-$COMPONENT-ASG --scaling-adjustment -$aff --adjustment-type ChangeInCapacity --output text > decrease.txt
dec=$(cat decrease.txt)

echo "Please configure AS Alarm"
echo ""
read -e -p "Enter High CPU threshold (Integer Value)...: " high
echo ""
read -e -p "Enter Lower CPU threshold (Integer Value)...: " low
echo ""

aws cloudwatch put-metric-alarm --alarm-name $Cluster-$COMPONENT-AddCapacity --metric-name $Cluster-$COMPONENT-CPU-HIGH --namespace AWS/EC2 --statistic Average --period 300 --threshold $high --comparison-operator GreaterThanOrEqualToThreshold --dimensions "Name=AutoScalingGroupName,Value=$Cluster-$COMPONENT-ASG" --evaluation-periods 2 --alarm-actions $inc
aws cloudwatch put-metric-alarm --alarm-name $Cluster-$COMPONENT-RemoveCapacity --metric-name $Cluster-$COMPONENT-CPU-LOW --namespace AWS/EC2 --statistic Average --period 300 --threshold $low --comparison-operator LessThanOrEqualToThreshold --dimensions "Name=AutoScalingGroupName,Value=$Cluster-$COMPONENT-ASG" --evaluation-periods 2 --alarm-actions $dec

rm -fr increase.txt decrease.txt

echo "Job Finished!"
echo ""