Search This Blog

Wednesday, June 30, 2010

All About NFS

1)Definition
2)Why to use
3)External source for reading.
4)Syntax
5)Example

1)The Network File System (NFS) is an industry standard.

2)NFS allows entire file systems to be shared among other machines in a network.

3)A very good article about NFS can be found at following location.
http://www.linux-tutorial.info/modules.php?name=MContent&pageid=150

4)
Before we talk about the syntax lets make some things clear about nfs.

In NFS architecture there is a Server and client(s).
Server is the one who is having a disk space to share.
Client is the one who want to use space on remote machine.

The syntax for using the mount command to mount remote file system is basically the same as for local file systems.
The difference being that you specify the remote host along with the exported path. For example, if I want to mount the man-pages from 10.180.18.222, I could do it like this:
First make following path exists in client .
/usr/man
if it doesn't exists then create it.

run following command at client command prompt.
#mount -t nfs [-o options] 10.180.18.222:/usr/man /usr/man

5)

In following example i m sharing a folder using NFS.

NFS Server:
Make sure nfs service is running.
# service nfs status
rpc.mountd (pid 10428) is running...
nfsd (pid 10425 10424 10423 10422 10421 10420 10419 10418) is running...

I m sharing below folder.

# ls -ltrd /shareddocument/
drwxr-xr-x 2 root root 4096 Jan 25 17:16 /shareddocument/

Command to share the folder to client.

# exportfs client_ip_address:/shareddocument

type exportfs to list shared folders and clients who can share them.

# exportfs
/shareddocument client_ip_address


NFS Client:

Make sure nfs service is running.

Mount the folder

# mount server_ip_address:/shareddocument /shareddocumentonserver

NFS mount using exportfs is well documented in below link.

http://www.thegeekstuff.com/2010/10/nfs-mount-guide/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+TheGeekStuff+%28The+Geek+Stuff%29

More on this coming soon.

Tuesday, June 22, 2010

How to trim variable in linux.

if MACHINE_NAME=ABCDF


use following simple commands to trim it.


# echo $(echo $MACHINE_NAME)

This will cause MACHINE_NAME to contain ABCDF without any white spaces in either left or right sides.

Linux sed command.

In this article for sed command we will deal with below queries.

1)How to delete a line of a file specifying line number?
2)How to change case of letters/characters using sed?
3)How to delete blank lines of files.

How to delete a line of a file specifying line number?

content of temp.txt

a
b
c
d

We can delete a specific line of file using sed.
For example .
If we need to delete 2nd line of a file temp.txt .
run
#sed "2d" temp.txt
output:
a
c
d

What if we need to include a variable that defines the line number to be deleted.

#var=2; sed "${var}d" temp.txt
output:
a
c
d

(Note:here sed command doesnt make any changes the actual content of a file instead it is just shows the output after deleting the second line of a file.
For actually deleting the line in a file. you need to generate separate file using the output provided by sed command and then replace it with existing file using mv.)

for example.
above code can be written as.
#var=2; sed "${var}d" temp.txt > tmp.txt
#mv temp.txt tmp.txt
More information and different ways to accomplish the task can be found at.
http://www.unix.com/shell-programming-scripting/138366-how-would-i-delete-line-specific-line-number.html

How to change case of letters/characters using sed?


# cat /tmp/names.txt
rohan
arun
adam
john

# cat /tmp/names.txt |sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
ROHAN
ARUN
ADAM
JOHN

Note:
y/source/dest/
Transliterate the characters in the pattern space which appear in source to the corresponding char-acter in dest.


3)How to delete blank lines of files.

Lets create a file called File1.txt .
# cat File1.txt
Agnes Gonxha Bojaxhiu more commonly known as Mother Teresa


Mother Teresa's Missionaries of Charity at the time of her death had 610 missions in 123 countries including hospices

Notice the two spaces between the lines.
Lets use delete to delete those line(you may use i operator instead of e for modifying the file File1.txt).
# sed -e '/^ *$/d' File1.txt
Agnes Gonxha Bojaxhiu more commonly known as Mother Teresa
Mother Teresa's Missionaries of Charity at the time of her death had 610 missions in 123 countries including hospices

Note:
^ (caret) : used for matching the beginning of the line.
$ (dollar sign) : used for matching end of the line.
* (asterisk) : used for matching zero or more occurrences of the previous character ( the previous character in this case is a space).


AWK

Awk Programming.

1) Simple Awk commands:

Examples:
# date
Mon Nov 30 09:46:09 IST 2009

# date | awk '{print $2}'
Nov

# date | awk '{print $2 " " $6}'
Nov 2009

# date | awk '{print "Month : " $2 " Year : " $6}'
Month : Nov Year : 2009
2) Awk command with a use of variable:
#Command | awk -v h="$hostname" '{print $0, h}'

