Saturday, October 13, 2012

Quick Setup KVM aka Kernel-based Virtual Machine

Well, I thought this was something difficult, but trust me its not brain twister to setup the virtual machines using KVM.

Note: This tutorial assumes you understand the basics of linux and aware of the commands usage.

Ok here is how I setup the same.

1. Install CentOS 6  ( minimal Installation )
2. Turn of selinux

# vi /etc/selinux/config

make the following change.

SELINUX=disabled 
Now reboot your machine to have this applied.

3. Update the system using yum

4. Install packages for Virtualization to work.

# yum install -y openssh-server openssh-client qemu-kvm  libvirt bridge-utils virt-manager.x86_64  virt-top.x86_64 screen

5. Lets setup the network now. For the kvm to work, we will need to setup bridge network. The following is the configuration options.


[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="no"
ONBOOT=yes
HWADDR=00:01:6C:53:82:72
BRIDGE="br0"
[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0"
NM_CONTROLLED="no"
ONBOOT=yes
HWADDR=00:01:6C:53:82:72
TYPE=Bridge
IPADDR=192.168.1.10
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8


4. Save the settings and open a screen to restart the network.

# screen -S network
# /etc/init.d/network restart
5. Now you should see the bridge network up and running.

6. Start libvirtd

# /etc/init.d/libvirtd start

Oops. it did not start for me :D here's what was missing

#  yum -y install avahi

Now libvirtd will start..

7. Copy an ISO to your home directory so that we can use this for creating Virtual Machines, we will be using centos here.

8. Create your VMs now

# virt-install --name=server_name --ram=512 --arch=x86_64 --vcpus=2 --location=/home/packages/CentOS-6.0-x86_64-bin-DVD1.iso  --os-type=linux --os-variant=rhel6 --file /home/images/server.img  --nonsparse --nographics -s15 --extra-args='console=tty0 console=ttyS0,115200n8' --prompt
9. Use Man pages for exact options.

Hope this helps :)






Friday, February 17, 2012

Unable to install applications using GEM

I faced an issue today, I was trying to install a package using gem command but ended up in the following error


Building native extensions.  This could take a while...
ERROR:  Error installing cassandra:
        ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h

So in order to fix this you need to install the ruby-devel package.

you can use yum or rpm or which ever you are comfortable with.

Wednesday, December 14, 2011

cPanel + mysql slow queries to TABLE_SCHEMA

If you are seeing the following in mysqladmin proc for a long time then its basically cPanel calculating account disk usage from the information_schema, this tends to increase the load on some servers.



| 14436 | root           | localhost | mysql          | Query          | 2227 |                    | SELECT TABLE_SCHEMA as DB,SUM(DATA_LENGTH)+SUM(INDEX_LEN
GTH) AS SPACEUSED from information_schema.ta |

You can place the following in your cpanel conifg (/var/cpanel/cpanel.config) to force /scripts/update_db_cache to utilize a `du` style disk calculation. This should help you.

use_information_schema=0

restart cpanel once done :) 

Sunday, November 27, 2011

Unable to mount hard disk/Partition

Yesterday I faced a strange issue, after rebooting the server I noticed that our back drives did not mount automatically. The fstab entries were proper but still the device did not mount. I tried manually

# mount /dev/sdb1 /backup

unable to mount /dev/sdb1 /backup busy or already mounted.

Googled a lot but did not find any fix, checked if the raid setup was causing the issue since we had raid setup sometime back ( although it was not in use )

Did the following to fix this ( try as a last attempt if no other method works :D )


root@server [~]# dmsetup ls 
ddf1_4035305a0590430220202020202020201d9400003a354a45   (253, 2) 
VolGroup00-swap (253, 1) 
VolGroup00-root (253, 0) 
root@server [~]# dmsetup remove ddf1_4035305a0590430220202020202020201d9400003a354a45 
root@server [~]# dmsetup ls 
VolGroup00-swap (253, 1) 
VolGroup00-root (253, 0) 
root@server [~]# mount /dev/sdb1 /backup 


root@server [~]# df -h


/dev/sdb1             276G  223G   39G  86% /backup 




Hope this helps :)

Saturday, November 20, 2010

Cpanel upcp error

Issue: root@server [~]# /scripts/upcp --force
/scripts/upcp syntax OK
Running Futex Check/Fix......Done
Undefined subroutine &Cpanel::Update::automatic_updates_enabled called at /scripts/upcp line 273.

Solution: wget -O /root/updatenow.static http://httpupdate.cpanel.net/cpanelsync/RELEASE/scripts/updatenow.static && perl /root/updatenow.static --manual

Then run /scripts/upcp --force.

It should fix it!!

Wednesday, October 27, 2010

mount/Unmount a partition in Linux

I was trying to umount a partition, it gave me error saying the device is busy and un mount was not working. I then started to troubleshoot this and came to the conclusion that something was still accessing the partition and hence the Linux was not allowing me to unmount it. So what do you do to know what process is using this? There are couple of command utilities that can assist you in this. One is lsof and the other one is fuser,  so how do you use this? lets see that below.

# lsof /dev/sda2

 or
 
# fuser -m /dev/sda2

it will list you the process that is using that partition, either stop the process or kill it and then you can umount it. Hope it helps ;)

Friday, October 1, 2010

Recovering files/settings from a cPanel server from a Harddisk failure/Crash


Bad things happen...Same is the case with a server, Suppose you have a cPanel server and one fine morning, you get this alert.. Site DOWN!!!

oops your hdd crashed? well dont panick... contact your datacentre and get the same OS installed on a new hdd, lets do the data recovery real fast!


Once the server is UP with new OS, install cPanel and connect your old hdd as slave and mount it to /oldHD





# mount /dev/sdb1 /oldHD

