Monday 26 March 2018

Vmware – Unable to operate a ESX host with locked disk

Background – No operation can be performed on an ESX host and you may see files are locked by other processes.
Solution
Determine which ESXi/ESX host has a locked or rogue file.
* First login to the local tech support mode console on the host.
* Use the command vmkfstools to obtain the lockstatus of the file.
# vmkfstools -D /vmfs/volumes/LUN/VM/disk-flat.vmdk
You would see a similar output as below,
Lock [type 10c00001 offset 54009856 v 11, hb offset 3198976
gen 9, mode 0, owner 4655cd8b-3c4a19f2-17bc-00126e808070 mtime 114]
Addr <4, 116, 4>, gen 5, links 1, type reg, flags 0, uid 0, gid 0, mode 600
len 5368709120, nb 0 tbz 0, cow 0, zla 3, bs 1048576
Look for the output logged to the vmkernel , messages , or vmkernel.log files to see the complete output. Read more

Device eth0 does not seem to be present

Issues
After restoring a VM from datastore or after cloning a centos VM on Vsphere, we see the following error during network restart
“Device eth0 does not seem to be present”
Cause:
After cloning or restore from datastore, the MAC address needs to be edited on the VM configuration settings since the MAC ID tends to change during restore/clone. Read more

Migrating emails from one server to another without Server access

Imapcopy:
There are many tools available for this mail to mail migration, here we are going to use “Imapcopy”, which I believe to be the best and easy command line tool. It does support both Imap and Imaps protocols.
Since this tool only uses ‘imap’ protocol to copy emails, not much of server resources will be used and also you do not need the admin/root login details of the server.
Requirements:
  • Login details of email accounts from both source server and destination server
  • Both servers hostnames and working imap port number (Be default it is 143 for http and 993 for https)
  • A linux machine, either a server or local machine with internet connectivity. Read more

MEGACLI Commands to check Hardware RAID config and Setup:

To know the Hardware RAID controller and other information use lspci command.
lspci | grep -i raid
O/P:
01:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)
The above command shows the RAID controller vendor details.
Installation of Megacli in Centos:

Add multiple interface and IP address – ubuntu and centos