Here h is a variable called hostname .
If a ouput of command is
Aaa 111 222
Bbb 333 444
Ccc 444 444
And when you pipe it to awk .
For example.
#Command | awk -v h="$hostname" '{print $0, h}'
The output will be:
Aaa 111 222 hostname
Bbb 333 444 hostname
Ccc 444 444 hostname

Advanced AWK

#xm list" < /dev/null | grep -v Name |awk 'BEGIN {tot=0} "totalvcpu" {tot=tot+$4} END {print tot}'
The above command will sum up 4 column returned by xm list" < /dev/null | grep -v Name and display to total of every value in column 4.
More will be coming soon.

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

Monday, June 21, 2010

FTP setup in Linux

for setting up ftp server you will need vsftpd rpm (OEM OS).

I have got the rpm from OEM 4.7 CD itself (CD 3).

vsftpd rpm is version specific.

vsftpd-2.0.1-6.el4.i386.rpm is suitable for OEM 4.7.

You may get the same rpm

Then i have read following documents for setting up FTP.

http://www.idevelopment.info/data/Unix/Linux/LINUX_TelnetFTPAsRoot.shtml


This is done so as to provide root to ftp login into system.
We had difficulties from other user logins such as ftp .We were not allowed to change the directories.
So I have setup root to ftp login However it is not recommended for security reasons.

How to add a new repository to Oracle Virtual Server.

Mounting NFS Share as repository.
To make sure which repository is currently exist in the server .
run
#/opt/ovs-agent-latest/utils/repos.py -l
typically for the first run it won't list anything.

Create a share on storage then add the share as repository.
#/opt/ovs-agent-latest/utils/repos.py -n 10.180.36.110:/export/LAB

You should get something like this.
#/opt/ovs-agent-latest/utils/repos.py -l
c9a30a22-f0c5-435f-8f31-376e95f54107 => 10.180.36.110:/export/LAB

To make the repository as root .
run
#/opt/ovs-agent-latest/utils/repos.py -r 86bacbb6-99a4-48e6-b2f9-89598943e16e
[ * ] c9a30a22-f0c5-435f-8f31-376e95f54107 => 10.180.36.110:/export/LAB

(here [ * ] indicates its a root )

For more detailed information on different options available with repos.py
run
#/opt/ovs-agent-latest/utils/repos.py

Mounting Local shares as repositories.

#/opt/ovs-agent-2.3/utils/repos.py -n /dev/sda5
#/opt/ovs-agent-2.3/utils/repos.py -n /dev/sdb1
#/opt/ovs-agent-2.3/utils/repos.py -n /dev/sdc1
List the repositories.
#/opt/ovs-agent-2.3/utils/repos.py -l
Make one as root repository.
#/opt/ovs-agent-2.3/utils/repos.py -r a7d5463b-288f-4c14-b28a-5e999c987a29
More on this coming soon.

Difference between ethtool and miitool

ethtool is use widely in the linux distributions.

However miitool is not outdated, but superseded. According to the net, it still can handle some older NICs that ethtool can't.

Sunday, June 20, 2010

How to Partition a Hard Disk In Linux.

Tomcat Installation

Step 1 : Install an Operating System.

Operating System: OEL5.2_32bit
For Default installation you will need first 3 cds namely.

Enterprise-R5-U2-Server-i386-disc1.iso
Enterprise-R5-U2-Server-i386-disc2.iso
Enterprise-R5-U2-Server-i386-disc3.iso

Step2:Install Tomcat, JDK, JRE and define a save point.

We are going to install following softwares in the newly created machines.

Make a folder named install in /.
Copy all the required softwares in /install.
apache-tomcat-5.5.29.tar.gz
jdk-6u20-linux-i586-rpm.bin
jre-6u20-linux-i586-rpm.bin

Installation Guide:

1)apache-tomcat-5.5.29.tar.gz:
I have choosen linux version of tomcat.
For Initial Setup You should always go for
Core version download.
downloaded apache-tomcat-5.5.29.tar.gz
#gunzip apache-tomcat-5.5.29.tar.gz
#tar -xvf apache-tomcat-5.5.29.tar.gz
This will create a new folder as apache-tomcat-5.5.29 in same directory.
go to apache-tomcat-5.5.29/bin
run
#./startup.sh

it will not run as java new version is not yet installed.

2) jdk-6u20-linux-i586-rpm.bin:
Next we will install latest jdk version.
#chmod +x jdk-6u20-linux-i586-rpm.bin
#./ jdk-6u20-linux-i586-rpm.bin
This will create a new folder in
/usr/java/jdk1.6.0_20/
use it for JAVA_HOME.



