Wednesday, November 20, 2013

Server Provisioning / De-provisioning on Proxmox using Shell Script.

 Here is my attempt to simplify server provisioning / De-provisioning on Proxmox using shell script. Hope you find it useful.

****************************************************************************
#!/bin/bash

echo " Proxmox OpenVZ Server Provisioning Tool"
echo ""
echo " Please select from the below choices"
echo ""
echo " 1. KVM Server Instance Provisioning"
echo " 2. KVM Server Instance Decommissioning"
echo ""
read -p "Please enter you numerical choice: " choice

echo $choice

if [ "$choice" -lt 1 ] || [ "$choice" -gt 2 ]; then
                        echo "Wrong choice selection - Existing the program - Please try again"
                        exit
                if [ "$choice" -eq 1 ]; then
                        echo " Initiating Server Provisioning Procedure"
                elif [ "$choice" -eq 2 ]; then
                        echo " Initiating Server Decommissioning Procedure"

                fi

fi

case $choice in
1)
##### SECTION FOR TOTAL NUMBER OF SERVER AND OPERATING SYSTEM SELECTION #####
echo "Enter the number of servers needed (1-5)"
echo ""
read -p "Please enter the numerical value: " kvmsrvno
if [ "$kvmsrvno" -le 0 ] || [ "$kvmsrvno" -gt 5 ]
        then
                echo "Please try again by entering a valid number between (1-6)"
                exit
        else
                echo "Enter the number corresponding to the operating system 1.Windows2012 2.Windows2008R2 3.WindowsXP 4.Windows7 5.RedHat6 6.CentOS6"
                read -p "Please enter the numerical value: " kvmselection
    if [ "$kvmselection" -le 0 ] || [ "$kvmselection" -gt 6 ]
        then
                echo "Please try again by entering a valid number between 1,2,3,4,5 or 6"
        exit
    fi
fi
#echo "The operating system selected is $kvmselection"

############################################################fngetvmid() {
        pvesh get /cluster/resources --type vm |grep -i vmid |sort -n |awk '{print $3}' > /mnt/pve/ISO/automation_scripts/allocated_vmid
while read avail_vmid
do
                grep -x $avail_vmid /mnt/pve/ISO/automation_scripts/allocated_vmid > /dev/null
        if [ `echo $?` -ne 0 ]
        then
                VMID=$avail_vmid
                echo $VMID
                exit
        fi
done <  /mnt/pve/ISO/automation_scripts/vmidlist
}
#vm_id=$(fngetvmid)

##############################################################

fngetkvmhostname() {
case $kvmselection in
  1)
        hostname=Win2012-$vm_id;
        clntmpt=128;;
  2)
        hostname=Win2008R2-$vm_id;
        clntmpt=125;;
  3)
        hostname=WindowsXP-$vm_id;
        clntmpt=126;;
  4)
        hostname=Windows7-$vm_id;
        clntmpt=127;;
  5)
        hostname=Redhat6-$vm_id;
        clntmpt=123;;
  6)
        hostname=CentOS6-$vm_id;
        clntmpt=116;;
 esac
}

##################################################################
count=1
while [ "$count" -le "$kvmsrvno" ]
    do
        #ip_addr=$(fngetip)
        vm_id=$(fngetvmid)
        fngetkvmhostname
        pvesh create /nodes/`hostname`/qemu/$clntmpt/clone --newid $vm_id --full --name=$hostname #--pool="$poolname"
                #echo $ip_addr >> /mnt/pve/ISO/automation_scripts/allocated_list
        echo "#################################################################"
        count=`expr $count + 1`
        done;
break;;

2)
        echo "KVM Server Decommissioning Initiated"
        echo ""
        echo "Please specify the VMIDs of the instances to be decommissioned (Use comma separated values)"
        echo ""
        read -p "Please enter the numerical value: " delvid

        IFS=","
        for vmid in $delvid
        do
        #v_delip=`grep -i IP_ADDRESS /etc/vz/conf/$vmid.conf |sed -r 's/[^\"]*([\"][^\"]*[\"][,]?)[^\"]*/\1 /g' | sed "s/\"//g"`
        #delip=sed
        qm stop $vmid
        qm destroy $vmid
        #sed -i "s/$delip//g" "/opt/automation_scripts/allocated_list"
        #sed -i '/^$/d' "/opt/automation_scripts/allocated_list"
        echo "#################################################################"
        done;
break;;
esac

********************************************************************

Monday, August 05, 2013

