Below are my notes for configuring a CentOS box to connect to an iSCSI target. This assumes you have already configured an iSCSI target on another machine / NAS. Much of this information comes thanks to this very helpful website.
Install the software package
|
1
|
yum -y install iscsi-initiator-utils |
Configure the iqn name for the initiator
|
1
|
vi /etc/iscsi/initiatorname.iscsi |
|
1
2
|
InitiatorName=iqn.2012-10.net.cpd:san.initiator01InitiatorAlias=initiator01 |
Edit the iSCSI initiator configuration
|
1
|
vi /etc/iscsi/iscsid.conf |
|
1
|
node.startup = automaticnode.session.auth.authmethod = CHAP
node.session.auth.username = initiator_usernode.session.auth.password = initiator_pass#The next two lines are for mutual CHAP authentication
node.session.auth.username_in = target_user
node.session.auth.password_in = target_password
|
Start iSCSI initiator daemon
|
1
2
|
/etc/init.d/iscsid start chkconfig --levels 235 iscsid on |
Discover targets in the iSCSI server:
|
1
2
|
iscsiadm --mode discovery -t sendtargets --portal 172.16.201.200 the portal's IP address172.16.201.200:3260,1 iqn.2012-10.net.cpd:san.target01 |
Try to log in with the iSCSI LUN:
|
1
2
3
|
iscsiadm --mode node --targetname iqn.2012-10.net.cpd:san.target01 --portal 172.16.201.200 --loginLogging in to [iface: default, target: iqn.2012-10.net.cpd:san.target01, portal: 172.16.201.200,3260] (multiple)Login to [iface: default, target: iqn.2012-10.net.cpd:san.target01, portal: 172.16.201.200,3260] successful. |
Verify configuration
This command shows what is put into the iSCSI targets database (the files located in /var/lib/iscsi/)
|
1
|
cat /var/lib/iscsi/send_targets/172.16.201.200,3260/st_config |
|
1
2
3
4
5
6
7
8
9
10
11
12
|
discovery.startup = manualdiscovery.type = sendtargetsdiscovery.sendtargets.address = 172.16.201.200discovery.sendtargets.port = 3260discovery.sendtargets.auth.authmethod = Nonediscovery.sendtargets.timeo.login_timeout = 15discovery.sendtargets.use_discoveryd = Nodiscovery.sendtargets.discoveryd_poll_inval = 30discovery.sendtargets.reopen_max = 5discovery.sendtargets.timeo.auth_timeout = 45discovery.sendtargets.timeo.active_timeout = 30discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768 |
Verify session is established
|
1
2
|
iscsiadm --mode session --op showtcp: [2] 172.16.201.200:3260,1 iqn.2012-10.net.cpd:san.target01 |
Create LVM volume and mount
Add our iSCSI disk to a new LVM physical volume, volume group, and logical volume
|
1
2
3
4
5
6
7
|
fdisk -lDisk /dev/sdb: 17.2 GB, 17171480576 bytes64 heads, 32 sectors/track, 16376 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000 |
|
1
|
Disk /dev/sdb doesn't contain a valid partition table |
|
1
2
|
pvcreate /dev/sdb
vgcreate iSCSI /dev/sdb
lvcreate iSCSI -n volume_name -l100%FREE
mkfs.ext4 /dev/iSCSI/volume_name |
Add the logical volume to fstab
Make sure to use the mount option _netdev. Without this option, Linux will try to mount this device before it loads network support.
|
1
|
vi /etc/fstab/dev/mapper/iSCSI-volume_name /mnt ext4 _netdev 0 0
|
Success.