Saturday, March 20, 2010

How to setup xen virtual machine in rhel5 / centos5

Xen is a virtualization software/ virtaul machine or virtual private server used in linux platform as VMware, Virtuzzo, openVZ, Parallelz etc. It decreases the need of dedicated machines. It is easy to configure. See the steps below!

First we have to check whether the processor support virtual machines or not
#cat /proc/cpuinfo
flags : pae

PAE is Physical Address Extension.

[or Processor with Intel VT technology]

##3Installing xen Virtual private server###
This is using a yum server. If you dont have a yum server configured, install the needed rpms.

yum -y install xen* kernel-xen*

7 packages will be installed


#yum -y install virt-manager /if not installed

###Change in grub.conf###
default=0 /Edited grub.conf n made xen boot 1st.
[otherwise you can select the xen kernel from grub menu while booting]

###Installation of Virtual Machine###
Two installation methods
[just execute the following command in terminal for graphical installation]
[just execute the following command in terminal for text installation]

###In text mode install###

virt-install must be run as root and, once invoked, will ask a number of questions before creating the guest system. The question are as follows:

What is the name of your virtual machine? - The name by which the guest system will be referenced when managing and monitoring the system with other tools.

How much RAM should be allocated (in megabytes)? - The amount of system memory to be made available to the guest operating system.

What would you like to use as the disk (path)? - The path to the file or disk partition to be used to contain the guest operating system.

Would you like to enable graphics support? (yes or no) - Defines whether the graphical installer is used (in a VNC window) or the text based installer in the shell.

What is the install location? - The location of the installation files for the OS. This can be an ftp, nfs, http, ISO image or local CD or DVD device location.

For listing Domain and virtual instances
#xm list

For starting a virtual machine
#xm create vm_name
#xm console vm_name

For shutting a virtual machine
#xm destroy vm_name

How to configure or setup VNC server in linux rhel5 / centos5

Sometimes we need to access remote servers. Most times we just ssh into them. But what if we required graphical access. VNC server comes there. It helps us to login to remote server graphically. Just as in remote desktop in Windows. VNC is Virtual network Computing.

How to Configure a VNC server In linux?
###VNC Server configuration###
#yum -y install vnc*

For using this we need to setup a password for the server. We can set it by the linux command vncpasswd.
###Set the password###

###Restart the service###
#service vncserver start

To make VNC server we need to run the following command. While executing it. it will create some files.
###Run the server command###
#vncserver :13 The display number. Default will be one. If available.

This file will be generated when executing the above command. We need to do a small change in that in order to make it was server.
# vi .vnc/xstartup
uncomment the following lines.
exec /etc/X11/xinit/xinitrc

#service vncserver restart

###VNC Client configuration###
[Accessing the VNC server from the client]
###Run the vncviewer command###
Server : Give the IP of Server with the display ID
Password: ****** Give the password

Its over. Have fun

###Installation through VNC###

boot: linux vnc vncpassword=redhat ip= netmask= gateway= //if more than one ethernet device is present u have to select one from them. But no need to configure the ips again.

language selection
network selection //if more than one is present

vncviewer ip:1
password: redhat

If you are getting grey screen when login via vnc, configure the vnc as follows.

[root@server ~]# cat /root/.vnc/xstartup

# Uncomment the following two lines for normal desktop:
exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
#[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session &
#twm &
[root@server ~]#

Kill all the processes associated with vnc and restart the service and execute vncserver command again.

How to configure disk qouta in centos linux

Quota is used for limiting the disk usage for users or groups.

To verify that the quota is enabled in the kernel
#grep CONFIG_QUOTA /boot/config-`uname -r`

CONFIG_QUOTA=y -enables limit on usage
CONFIQ_QUOTACTL=y -associated with disk quota manipulation.

If you have custom or upgraded kernel. Enable quota by running any of the following commands.
#make menuconfig
#make gconfig
#make xconfig

Check the quota package
#rpm -q quota

[root@server ~]# rpm -q quota
[root@server ~]#

For using Quotas the partition we are using for quota [quota can only be used per partition.] should be mounted with quota options. For that go to /etc/fstab and edit the partition mount options.

#vi /etc/fstab
LABEL=home /home ext3 defaults,usrquota,grpquota 1 1

If the partition is already mounted remount it for affecting changes in mount options.
#mount -o remount /home

