In this “How-To” tutorial, I am going to explain how we can set up LUN/Shared Storage using iSCSI. This set-up requires 2 Linux Servers running RHEL 6 (of course, same can be applied to similar Linux distributions). I am demonstrating this using 2 64 bit RHEL VMs running on Oracle Virtual Box. I will try to keep the language as simple as possible 😉
iSCSI simply means SCSI storage networking over TCP/IP. In simple words, we can attach a Storage Device (be it hard-disk, USB pen-drive, SSD or any similar block device) to a server and share that storage with the clients machines over TCP/IP. Below is how we are going to accomplish this.
iSCSI Target is a server to which storage is attached. Say, you have a 1TB disk & you want your client machines to access this over network. What we will do here is to create a partition (LUN – Logical Unit Number) on this disk & offer this partition or LUN as a shared, separate disk to client machine that can be formatted. You will need to set up your server as iSCSI Target. Follow these steps to configure it.
1. Install scsi-target-utils.x86_64 package.
2. Start tgtd service. Set it to start-at boot time.
service tgtd start && chkconfig tgtd on
3. Edit /etc/tgt/target.conf file & edit with below contents. Here we are sharing /dev/var_vg/raid2 LVM partition as LUN. This could be any valid partition. Note that you may substitute .com.server with your IP address in case you don’t have a working DNS.
4. Reload tgtd service by issuing command : –
service tgtd reload
5. Check LUN details by issuing : –
tgtadm --node target --op show
You can see below that our 105 MB raid2 partition has been configured as LUN. You might need to reboot your server to reflect the changes.
That’s all for server side configuration. Lets move to client side configuration 🙂
1. Install iscsi-utils.x86_64 package.
2. First, we will discover our Target by issuing command :-
iscsiadm -m discovery -t st -p 192.168.0.123
192.168.0.123 is IP of our Target. It will automatically start iscsid service. Copy the iqn part from output.
3. Now we will login to the Target. Issue this command : –
iscsiadm -m node -t iqn.1994-05.com.server:scsi -p 192.168.0.123 -l
This might be slightly overwhelming at first sight 😉 -m stands for mode, -t stands for target, -p stands for portal & -l stands for login. After -t, replace with the copied output (that you copied in step # 2).
4. Check if you are able to see a new disk (LUN) added by issuing : –
We can see we now have an additional disk /dev/sdb. In case you don’t see this new disk or LUN, reboot your server & repeat the steps.
You can now create a new mount-point & format that with any file-system of your choice.
Caveats : –
- Make sure iptables is off or apply suitable chains.
- Make sure your machines are able to ping each other. Make suitable changes to /etc/hosts file.
- You might need to reboot your machines to reflect the changes (already mentioned above).