The below script uses to add bulk IPs for the same gateway and subnet :
Save IPs in a file like /opt/dummy.txt and run the script to add them up.
Interface add script – Ubuntu or Centos:
echo Enter Distribution ubuntu\/centos
read os
if [ "$os" == "centos" ]
then
echo Enter Interface Name
read intface
echo Enter IPdetails File name with PATH
read pat
echo Enter Netmask
read Net
echo Enter Gateway
read Gtw
alas=`cat $pat |wc -l`
for (( i=1 ; i<=$alas ; i++ ))
do
ipl=`head -n $i $pat |tail -n 1`
Ips=`echo $ipl|cut -d" " -f1`
#Net=`echo $ipl|cut -d" " -f2`
#Gtw=`echo $ipl|cut -d" " -f3`
grep -rw $Ips /etc/sysconfig/network-scripts>/opt/dummy.txt
if [[ "$?" -ne "0" ]]
then
alaupdate=`ls /etc/sysconfig/network-scripts|grep ifcfg-$intface|grep :|cut -d":" -f2|sort -n|tail -n 1`
alaactual=`expr $alaupdate + 1`
echo DEVICE=$intface:$alaactual >/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo BOOTPROTO=none >>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo IPADDR=$Ips>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo NETMASK=$Net>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo ONBOOT=yes>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo GATEWAY=$Gtw>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo TYPE=Ethernet>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
else
echo The $Ips Already exist in one Interface
fi
done
else
if [ "$os" == "ubuntu" ]
then
echo Enter Interface Name
read intface
echo Enter IPdetails File name with PATH
read pat
echo Enter Netmask
read Net
echo Enter Gateway
read Gtw
alas=`cat $pat |wc -l`
for (( i=1 ; i<=$alas ; i++ ))
do
ipl=`head -n $i $pat |tail -n 1`
Ips=`echo $ipl|cut -d" " -f1`
#Net=`echo $ipl|cut -d" " -f2`
#Gtw=`echo $ipl|cut -d" " -f3`
cat /etc/network/interface|grep -w $Ips
if [[ "$?" -ne "0" ]]
then
alaupdate=`cat /etc/network/interface |grep auto|wc -l`
alaactual=`expr $alaupdate + 1`
echo >>/etc/network/interface
echo auto $intface:$alaactual >>/etc/network/interface
echo iface $intface:$alaactual inet static >>/etc/network/interface
echo address $Ips >>/etc/network/interface
echo netmask $Net >>/etc/network/interface
echo gateway $Gtw >>/etc/network/interface
else
echo $Ips is already exist in file
fi
done
else
echo only ubuntu or centos allowed
fi
fi
The below script will use to add bulk IPs in different gateway and subnet: 
( Save the Ips in a file like IP MASK GATEWAY .For Example 192.168.1.2 255.255.255.0 192.168.1.1 )
echo Enter Distribution ubuntu\/centos
read os
if [ "$os" == "centos" ]
then
echo Enter Interface Name
read intface
echo Enter IPdetails File name with PATH
read pat
alas=`cat $pat |wc -l`
for (( i=1 ; i<=$alas ; i++ ))
do
ipl=`head -n $i $pat |tail -n 1`
Ips=`echo $ipl|cut -d" " -f1`
Net=`echo $ipl|cut -d" " -f2`
Gtw=`echo $ipl|cut -d" " -f3`
grep -rw $Ips /etc/sysconfig/network-scripts>/opt/dummy.txt
if [[ "$?" -ne "0" ]]
then
alaupdate=`ls /etc/sysconfig/network-scripts|grep ifcfg-$intface|grep :|cut -d":" -f2|sort -n|tail -n 1`
alaactual=`expr $alaupdate + 1`
echo DEVICE=$intface:$alaactual >/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo BOOTPROTO=none >>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo IPADDR=$Ips>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo NETMASK=$Net>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo ONBOOT=yes>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo GATEWAY=$Gtw>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
echo TYPE=Ethernet>>/etc/sysconfig/network-scripts/ifcfg-$intface:$alaactual
else
echo The $Ips Already exist in one Interface
fi
done
else
if [ "$os" == "ubuntu" ]
then
echo Enter Interface Name
read intface
echo Enter IPdetails File name with PATH
read pat
alas=`cat $pat |wc -l`
for (( i=1 ; i<=$alas ; i++ ))
do
ipl=`head -n $i $pat |tail -n 1`
Ips=`echo $ipl|cut -d" " -f1`
Net=`echo $ipl|cut -d" " -f2`
Gtw=`echo $ipl|cut -d" " -f3`
cat /etc/network/interface|grep -w $Ips
if [[ "$?" -ne "0" ]]
then
alaupdate=`cat /etc/network/interface |grep auto|wc -l`
alaactual=`expr $alaupdate + 1`
echo >>/etc/network/interface
echo auto $intface:$alaactual >>/etc/network/interface
echo iface $intface:$alaactual inet static >>/etc/network/interface
echo address $Ips >>/etc/network/interface
echo netmask $Net >>/etc/network/interface
echo gateway $Gtw >>/etc/network/interface
else
echo $Ips is already exist in file
fi
done
else
echo only ubuntu or centos allowed
fi
fi

Linux – Creating a Partition Size Larger Than 2TB using Parted Command

Linux – Creating a Partition Size Larger Than 2TB using Parted Command

Find Out Current Disk Size:
fdisk -l /dev/sdb
  • Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes
  • 255 heads, 63 sectors/track, 364801 cylinders
  • Units = cylinders of 16065 * 512 = 8225280 bytes
  • Sector size (logical/physical): 512 bytes / 512 bytes
  • I/O size (minimum/optimal): 512 bytes / 512 bytes
  • Disk identifier: 0x00000000
  • Disk /dev/sdb doesn’t contain a valid partition table


Linux – Create 3TB partition size:
To create a partition start GNU parted as follows:
  • # parted /dev/sdb
Output:
  • GNU Parted 2.3
  • Using /dev/sdb
  • Welcome to GNU Parted! Type ‘help’ to view a list of commands.
    (parted)
Creates a new GPT disklabel i.e. partition table:
  • (parted) mklabel gpt
Sample outputs:
  • Warning: The existing disk label on /dev/sdb will be destroyed and all
  • data on this disk will be lost. Do you want to continue?
  • Yes/No? yes
    (parted)

MySQLTuner-perl Script

MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief format along with some basic performance suggestions.

Compatibility:
  • MySQL 3.23, 4.0, 4.1, 5.0, 5.1 (full support)
  • MySQL 5.4 (not fully tested, partially supported)
  • MySQL 6.0 (partial support)
  • MariaDB 10.x (partial support)
  • Perl 5.6 or later (with perl-doc package)
  • Unix/Linux based operating system (tested on Linux, BSD variants, and Solaris variants)
  • Windows is not supported at this time
  • Unrestricted read access to the MySQL server (OS root access recommended for MySQL < 5.0)