Check the filesystem is mounted with changed options. If not, you may have to umount and mount again or u've to restart the system.
#mount -to check
Device_name on /mount_point type ext3 (rw,usrquota,grpquota)

Create quota database
#quotacheck -mcug /home
[ If you are using quotacheck -cug, it will throw an error that it cannot remount the filesystem mounted on m_point so counted values might not be right. Please stop all the programs writing to filesystem or use -m flag to force checking. This will happen when we use the filesystems like "/". Many processes are writing into "/" that time. Thats why it is throwing this error.]

-c option specifies that the quota files should be created for each file system with quotas enabled.
-u option specifies to check for user quotas.
-g option specifies to check for group quotas.
If not, those files will be created.

quotacheck -mcug /home -will create following files in /home

Assign quota policies for user
#edquota username
#quota username -shows the quota for set for that user

Assign quota policies for group
#edquota -g groupname -think a user should exist with that group
#quota -g groupname -shows the quota for set for that group

Defining prototypical users
edquota -p user1 user2

To see all user qouta reports
#repquota -a

To see the user quotas in /home
#repquota -u /home
To see the group quotas in /home
#repquota -g /home
To see the quotas in appropriate size
#repquota -s /home -shows used space and hard limit in MB
To check the quota is on or not
#quotaon -v /home

To update the usage
#quotacheck -mavug -execute this often for knowing latest usage info. Put it in cronjob. may need -f option.
[This will check all the files and directories in all partitions which is mounted with quota options.]
-a Check all mounted non-NFS filesystems in /etc/mtab
-v Verbose. Displays the information as it proceeds.
-u Checks for the user quotas.
-g Checks for the group quotas.

Add quotacheck to daily cron
# cat /etc/cron.daily/quotacheck
quotacheck -avug

Setting grace period
#edquota -t
10days not 10 days.

To enable and disable the qoutas
#quotaon -vaug with -m if needed. For only one partition; quotaon -vug /home
#quotaon -vaug -will turn on all the quotas [group and user]
#quotaoff -vaug -will turn off all the quotas [gruop and user]

How to schedule jos in linux using cron in rhel5 or centos5

Cron job is a job scheduling utility. If we configure a cron job to run on certain time, cron will run it according to the configuration.

These are the packages needed to install cron job.
###Packages :###

### Service ###


###vixie-cron installs the services and man pages:###

[root@server ~]# rpm -ql vixie-cron

###crontabs installs main configuration Directories:###

[root@server ~]# rpm -ql crontabs

### anacron installs 0anacron scripts ###

[root@server ~]# rpm -ql anacron


### Scheduling a cron job ###
Log in as the user who you want to execute the job.

#crontab -e //This will open a file in which u can specify Cron jobs. Press "i" for insert mode.

Cron job has a special format. It has six fields

Min Hour Date Month Day Program
[0-59] [0-23] [1-31] [1-12] [0-7] command
Jan,Feb Sun,Mon
Etc etc
[You can configure multiple jobs in next line(line by line)]
[save the file]

Example 1:
Suppose you want to run a job on February 19th at 10:35am. Job is creating a directory named test_cron under "/".

35 10 19 2 * mkdir /test_cron
Min Hr Date Month Every Day job

"*" Symbol in a field represents all valid values.

Example 2:
Multile values can be separated by commas.

0,15,30,45 * * * * touch /abc

This will update timestap of "/abc" in every 0th, 15th, 30th, and 45th minute of every hour. Every date, every month, every day of week.

Example 3:
Suppose you want to run a job every week days at 5 pm. Eg: Shutdown system everyday at 5 pm.

0 17 * * 1-5 init 0

Example 4:

*/15 * * * * who

The above line will run the "who" command every 15th minute, of every hour, of every
month, for all days of the week.

### Other crontab commands ###

#crontab -l //This will list the cron jobs of the logged user.
#crontab -u user_name -l //This will list the jobs of the user user_name.
#crontab -r //This will remove the users cron jobs.

All jobs will be saved in "/var/spool/cron/"
Normal users do not have access to that directories.

### Main Directories and Files ###

/etc/cron.deny //Contains the list of restricted users to schedule jobs.
/etc/cron.allow //Contains the list of allowed users to schedule jobs.

### Access Control ###

