Friday, July 17, 2009

Add repository for YUM

While using yum in RHEL, it used to say :

Loading "security" plugin
Loading "rhnplugin" plugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Parsing package install arguments
No package sendmail-cf available.
Nothing to do

I then thought, why not just change the repository for my YUM.. it's as easy as 123..

step 1. Go to /etc/yum.repos.d directory
step2. Create a file e.g myrepos
step3. Add the section header e.g [myrepos]
step4. Add the URL for the rpm repos; your final repos might look like this
#vi /etc/yum.repos.d/myrepos
[myrepos]
baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel5/i386/
gpgcheck=0
step5. If you've done that, the rest is simple. Upgrade your system by doing:
yum update
You can add new software by typing:
yum install
Or update installed software:
yum update
Or search for software in the local repository meta-data:
yum search
Or simply list all available software:
yum list available
From time to time you may want to save some diskspace:
yum clean

for more: http://dag.wieers.com/rpm/FAQ.php#B

Monday, April 20, 2009

step-by-step SUDO in linux

http://www.linuxhelp.net/guides/sudo/

Sunday, April 19, 2009

Step-By-Step Configuration of NAT with iptables

http://www.howtoforge.com/nat_iptables

Replacing Hard disk in RAID 1

http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array

http://www.howtoforge.com/how-to-resize-raid-partitions-shrink-and-grow-software-raid

http://lists.us.dell.com/pipermail/linux-poweredge/2003-July/008898.html

Personally I would give milions hi5 to above link ;-)

Implementing RAID in LINUX

Create a RAID Device /dev/md4 by creating equal two disks from available free space on your harddisk and mount it on /data. 


Let's say we have /dev/hdd as our added disk and we don't have extra harddisk.. becoz i am poor guy and i can't buy new disk during the current economic recession ;-)
I can create two partitions which can be treated as two disks for the RAID implementation.

Create the Two partitions having equal size.

Change the Partition ID to fd (Linux raid Autodetect)


#fdisk /dev/hdd
........
.........
/dev/hdd3            2001        2500      252000   fd  Linux raid autodetect
/dev/hdd4            2501        4161      837144    5  Extended
/dev/hdd5            2501        3000      251968+  fd  Linux raid autodetect
.......

Use partprobe command to synchronic the partition table. 

[root@localhost ~]# partprobe

[root@localhost ~]# mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/hdd3 /dev/hdd5
mdadm: array /dev/md4 started.

[root@localhost ~]# mkfs -t ext3 /dev/md4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
62992 inodes, 251904 blocks
12595 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
31 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks: 
8193, 24577, 40961, 57345, 73729, 204801, 221185

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@localhost ~]# mkdir /data

[root@localhost ~]# cd /data
[root@localhost data]# ls
lost+found

(which implies that /dev/md4 is sucessfully mounted )

http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array





Why SGID bit?

Who ever creates the files/directories on /mygrpdir group owner should be 

automatically should be the same group owner of /mygrpdir. 


1.     chmod g+s /mygrpdir

2.     Verify using: ls -ld /mygrpdir 

Permission should be like: 

drwxrws--- 2 root sysusers 4096 Mar 16 18:08 /mygrpdir 


If SGID bit is set on directory then who every users creates the files on directory group 

owner automatically the owner of parent directory. 

 

To set the SGID bit: chmod g+s directory 

To Remove the SGID bit: chmod g-s directory 

Extending and Reducing LV in LINUX

Lets extend the size of  testlv

[root@localhost ~]# lvdisplay /dev/testvg/testlv
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                100.00 MB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0


[root@localhost ~]# umount /dev/testvg/testlv 

[root@localhost ~]# fsck -f /dev/testvg/testlv 
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/25792 files (9.1% non-contiguous), 8927/102400 blocks

[root@localhost ~]# lvextend -L +150M /dev/testvg/testlv 
  Rounding up size to full physical extent 152.00 MB
  Extending logical volume testlv to 252.00 MB
  Logical volume testlv successfully resized


[root@localhost ~]# resize2fs /dev/testvg/testlv 
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/testvg/testlv to 258048 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 258048 blocks long.


[root@localhost ~]# lvdisplay /dev/testvg/testlv 
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                252.00 MB
  Current LE             63
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0



