iSCSI is a great way to attach enterprise class storage to your EC2 instances and it’s very easy to setup, even if you have zero storage management experience. The best part is that all of the steps are completed directly within your Linux instance itself.
- You’ll need some iSCSI storage within your VPC. This is really easy to deploy with ONTAP Cloud – grab yourself a free 30-day trial.
- An instance running in your VPC that you can SSH to.
Simply follow the steps below:
First, log into your instance via SSH/terminal (most use PuTTy for this).
Update your packages (Optional – but best practice):
sudo yum update -y
Next, we install iSCSI into our host:
sudo yum install iscsi-initiator-utils
We will now discover the iSCSi system (I’m using ONTAP in AWS, but you can use it in Azure, whitebox or on-prem). Simply replace 0.0.0.0 with your own IP address.
iscsiadm -m discovery -t st -p 0.0.0.0
Optional: Heres how to find your iSCSI IP address for ONTAP. SSH to your ONTAP management IP (18.104.22.168 in this example):
ssh email@example.com network interface show exit
Next, confirm that your host is seeing the iSCSI portal(s) correctly. they will be listed with the following command:
iscsiadm -m node
iSCSI requires your host to log in to the discovered portal, simply run the following command:
iscsiadm -m node --targetname "iqn.xxx.netapp:xxxxx" --portal "<ip-address:port>" --login
Optional but recommended: Restart the iSCSI service:
Now, make a note of the initiator name on your host – this will come in handy later:
The next few steps are for ONTAP users, if you are using other storage please refer to their reference manuals:
Login to your ONTAP system, create a volume and LUN:
ssh firstname.lastname@example.org volume create -volume <myvolname> -aggregate aggr1 -size 1024GB -space-guarantee none lun create -volume <myvolname> -lun <lunname> -ostype linux -space-reserve disabled -size 1024GB
iSCSI uses the concept of igroups in order to securely and logically share resources. We want our host iSCSI initiator to be part of a new igroup (for example I could create an igroup called mysql for all of my database instances). In this example my host initiator was iqn.1994-05.com.redhat:265535cef94:
igroup create -igroup mygroup -ostype linux igroup add -igroup <myigroup> -initiator iqn.1994-05.com.redhat:265535cef94 lun map -volume <myvolname> -lun <lunname> -igroup <myigroup>
That’s it – your Linux instance should now see all LUNS that are available to the igroup for which it is a member. You can view these LUNs with:
Now you have a LUN you’ll need to format it, partition it and mount it:
fdisk /dev/sdb mkfs.ext3 /dev/sdb1 mount /dev/sdb1 /mnt
You’ve ready to go!
If you happen to be running ONTAP, you can try instant cloning of your LUNs / databases /etc. Unlike AWS Snapshot clones, these are instant and have the full performance the minute they are created! Simply SSH into ONTAP and run:
volume clone create -parent-volume myvolume -flexclone myclonename
And just like that, you have created a clone of your data! Clones take up no additional space, are instantly available and can be mounted to any other (or the source) instance, great for speeding up development and saving money at the same time!