Sunday, January 3, 2010

iSCSI/NFS on LVM on RAID5 (Software RAID) howto guide, CentOS 5.3

This is just a quid blog to show howto, cos I found there are not much on-line tutorial cover this in a easy way.

And of course, as I keep it simple, it only cover basic stuffs. Please feel free to comment and add on better approach.



## RAID ##
===============================
Links:
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch26_:_Linux_Software_RAID

= Create Partition with 'fdisk'
to create partition (with 'n')
modify the partition's label to RAID (with 't', and code is fd)
then 'w' to write the partition
repeat until the disks is done
do a 'partprobe' to make sure it's written and take effect
do 'fdisk -l' to make sure the partition tables is correct

= Assign disk to raid
mdadm -C -v /dev/md0 -l5 -n3 /dev/hdb1 /dev/hdc1 /dev/hdd1
# l5 => RAID 5, n3 => a RAID set of 3 disks
cat /proc/mdstat # make sure RAID is created. it will also show if it's sync-ing or recoverying
mdadm -D -s -v # Double check. or 'mdadm -D -s -V /dev/md0


## LVM ##
===============================
Links:
http://www.howtoforge.com/linux_lvm_p3

= Create Physical Volume(PV), Volume Group(VG) and Logical Volume(LV)
pvcreate /dev/md0 # assign "/dev/md0" as an PV
pvdisplay # make sure they're all set
vgcreate vg-raid /dev/md0 # create VG group "lvm-raid"
vgdisplay # Show the Volume Group status
lvcreate -n xStorage -L 40G vg-raid # Create a LV as xStorage, 40G from vg-raid
lvdisplay # Show Logical Volume status
ls /dev/vg-raid/xStorage # The created LV should be here..
mkfs.ext3 /dev/vg-raid/xStorage # format the LV to be used
mount /dev/vg-raid/xStorage /mnt # lets test if we could mount it. :-)
df -h # You should see it in your mounted list

## iSCSI ##
===============================
Links:
http://www.cyberciti.biz/tips/howto-setup-linux-iscsi-target-sanwith-tgt.html

= Installation
yum -y install scsi-target-utils iscsi-initiator-utils
chkconfig iscsid on
chkconfig iscsi on
chkconfig tgtd on
chkconfig --list | grep iscsi
chkconfig --list | grep tdtd
/etc/init.d/iscsi restart
/etc/init.d/tgtd restart
/etc/init.d/iscsid restart

= Configuring iSCSI Target (iSCSI Server)
tgt-setup-lun -d /dev/vg-raid/xStorage -n xStore 192.168.1.4 # create lun only accept client with IP 192.168.1.4
#*** NOTE: You can only setup lun with a device, not partition!! ***#
tgtadm --lld iscsi --op show --mode target # Show alll luns
iscsiadm --mode discovery --type sendtargets --portal 192.168.1.4 # List lun from the server
Change iptables:
iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --dport 3260 -j ACCEPT # Open the port to all NIC
iptables-save > /etc/sysconfig/iptables # Save the updated rules to iptables configuration file

= Configuring iSCSI Initiator (iSCSI Client)
iscsiadm -m discovery --type sendtargets --portal 192.168.1.4 # Check if the iSCSI Target is accessable
iscsiadm -m node -T iqn.2001-04.com.NesSAN-xStore -l # -l to login to target, -u to logout
# add '--portal 192.168.1.4:3260' for specifid server
ll /dev/sd* # The new disk should be now there.
mount /dev/sdc /mnt # Lets mount it..
df -h
touch `hostname`-`date +%Y%m%d-%H%M%S` # Test if it's writable and if it's sync over the network


## NFS ##
===============================
Links:
http://www.cyberciti.biz/tips/howto-setup-linux-iscsi-target-sanwith-tgt.html


echo '
# Local Mount Name # Client Access List
/mnt 192.168.1.0/24(rw,no_root_squash,sync)
' >> /etc/exports

exportfs -a
/etc/init.d/nfs restart # Restart nfs mount