Run these rsync commands to move everything over;


# rsync -vrplogDtH /oldHD/usr/local/apache/conf /usr/local/apache
# rsync -vrplogDtH /oldHD/var/named /var
# rsync -vrplogDtH /oldHD/home/* /home
# rsync -vrplogDtH /oldHD/usr/local/cpanel /usr/local
# rsync -vrplogDtH /oldHD/var/lib/mysql /var/lib
# rsync -vrplogDtH /oldHD/var/cpanel /var
# rsync -vrplogDtH /oldHD/usr/local/cpanel/3rdparty/mailman /usr/local/cpanel/3rdparty
# rsync -vrplogDtH /oldHD/var/log/bandwidth /var/log
# rsync -vrplogDtH /oldHD/usr/local/frontpage /usr/local
# rsync -vrplogDtH /oldHD/var/spool/cron /var/spool
# rsync -vrplogDtH /oldHD/root/.my.cnf /root
# rsync -vrplogDtH /oldHD/etc/httpd/conf/httpd.conf /etc/httpd/conf
# rsync -vrplogDtH /oldHD/etc/sysconfig/network /etc/sysconfig



almost done.. now some configuration files need to be copied.

go to the old etc directory


# cd /oldHD/etc
# rsync -vrplogDtH secondarymx domainalias valiases vfilters exim* proftpd* pure-ftpd* passwd* group* *domain* *named* wwwacct.conf cpupdate.conf quota.conf shadow* *rndc* ips* ipaddrpool* ssl hosts /etc

Once this is complete run



# /scripts/fixeverything
# /scripts/upcp –force
# /scripts/easyapache
everything should be working fine now :) 

Thursday, July 8, 2010

Extended logging in Exim

1. Open /etc/exim.confRemove Formatting from selection


#vi /etc/exim.conf




2. Enter the following 


log_selector=+all


3. Save the file and change its attribute


# chattr + i  /etc/exim.conf


4. Restart Exim


# /etc/init.d/exim restart


Thats it! now check the exim log


# tail -f /var/log/exim_mainlog

Saturday, November 28, 2009

Enable Quota in VPS ( openvz )

If you are experiencing an issue with OpenVZ VPS disk quota, please make sure that the following values are set in the VPS conf.


VPS conf Location : /etc/vz/conf/VEId.conf


In the main node, do the following steps.


1) #grep DISK_QUOTA /etc/vz/conf/VEId.conf


If no disk quota value has found ot it is disabled, change the value to


DISK_QUOTA=yes


2) Check that disk quota is enabled in the main server itself.


grep DISK_QUOTA /etc/sysconfig/vz


If not enable the value to yes in the conf.


DISK_QUOTA=yes


3) Check for the value quotaugidlimit .


#grep -i quotaugidlimit /etc/vz/conf/veid.conf




4) Check the quota module "vzdquota" is loaded or notin main node.


# lsmod |grep -i vzdquota


5) You can set the value quotaugidlimit from the main node using the below command.


vzctl set veid –quotaugidlimit 500 –save


6) Make sure to reboot the mentioned node from the main node.


vzctl restart veid


7) Enter the the node for which you are experiencing the problem.


vzctl enter veid


Type the command 'mount'. It should give a similar output.


# mount
/dev/simfs on / type reiserfs (rw,usrquota,grpquota)
/proc on /proc type proc (rw)
/sys on /sys type sysfs (rw)
none on /dev type tmpfs (rw)
none on /dev/pts type devpts (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)


Also make sure that symbolic links are existing from aquota.group and aquota.user to their respectve physical locations.




# ll
total 64
lrwxrwxrwx 1 root root 39 Oct 19 11:41 aquota.group -> /proc/vz/vzaquota/00000030/aquota.group
lrwxrwxrwx 1 root root 38 Oct 19 11:41 aquota.user -> /proc/vz/vzaquota/00000030/aquota.user

Sunday, November 22, 2009

Create VPS nodes in OpenVZ

Steps for creating nodes in OpenVZ.

1. First of all check if the templates are available. Go to the vz cache directory

[root@server ~]# cd /vz/template/cache

[root@server cache]# pwd
/vz/template/cache
[root@server cache]# ll
total 1356612
-rw-r--r-- 1 root  root  158160318 Jul 10  2010 centos-4-x86.tar.gz
-rw-r--r-- 1 root  root  158609159 Sep 14 16:11 centos-4-x86.tar.gz.1
-rw-r--r-- 1 root  root  130092151 May 13  2008 centos-5-i386-default.tar.gz
-rw-r--r-- 1 root  root  191595463 Sep 14 16:16 centos-5-x86_64.tar.gz
-rw-r--r-- 1 root  root  180022352 Apr 26  2010 centos-5-x86.tar.gz
-rw-r--r-- 1 root  root  212917989 Sep 14 16:25 centos-6-x86_64.tar.gz
-rw-r--r-- 1 root  root  117087334 Nov 12  2010 debian-4.0-x86.tar.gz
[root@server cache]#
[root@server cache]#

if you do not have any templates you can download the precreated templates from the openvz website

http://wiki.openvz.org/Download/template/precreated

Once downloaded follow the steps below to create the nodes.


[root@server ~]# vzctl create 101 --ostemplate centos-5-i386-default --config vps.basic
[root@server ~]# vzctl set 101 --onboot yes --save
[root@server ~]# vzctl set 101 --hostname training.server.com --save
[root@server ~]# vzctl set 101 --ipadd 192.168.0.101 --save
[root@server ~]# vzctl set 101 --nameserver 4.2.2.2 --save
[root@server ~]# vzctl start 101
[root@server ~]# vzctl exec 101 /etc/init.d/sshd start
[root@server ~]# vzctl exec 101 passwd

Hope this helps!