Time and date setting in CentOS


View the current time and the timezone setting on the server by running the below command
#date

Steps to change the timezone settings.

 Make a backup of the current localtime file
#mv /etc/localtime /etc/localtime.bak

Create a new zone file setting using the below command. (Below example for India)
#ln -s /usr/share/zoneinfo/Asia/Calcutta /etc/localtime


Manually Set Data and Time using the following command
date -s "13 Feb 2015 10:30:00"


Wednesday, June 19, 2013

Configuring snmp on debian server

Configuring Debian Server to respond to snmp query

#dpkg --list |grep snmp
ii  libnet-snmp-perl                     5.2.0-4                        Script SNMP connections
ii  libsnmp-base                         5.4.3~dfsg-2                   SNMP (Simple Network Management Protocol) MIBs and documentation
ii  libsnmp15                            5.4.3~dfsg-2                   SNMP (Simple Network Management Protocol) library
ii  snmp                                 5.4.3~dfsg-2                   SNMP (Simple Network Management Protocol) applications
ii  snmpd                                5.4.3~dfsg-2                   SNMP (Simple Network Management Protocol) agents

Setting public as community string.

rocommunity public
##       sec.name     source           community
##       ========     ======           =========
com2sec  local       localhost        craz33guy
com2sec  network_1   172.22.6.0/24    craz33guy
#com2sec  network_2   192.168.2.0/24   craz33guy

##       Access.group.name   sec.model        sec.name
##       =================  =========         ========
group    MyROGroup_1        v1                local
group    MyROGroup_1        v1                network_1
group    MyROGroup_2        v2c               network_2

##   MIB.view.name     incl/excl  MIB.subtree  mask
##   ==============   =========  ===========  ====
view all-mibs         included   .1           80

##      MIB
##      group.name   context sec.model sec.level prefix read     write  notif
##      ==========   ======= ========= ========= ====== ====     =====  =====
access  MyROGroup_1  ""       v1       noauth    exact  all-mibs none   none
access  MyROGroup_2  ""       v2c      noauth    exact  all-mibs none   none

############################################################################

Adding custom scripts to be monitored using SNMP

Sample check_keepalived Script
-------------------------------------
#!/bin/bash
count=`ps -ef |grep -c keepalived`
if [ $count -lt 4 ]; then
        echo "1"
else
        echo "0"
fi

------------------------------------



Copy the script to /bin/check_keepalived.sh
#chmod 777 /bin/check_keepalived.sh

Add the following line in snmpd.conf file
exec keepalive /bin/sh /bin/check_keepalived.sh

#service snmpd restart

Test if the script is executable using snmp and showing desired results 
From the SNMP server run this command. This will execute all the Snmp custom scripts and show the output.
snmpwalk -v2c -c craz33guy 172.21.6.64 NET-SNMP-EXTEND-MIB::nsExtendObjects

To execute a specific Script from the bunch of custom scripts.
snmpwalk -v2c -c craz33guy 172.21.6.64 1.3.6.1.4.1.8072.1.3.2.4.1

 More details on the custom OID are explained in the below link
http://www.oidview.com/mibs/8072/NET-SNMP-EXTEND-MIB.html 
http://www.net-snmp.org/wiki/index.php/Tut:Extending_snmpd_using_shell_scripts
 ===========================
rocommunity testcomm
##       sec.name     source           community
##       ========     ======           =========
com2sec  local       localhost          testcomm
com2sec  network_1   172.21.10.33/32    testcomm
#com2sec  network_1   10.0.0.207/32      testcomm

##       Access.group.name   sec.model        sec.name
##       =================  =========         ========
group    MyROGroup_1        v1                local
group    MyROGroup_2        v2c               network_1

##   MIB.view.name     incl/excl  MIB.subtree  mask
##   ==============   =========  ===========  ====
view all-mibs         included   .1           80

##      MIB
##      group.name   context sec.model sec.level prefix read     write  notif
##      ==========   ======= ========= ========= ====== ====     =====  =====
access  MyROGroup_1  ""       v1       noauth    exact  all-mibs none   none
access  MyROGroup_2  ""       v2c       noauth    exact  all-mibs none   none
=================================


Tuesday, May 07, 2013

Check if the Linux Operating System is 32 Bit or 64 Bit

Run the below commands to check if the operating system is 32Bit or 64Bit.


  1. uname -a
  2. getconf WORD_BIT
  3. file /usr/bin/file
The above command will show if the operating system bit size