****************************************************
After we are done with increasing the size of testlv, let's reduce the size of testlv

[root@localhost ~]# umount /dev/testvg/testlv

[root@localhost ~]# fsck -f /dev/testvg/testlv
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/63488 files (9.1% non-contiguous), 14193/258048 blocks

[root@localhost ~]# resize2fs /dev/testvg/testlv 150M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/testvg/testlv to 153600 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 153600 blocks long.


[root@localhost ~]# lvreduce -L 150M /dev/testvg/testlv 
  Rounding up size to full physical extent 152.00 MB
  WARNING: Reducing active logical volume to 152.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testlv? [y/n]: y
  Reducing logical volume testlv to 152.00 MB
  Logical volume testlv successfully resized

[root@localhost ~]# lvdisplay /dev/testvg/testlv 
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                152.00 MB
  Current LE             38
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0



(have u noticed the sequence of commands: lvextend and resize2fs commands are in different order for two different operations. Keep only one thing in mind, resize2fs should be run before lvextend while reducing the size of LV )

Sunday, April 12, 2009

Step by Step guide: Manage additional disk on Linux using LVM

Let's we have physical drive connected in slave of secondary IDE i.e /dev/hdd

#fdisk /dev/hdd (and create following partitions with id:8e)

Device Boot Start End Blocks Id System
/dev/hdd1 1 1000 503968+ 8e Linux LVM
/dev/hdd2 1001 2000 504000 8e Linux LVM

[root@localhost ~]# pvcreate /dev/hdd1 /dev/hdd2
Physical volume "/dev/hdd1" successfully created
Physical volume "/dev/hdd2" successfully created

[root@localhost ~]# pvdisplay [compare with the o/p of same command after creating f/s of LV]
"/dev/hdd1" is a new physical volume of "492.16 MB"
--- NEW Physical volume ---
PV Name /dev/hdd1
VG Name
PV Size 492.16 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID lanTX2-t6KC-MTID-Ag8V-un2g-R6a9-janMLC

"/dev/hdd2" is a new physical volume of "492.19 MB"
--- NEW Physical volume ---
PV Name /dev/hdd2
VG Name
PV Size 492.19 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID W29vIo-K2SN-07Zl-3Xn8-1pDX-hkxQ-P3gk2h


[root@localhost ~]# vgcreate testvg /dev/hdd1 /dev/hdd2
Volume group "testvg" successfully created


[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 980.00 MB
PE Size 4.00 MB
Total PE 245
Alloc PE / Size 0 / 0
Free PE / Size 245 / 980.00 MB
VG UUID TbRxlH-zYl9-Y3zz-tsEH-1ASj-1uma-qhVLo8


[root@localhost ~]# lvcreate -L 124M -n testlv testvg [creating LV of size 124M with name testlv ]
Logical volume "testlv" created

[root@localhost ~]# lvdisplay /dev/testvg/testlv
--- Logical volume ---
LV Name /dev/testvg/testlv
VG Name testvg
LV UUID jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
LV Write Access read/write
LV Status available
# open 0
LV Size 124.00 MB
Current LE 31
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0


[root@localhost ~]# mkfs -t ext3 /dev/testvg/testlv [ creating filesystem ]
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
31744 inodes, 126976 blocks
6348 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
16 block groups
8192 blocks per group, 8192 fragments per group
1984 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@localhost lvmmntpt]# pvdisplay
--- Physical volume ---
PV Name /dev/hdd1
VG Name testvg
PV Size 492.16 MB / not usable 4.16 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 122
Free PE 122
Allocated PE 0
PV UUID lanTX2-t6KC-MTID-Ag8V-un2g-R6a9-janMLC

--- Physical volume ---
PV Name /dev/hdd2
VG Name testvg
PV Size 492.19 MB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 123
Free PE 92
Allocated PE 31
PV UUID W29vIo-K2SN-07Zl-3Xn8-1pDX-hkxQ-P3gk2h

[root@localhost lvmmntpt]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 980.00 MB
PE Size 4.00 MB
Total PE 245
Alloc PE / Size 31 / 124.00 MB
Free PE / Size 214 / 856.00 MB
VG UUID TbRxlH-zYl9-Y3zz-tsEH-1ASj-1uma-qhVLo8