3) jre-6u20-linux-i586-rpm.bin
Next we will install latest jre version.
#chmod +x jre-6u20-linux-i586-rpm.bin
#./jre-6u20-linux-i586-rpm.bin
This will create a new folder in
/usr/java/jre1.6.0_20/
use it for JRE_HOME.

After installation of above mentioned 3 important software its time to take snapshot of the machine.


Step3:Configure java and TOMCAT and define a savepoint.

# javac -version
javac 1.6.0_20
# java -version
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20071124 (Red Hat 4.1.2-42)

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


######At this time java is set to default java in linux our aim is to change it to latest java version.
for setting up this you need root login therefore type

#su

######Then you type

#/usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_20/bin/java 2

######Finally you type
#;/usr/sbin/alternatives --config java
........ and choose '2'nd option.


Now make sure you disable firewall .

# system-config-securitylevel
Disable the firewall

I have created a script called Tomcat and pasted following content inside it.
# This is the init script for starting up the
# Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

tomcat=/install/apache-tomcat-5.5.29
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
export JAVA_HOME=/usr/java/jdk1.6.0_20


start(){
echo -n $"Starting Tomcat service: "
#daemon -c
$startup
RETVAL=$?
echo
}

stop(){
action $"Stopping Tomcat service: " $shutdown
RETVAL=$?
echo
}

restart(){
stop
start
}


# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
# This doesn't work ;)
status tomcat
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac

exit 0


Edit the lines that start with tomcat and export to match where you installed tomcat and your jdk.

Note: I can't remember where I first got the original version of this script so if you deserve credit for this,

Save the script with name “tomcat” to a location “/etc/init.d”

(at least on most newer releases since /etc/init.d is a standard now). Then you have to allow execute access to the script, so run:

#chmod a+x tomcat
Add to appropriate run level directories

The easy way to do this is to just simply run:

#chkconfig --add tomcat


Add username/Password for tomcat manager:
How to add a new user name to tomcat manager:

just add line number 3 and 6 to /install/apache-tomcat-5.5.29/conf/tomcat-users.xml
xml version='1.0' encoding='utf-8'?>
tomcat-users>
role rolename="manager"/>
role rolename="tomcat"/>
role rolename="role1"/>
user username="manager" password="tomcat" roles="manager,tomcat"/>
user username="tomcat" password="tomcat" roles="tomcat"/>
user username="both" password="tomcat" roles="tomcat,role1"/>
user username="role1" password="tomcat" roles="role1"/>
tomcat-users>

Restart tomcat server.
By using service tomcat restart.



To check whether the Tomcat is running or not.

#netstat -ntpl | grep java
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 6375/java
tcp 0 0 :::8009 :::* LISTEN 6375/java
tcp 0 0 :::8080 :::* LISTEN 6375/java

You should see at least one java process and you can use ps to identify if this is Tomcat.

# ps -ef | grep 6375
root 6375 1 0 May18 pts/2 00:01:06 /usr/java/jdk1.6.0_20/bin/java -Djava.util.logging.config.file=/install/apache-tomcat-5.5.29/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/install/apache-tomcat-5.5.29/common/endorsed -classpath /install/apache-tomcat-5.5.29/bin/bootstrap.jar -Dcatalina.base=/install/apache-tomcat-5.5.29 -Dcatalina.home=/install/apache-tomcat-5.5.29 -Djava.io.tmpdir=/install/apache-tomcat-5.5.29/temp org.apache.catalina.startup.Bootstrap start
root 9222 5091 0 18:29 pts/2 00:00:00 grep 6375

Network Ethernet Port Checker

If you want to make sure which physical interface is eth0 and which is eth1 or eth2 and so on

run:

#ethtool -p eth0 20

This blinks the LED on the interface for five seconds–without interrupting network traffic.

#ethtool eth0

This will show the port speed .

A good article over ethtool can be found here.

http://www.thegeekstuff.com/2010/10/ethtool-command/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+TheGeekStuff+%28The+Geek+Stuff%29

Friday, June 18, 2010

Add new disk to linux server.

Very Good link to teach how to add new hard disk to existing machine.


In below mentioned article author has added a second hard disk to existing machine and formatted it with the ext3 file system. For the purpose of this example, you need to add a second hard drive in a Red Had Linux system where the drive will be recognized as /dev/hdb or /dev/sdb.

this tutorial will create one partition on newly created hard drive which will be /dev/hdb1 or /dev/sdb1.

http://www.idevelopment.info/data/Unix/Linux/LINUX_PartitioningandFormattingSecondHardDrive_ext3.shtml

schedule script in linux using crontab.

Example 1:
This Example will schedule a job on 12 april at 23:00 Pm on Monday.

run following command in Linux.

#crontab -e

You will get a editor in linux .

