Setting up a iSCSI target, Red Hat style:
First you need to install the necessary packages:
yum install scsi-target-utils -yStart the target daemon and set it to start on boot:
service tgtd start; chkconfig tgtd onYou can now add a target, using the tgtadm command. Oddly enough, the help command is actually extremely helpful, in that it essentially gives you examples rather than a list of what each flag does. Not that there is anything wrong with a list of what each flag does, but sometimes more examples would not go amiss, anyway, create the target with:
tgtadm --lld iscsi --mode target --op new --tid=1 --targetname iqn.3141.15.domain.com:testYou then need to add a LUN to this target and tell it what storage it should use:
tgtadm --lld iscsi --mode logicalunit --op new --tid=1 --lun=1 --backing-store=/dev/sdbAll that remains is to enable the target to accept initiators:
tgtadm --lld iscsi --mode target --op bind --tid=1 --initiator-address=ALLYou can check port 3260 with (thanks to this daniel miessler for this post):
lsof -i:3260If you don't see any output then something has gone wrong. You can list the targets with this command:
tgtadm --lld iscsi --op show --mode targetMake sure that you open port 3260 on your firewall and save it:
iptables -I INPUT -p tcp --dport 3260 -j ACCEPT; service iptables saveThat should be it, you now have an iSCSI target ready to be mounted. Note that this will allow anybody to mount your target, so it is really only good as a internal test.
Configure a system as an iSCSI initiator that persistently mounts an iSCSI target
This is the actual objective. You need to install the relevant packages first:
yum groupinstall 'iSCSI Storage Client'Strangely, this group seems to consist solely of iscsi-initiator-utils. Anyway, start the iscsi service and set it to start on boot:
/etc/init.d/iscsi start; chkconfig iscsi onYou can now look for targets with this, where 10.168.20.233 is the ip address of the server hosting the iSCSI targets:
iscsiadm -m discovery -t sendtargets -p 10.168.20.233Restart the iscsi service:
service iscsi restartCheck that you see the new device with:
fdisk -lYou can now use the new disk to create partition(s) and file systems for those partition(s) and mount it (them).
A note of caution, as this is a network device, you need to make sure that you specify it in the fstab options, otherwise your system will refuse to boot up, something like this is needed
UUID=54e1bd41-68d0-4804-94f8-1b255e53a88d /iscsi ext4 _netdev 0 0
If your /dev/sdb is physical disk, better to use "direct-store" instead of "backing-store".
ReplyDelete@Anonymous
ReplyDeleteI'm using a virtual machine so I guess it really doesn't matter, but thanks for pointing this out, I was not aware of it.
backing-store - defines a virtual device on the target.
direct-store - defines a direct mapped device with the same properties as the physical device (such as VENDOR_ID, SERIAL_NUM, etc.)
I don't want to post this on too many sites, so I will stop here. I run "iscsiadm -m discovery -t sendtargets -p 10.168.20.233" and "service iscsi restart". The result is an sg device such as /dev/sg2. It is not what I need, which is /dev/sdb or similar. Any idea? Thanks.
ReplyDelete@Sam
ReplyDeleteThe drive names are due to naming conventions, see this Naming Conventions
What are you trying to do that requires an "sd" drive?