1.If both cron.deny and cron.allow do not exist, Only root user can schedule jobs.
2.If only cron.deny exists, all users excepts the users listed in cron.deny can schedule jobs.
3.If only cron.allow exists, root and listes users can schedule jobs.
4.If both files exits, then cron.deny will be ignored.

### Main directories in /etc ###

/etc/crontab runs and controls the executables in following direcotries.

1./etc/cron.hourly //Contains the files that are scheduled to be run hourly.
2./etc/cron.daily //Contains the files that are scheduled to be run daily.
3./etc/cron.weekly //Contains the files that are scheduled to be run weekly.
4./etc/cron.monthly //Contains the files that are scheduled to be run monthly.
5./etc/cron.d //Contains the additional system crontab files.

An example /etc/crontab file

[root@server ~]# cat /etc/crontab
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

Hourly jobs will execute at 1st minute of every hour, every date, every month, every week day. As root user. Run-parts is a script which run the jobs.
Daily jobs will execute at 4:02am everyday.
Weekly jobs will execute every Sunday at 4:22am
Monthly jobs wll execute every 1st day of month, at 4:42am

Example 5:
Suppose you want to run a few jobs in every two days

Create a directory "/etc/cron.2days with permission 755. And copy all the jobs to that directory.

#mkdir -m 755 /etc/cron.2days

And create and configure an entry for /etc/cron.2days in /etc/crontab

* * * * 0,2,4,6 root run-parts /etc/cron.2days

Restart the crond service.

### The Anacron System ###

The anacron runs the cron jobs that did not run when the computer is down. The daily jobs runs at 4:02am. At that time most computers [Eg Laptops] will be down. Anacron runs these non executed jobs when the system is up.

### Configuration File ###


There are four fields in each entry:

Period Delay Job-identifier Command

The period is specified in days, the delay in minutes. The job-identifier can contain any non-blank character, except slashes. It is used to identify the job in Anacron messages, and as the name for the job's timestamp file. The command can be any shell command.

An example /etc/anacrontab:

[root@server etc]# cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.

1 65 cron.daily run-parts /etc/cron.daily
7 70 cron.weekly run-parts /etc/cron.weekly
30 75 cron.monthly run-parts /etc/cron.monthly
[root@server etc]#

1st entry means, if the jobs in /etc/cron.daily have not been run in one day, it will wait 65 minutes after reboot and then runs it.

### How Anacron works:###

When Cron runs the run-parts command from /etc/crontab for cron.daily, cron.weekly, and cron.monthly, the first command to run is 0anacron. This command sets a timestamp in a file in /var/spool/anacron thats notes the time that this was last run.

On boot-up, the anacron command runs. The anacrontab file specifies how often the commands in cron.daily, cron.weekly, and cron.monthly should run. If they have nto run in this time, the anacron waits a few minuts as specified in second field of anacron entry and run the commands.

How to configure kickstart with remote installation in rhel5 [kickstart + dhcp] or centos5

KickStart [Unattended Installation]
When installing linux we have to sit if front of the system and answer the questions whenever it asks. This process is time consuming and needs one to attend while installation take process.Kickstart helps to install system unattended. We can create an answer file and notify the system to take the answers from the file. The file is known as kickstart file. We can configure dhcp such a way that it will automatically provide the system the path and details of the kickstart file in the network .In windows systems kickstart file is known as answer file. In this post we will see howto configure kickstart server linux step step and doing the remote installation using kickstart.

it is advised to read the remote installation post if you dont have much idea about remote installation.
These are the steps happening.
Server[dhcp+ks] client
1. asks IP and location of kickstart file the info
3. Takes the ks.cfg file and mounts share of OS

How to configure Automounter in rhel5 or centos5


###Service: autofs###
#service autofs start

###Main configuration file###

###Sub configuration files###
/etc/auto.misc For CD,Floppy etc.
/etc/ For the directories starting with"/".

###Adding a automount share###
#vi /etc/auto.master

Goto the following lines
/misc /etc/auto.misc
/net -hosts

Add this lines after the above lines
/- /etc/

Suppose u want to automount /media/rhel5 @ to /remote in your local


#mkdir /remote

#vi /etc/

#cd /remote
NFS share will be mounted automatically when u execute cd command to /remote. It will

be automatically unmount if you are not using the share for a particular amount of time.

You can set this time as shown below.

in /etc/auto.master file
/- /etc/ --timeout=60 Time is in seconds.