[root@localhost lvmmntpt]# lvdisplay /dev/testvg/testlv
--- Logical volume ---
LV Name /dev/testvg/testlv
VG Name testvg
LV UUID jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
LV Write Access read/write
LV Status available
# open 1 [ here open is 1 because it's mounted]
LV Size 124.00 MB
Current LE 31
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

[root@localhost ~]# vi /etc/fstab
…....
…....
/dev/testvg/testlv /lvmmntpt ext3 defaults 0 0


[root@localhost ~]# mount -a

[root@localhost ~]# cd /lvmmntpt/

[root@localhost lvmmntpt]# ls
lost+found
(It indicates successful mounting of newly created LV )

Sunday, March 29, 2009

LVM2

Logical Volume Manager

LVM is a tool for logical volume management which includes allocating disks, striping, mirroring
and resizing logical volumes

LVM version 2, or LVM2, is the default for Red Hat Enterprise Linux 5, which uses the device
mapper driver contained in the 2.6 kernel.

Steps required to configure LVM include:

• Creating physical volumes from the hard drives.
• Creating volume groups from the physical volumes.
• Creating logical volumes from the volume groups and assign the logical volumes mount
points.

PHYSICAL VOLUMES ---> VOLUME GROUP ---> LOGICAL VOLUME ---> MOUNT POINT/FILE SYSTEMS

(note: For Red Hat Enterprise Linux, LVM is the default method for disk partitioning: To verify it, try to use the default installation and see the File Systems, you can see LVM )
Let me walk you through the manual LVM configuration while linu installation:
Lets say my system has 2 IDE drives each of 3.0GB; As we know for linux installation, minimally we need to create following 3 partitions
/boot : it can't be created in logical volume
swap
/
(note: The physical volumes are combined into logical volumes, with the exception of the /boot/partition. The /boot/ partition cannot be on a logical volume group because the boot loadercannot read it. If the root (/) partition is on a logical volume, create a separate /boot/ partitionwhich is not a part of a volume group. )
......... will be discussed in detailed in lab............


Sunday, March 15, 2009

How to setup VSFTP server in RHEL5?

VSFTP: Very Secure File Transfer Protocol


========SERVER=============

[root@ilinux ~]# rpm -qa|grep vsftpd
vsftpd-2.0.5-12.el5

[root@ilinux ~]# service vsftpd status
vsftpd is stopped

[root@ilinux ~]# service vsftpd start
Starting vsftpd for vsftpd: [ OK ]

[root@ilinux ~]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@ilinux ~]# chkconfig --level 35 vsftpd on
[root@ilinux ~]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off

[root@ilinux ~]# vi /etc/vsftpd/vsftpd.conf

By default, anonymous user can do ftp without password;
anonymous user is chrooted to /var/ftp as "/"
local users (linux users) can do ftp using password;
local users are not chrooted by default; i.e local users can access all the resources of the system using ftp

===========CLIENT SIDE================

#ftp IP-ADD of server
username: anonymous
password: password is not required
ftp>help
ftp>ls {it will show the content of the remote/server}
ftp>!ls {it will display the content of the local system}
ftp>pwd {it will show the PWD of the remote/server}
ftp>lcd {it will display the LOCAL working directory}

[notice: for anonymous user pwd will display "/" which is chrooted to /var/ftp]

#ftp IP-ADD of server
username: local user's username
password: password
ftp>........
...............
[notice: for local users by default pwd will be "/home/username" and local users can change the location on the remote server i.e he can go to /etc or any possible location and thus can theft the important data easily]

========================================
========================================

=========SERVER SIDE================
Q: How to create chroot jail for the local users?
A: For this we need to uncomment few lines shown below in /etc/vsftpd/vsftpd.conf

#vi /etc/vsftpd/vsftpd.conf
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

#vi /etc/vsftpd/chroot_list
[add the usernames to be chrooted to /home/username]

#service vsftpd restart

=============CLIENT SIDE==================

#ftp
username:
password:
ftp>........
...............

[now PWD will show "/" as user is chrooted to /home/username and local users cannot change the location outside /home/username as "/" for this user will be "/home/username"