Thursday, May 31, 2012

The beginning of an ISCSI server with LVM and CentOS

Creating an iscsi storage server. The hardware I'm using is an old server with 8 250GB drives. The plan is to install CentOS even though something like FreeNAS would work fine. Setup the disks in a LVM layout with the majority of the free space is used for data storage. Ideally the OS would be on a raided disk array separate from the data storage. But just to get a simple setup going I'll have the OS on a single disk.

General steps:

  1. create and setup logical volume
  2. install iscsi target
  3. configure iscsi
  4. test

  • LVM 
To create a physical volume for use in a logical volume we'll use pvcreate.
pvcreate --zero y /dev/sde will zero the first 2048 bytes of sde and initialize sde for use.
I created 4 PVs using pvcreate --zero y /dev/sde /dev/sdf /dev/sdg /dev/sdh.
Next is to create a volume group.

To create a volume group use vgcreate. vgcreate VG_stor /dev/sde, this will create a volume group with the name VG_stor which contains the PV sde.
For my VG I ran vgcreate VG_stor /dev/sde /dev/sdf /dev/sdg /dev/sdh
Now time to create logical volumes

Logical volumes are created using lvcreate. To create a 100GB volume the command would look like lvcreate -L 100G -n vol_scsi VG_stor. This creates a 100GB volume with the name vol_scsi from the volume group VG_stor.
The command I used was lvcreate -L 100G -n vol_scsi VG_stor

In short
pvcreate --zero y /dev/sde /dev/sdf /dev/sdg /dev/sdh;
vgcreate VG_stor /dev/sde /dev/sdf /dev/sdg /dev/sdh;
lvcreate -L 100G -n vol_scsi VG_stor;


  • iSCSI target setup
Now that the the LV has been created the iSCSI needs to be configured.
To config file for the iSCSI target is /etc/tgt/targets.conf.
This setup will be very simple. Edit targets.conf and add the following:
<target iqn.2012-05.host.server:target0>
     backing-store /dev/VG_stor/vol_scsi
</target>

Now start the target daemon and have it startup on boot.
service tgtd start;
chkconfig tgtd on;

Check the target information
tgtadm --mode target --op show;

Allow port 3260 via tcp in iptables.

This should show the targets that are configured.

All that is left is to create and setup the iSCSI initiator.


  • iSCSI initiator setup


install iscsi-initiator-utils and configure /etc/iscsi/iscsid.conf if needed.
Now time to discover the target. iscsiadm -m discovery -t sendtargets -p iscsi-target-ip
There should be a target listed with the iqn of the iscsi target.

start the iscsi services
service iscsi start;
service iscsid start;

Look at the discovered targets.
iscsiadm -m node -o show;

Time to login to the target and confirm session.
iscsiadm -m node --login;
iscsiadm -m session -o show;

There should be a new entry in /proc/partitions. In my case it was sdd.

Now that is a basic run through on using LVM and iSCSI. It can get much more complex.

No comments:

Post a Comment