just enter following lines into it.
00 23 12 4 mon /usr/local/sbin/copyfile.sh



Explanation
Min Hour day month day (script to be executed)
00 23 12 4 mon /usr/local/sbin/copyfile.sh



You can use following command to see what jobs are scheduled in the machine.
crontab -l



At command:
You can use at command to execute the command only once. This is to avoid repetitive execution of command.Even if cron is capable of doing this but it is recommended to execute the command using at if it is supposed to run once .

Nice article over crontab.

http://www.thegeekstuff.com/2011/12/crontab-command/

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

How to add SSH Keygen

Add keygen to avoid prompting for password while running ssh command.

Type ssh-keygen –t rsa command at Server
.
When asked to save the file just press enter

[root@ServerHostname .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
#by default the key is saved in /root/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
49:66:a2:5f:73:5f:d4:fc:31:24:44:41:32:01:58:58 root@SERVERHOSTNAME

there are two methods to add the key to client choose whichever is suited to you.
Method 1:
Then ssh the id_rsa.pub file to remote server with the name as authorized_keys.
scp -p /root/.ssh/id_rsa.pub root@HOSTNAME:/root/.ssh/authorized_keys
Method 2:
Run following command from Server.
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@ClientHOst/IP
enter password for client machine.

Validate :
run SSH clientHOST/IP
You should be able to get the terminal of client without asking for any password.

How to run a command on Other server .

First login to the Client say (A) . Type following command.

ssh –t –t -q date

the above command displays date on Server.

Network Speed Allocation.

ethtool -s eth0 speed 100 duplex full autoneg off

to force the first NIC to operate at fix and non-negotiable speed at 100Mbps full duplex.

Use of scp

Copy a file using scp

# scp DEV_template root@10.180.45.152:/OVS

This will copy DEV_template file to /OVS of 10.180.45.152 machine.

How to list hidden files only.

list only hidden files

ls -a | grep ^"\."

How to list directories only.

To find directories only
(suppose a particular directory contains lot of files and directories and if we want to see only directories then use following command)

ls -l | grep ^d

find . -type d


Regular expression metacharacters
^ = Start of line
so "ls -l | grep ^d" will grep each line of output from ls for lines that begin with d and only d. (it will ignore d in any other position of the line).

Please find My post asking users to list directories only.

href="http://www.linuxquestions.org/questions/linux-newbie-8/how-to-list-directories-only-764450/

How to delete file in Linux

Delete Files

Use rm –rf with folder or file name (Use it very carefully)

How to gather Information about Linux Machine.

With a wide variety of Linux distributions available ,Sometime it becomes very essential to know which OS you are using.

I have listed some important commands to accomplish the task.
Name of distribution
# uname -o
GNU/Linux
Name of kernel version
# uname -r
2.6.9-78.0.0.0.1.ELhugemem
Version of OS only 4 redhat
# cat /etc/redhat-release
Enterprise Linux Enterprise Linux AS release 4 (October Update 7)

lsb_release –a ----------------------Very useful

http://www.linuxquestions.org/questions/linux-newbie-8/which-command-to-use-to-find-name-of-operating-system-764452/#post3732489

Use following program to determine the name of distribution you are using.

function get_distro_name {
if [[ -r '/etc/lsb-release' ]]; then
. /etc/lsb-release
[[ "$DISTRIB_ID" ]] && n="$DISTRIB_ID"
elif [[ -r '/etc/release' ]]; then
n=`head -1 /etc/release | sed 's/ *\([[^0-9]]*\) [0-9].*/\1/'`
elif [[ -r '/etc/arch-release' ]]; then
n="Arch Linux"
elif [[ -r '/etc/debian_version' ]]; then
n='Debian'
elif [[ -r '/etc/gentoo-release' ]]; then
n='Gentoo'
elif [[ -r '/etc/knoppix-version' ]]; then
n='Knoppix'
elif [[ -r '/etc/mandrake-release' ]]; then
n='Mandrake'
elif [[ -r '/etc/pardus-release' ]]; then
n='Pardus'
elif [[ -r '/etc/puppyversion' ]]; then
n='Puppy Linux'
elif [[ -r '/etc/redhat-release' ]]; then
n='Red Hat'
elif [[ -r '/etc/sabayon-release' ]]; then
n='Sabayon'
elif [[ -r '/etc/slackware-version' ]]; then
n='Slackware'
elif [[ -r '/etc/SuSE-release' ]]; then
n='SuSE'
elif [[ -r '/etc/xandros-desktop-version' ]]; then
n='Xandros'
elif [[ -r '/etc/zenwalk-version' ]]; then
n="Zenwalk"
fi
[[ "${n:-}" = '' ]] && \echo "ERROR: Could not determine the distro name" >&2 && \exit 1
echo $n
}
get_distro_name