配置服务器的iSCSI和发起者端的配置

来源:互联网 发布:地图数据采集是什么 编辑:程序博客网 时间:2024/05/16 02:45

Presentation(centos7测试通过)

In the iSCSI world, you’ve got two types of agents:

  • an iSCSI target provides some storage (here called server),
  • an iSCSI initiator uses this available storage (here called client).

As you already guessed, we are going to use two virtual machines, respectively calledserver andclient. If necessary, the server andclient virtual machines can be one and only one machine.

iSCSI target configuration

Most of the target configuration is done interactively through thetargetcli command. This command uses a directory tree to access the different objects.

To create an iSCSI target, you need to follow several steps on theserver virtual machine.

Install the following packages:

# yum install -y targetcli

Activate the target service at boot:

# systemctl enable target

Note: This is mandatory, otherwise your configuration won’t be read after a reboot!

Execute the targetcli command:

# targetcliWarning: Could not load preferences file /root/.targetcli/prefs.bin.targetcli shell version 2.1.fb34Copyright 2011-2013 by Datera, Inc and others.For help on commands, type 'help'./>

You’ve got two options:

  • You can create a fileio backstore called shareddata of100MB in the/opt directory (don’t hesitate to use tab completion):
    /> backstores/fileio/ create shareddata /opt/shareddata.img 100MCreated fileio shareddata with size 104857600

    Note: If you don’t specify write_back=false at the end of the previous command, it is assumedwrite_back=true. Thewrite_back option set to true enables the local file system cache. This improves performance but increases the risk of data loss. In production environments, it is recommended to usewrite_back=false.

  • You can create a block backstore that usually provides the best performance. You can use a block device like/dev/sdb or a logical volume previously created (#lvcreate –name lv_iscsi –size 100M vg):
    /> backstores/block/ create block1 /dev/vg/lv_iscsiCreated block storage object block1 using /dev/vg/lv_iscsi.

Then, create an IQN (Iscsi Qualified Name) callediqn.2014-08.com.example with a target namedt1 and get an associatedTPG (TargetPortal Group):

/> iscsi/ create iqn.2014-08.com.example:t1Created target iqn.2014-08.com.example:t1.Created TPG 1.Global pref auto_add_default_portal=trueCreated default portal listening on all IPs (0.0.0.0), port 3260.

Note: The IQN follows the convention of the RFC 3270 (see http://en.wikipedia.org/wiki/ISCSI to get more details).

Now, we can go to the newly created directory:

/> cd iscsi/iqn.2014-08.com.example:t1/tpg1/iscsi/iqn.20...ample:t1/tpg1> lso- tpg1 ................................................. [no-gen-acls, no-auth]  o- acls ............................................................ [ACLs: 0]  o- luns ............................................................ [LUNs: 0]  o- portals ...................................................... [Portals: 1]    o- 0.0.0.0:3260 ....................................................... [OK]

Below tpg1, three objects have been defined:

  • acls (access control lists: restrict access to resources),
  • luns (logical unit number: define exported resources),
  • portals (define ways to reach the exported resources; consist in pairs of IP addresses and ports).

If you use a version pre-RHEL 7.1 (this step is now automatically done by theiscsi/ create command), you need to create aportal (a pair of IP address and port through which the target can be contacted by initiators):

/iscsi/iqn.20...ple:t1/tpg1> portals/ createUsing default IP port 3260Binding to INADDR_ANY (0.0.0.0)Created network portal 0.0.0.0:3260.

Whatever version, create a lun depending on the kind of backstore you previously chose:

  • Fileio backstore:
    /iscsi/iqn.20...ample:t1/tpg1> luns/ create /backstores/fileio/shareddata Created LUN 0.
  • Block backstore:
    /iscsi/iqn.20...ample:t1/tpg1> luns/ create /backstores/block/block1 Created LUN 0.

Create an acl with the previously created IQN (hereiqn.2014-08.com.example) and an identifier you choose (hereclient), together creating the future initiator name:

/iscsi/iqn.20...ample:t1/tpg1> acls/ create iqn.2014-08.com.example:clientCreated Node ACL for iqn.2014-08.com.example:clientCreated mapped LUN 0

Optionally, set a userid and a password:

/iscsi/iqn.20...ample:t1/tpg1> cd acls/iqn.2014-08.com.example:client//iscsi/iqn.20...xample:client> set auth userid=usrParameter userid is now 'usr'./iscsi/iqn.20...xample:client> set auth password=pwdParameter password is now 'pwd'.

Now, to check the configuration, type:

/iscsi/iqn.20...om.example:d1> cd ../../iscsi/iqn.20...ple:tgt1/tpg1> lso- tpg1 ................................................. [no-gen-acls, no-auth]  o- acls ............................................................ [ACLs: 1]  | o- iqn.2014-08.com.example:client ......................... [Mapped LUNs: 1]  |   o- mapped_lun0 ............................. [lun0 fileio/shareddata (rw)]  o- luns ............................................................ [LUNs: 1]  | o- lun0 .......................... [fileio/shareddata (/opt/shareddata.img)]  o- portals ...................................................... [Portals: 1]    o- 0.0.0.0:3260 ....................................................... [OK]

Finally, you can quit the targetcli command:

/iscsi/iqn.20...ple:tgt1/tpg1> exitGlobal pref auto_save_on_exit=trueLast 10 configs saved in /etc/target/backup.Configuration saved to /etc/target/saveconfig.json

Note: The configuration is automatically saved to the /etc/target/saveconfig.json file.

Also, it can be useful to check the ports currently used:

# netstat -antActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address           Foreign Address         Statetcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTENtcp        0      0 0.0.0.0:3260            0.0.0.0:*               LISTENtcp        0      0 192.168.1.81:22         192.168.1.81:33584      ESTABLISHEDtcp6       0      0 :::22                   :::*                    LISTENtcp6       0      0 ::1:25                  :::*                    LISTEN

Finally, open the 3260 tcp port in the firewall configuration:

# firewall-cmd --permanent --add-port=3260/tcpSuccess

Reload the firewall configuration:

# firewall-cmd --reloadSuccess

iSCSI initiator configuration

To create an iSCSI initiator, you need to follow several steps on theclientvirtual machine.

Install the following package:

# yum install -y iscsi-initiator-utils

Edit the /etc/iscsi/initiatorname.iscsi and replace the content with the initiator name that you previously configured as acl on the target side:

InitiatorName=iqn.2014-08.com.example:client

If you previously set up a userid and a password on theserver, edit the/etc/iscsi/iscsid.conf file and paste the following lines:

node.session.auth.authmethod = CHAPnode.session.auth.username = usrnode.session.auth.password = pwd

Start the iscsi service:

# systemctl start iscsi

Caution: This action is mandatory to be able to unmount the remote resource when rebooting. Don’t confuseiscsid andiscsi services!

Execute the iscsiadm command in discovery mode with theserver ip address (here192.168.1.81):

# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.81192.168.1.81:3260,1 iqn.2014-08.com.example:t1

Note: If you don’t specify any port, the default port is 3260.

Execute the iscsiadm command in node mode with theserver ip address (here192.168.1.81):

# iscsiadm --mode node --targetname iqn.2014-08.com.example:t1 --portal 192.168.1.81 --loginLogging in to [iface: default, target: iqn.2014-08.com.example:t1, portal: 192.168.1.81,3260] (multiple)Login to [iface: default, target: iqn.2014-08.com.example:t1, portal: 192.168.1.81,3260] successful.

Note: As before, if you don’t specify any port, the default port is 3260.

To check the configuration, type:

# lsblk --scsiNAME HCTL       TYPE VENDOR   MODEL             REV TRANsda  2:0:0:0    disk LIO-ORG  shareddata       4.0  iscsi

To be sure that your resource is not in read-only mode (1=read-only mode), type:

# lsblk | egrep "NAME|sda"NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsda                  8:0    0  100M  0 disk

Now, you can create a file system:

# mkfs.ext4 /dev/sdamke2fs 1.42.9 (28-Dec-2013)/dev/sda is entire device, not just one partition!Proceed anyway? (y,n) yFilesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=0 blocks, Stripe width=4096 blocks25688 inodes, 102400 blocks5120 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=3368550413 block groups8192 blocks per group, 8192 fragments per group1976 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729Allocating group tables: doneWriting inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: done

Retrieve the UUID of this disk:

# blkid | grep "/dev/sda"/dev/sda: UUID="4a184c70-20ad-4d91-a0b1-c2cf0eb1986f" TYPE="ext4"

Add the disk UUID to the /etc/fstab file:

# echo "UUID=..." >> /etc/fstab

Note: Be very careful to type >> and not >, otherwise this will destroy all your configuration!
Make a copy of the /etc/fstab file before doing this operation if you don’t want to take any risk.

Edit the /etc/fstab file and add the mount point (here /mnt), the file system type (here ext4) and the mount options (_netdev):

UUID=... /mnt ext4 _netdev 0 0

Note: The _netdev mount option is mandatory to postpone the mount operation after the network initialization. If you don’t do it, the initiator boot process will be stopped after a timeout in maintenance mode.

To check your configuration, type:

# mount /mnt# touch /mnt/testFile

Optionally, you can dump all the initiator configuration (3=max output,0=min output):

# iscsiadm -m session -P 3iSCSI Transport Class version 2.0-870version 6.2.0.873-28Target: iqn.2014-08.com.example:t1 (non-flash)Current Portal: 192.168.1.81:3260,1Persistent Portal: 192.168.1.81:3260,1**********Interface:**********Iface Name: defaultIface Transport: tcpIface Initiatorname: iqn.2014-08.com.example:clientIface IPaddress: 192.168.1.10Iface HWaddress: Iface Netdev: SID: 1iSCSI Connection State: LOGGED INiSCSI Session State: LOGGED_INInternal iscsid Session State: NO CHANGE*********Timeouts:*********Recovery Timeout: 120Target Reset Timeout: 30LUN Reset Timeout: 30Abort Timeout: 15*****CHAP:*****username: usrpassword: ********username_in: password_in: ********************************Negotiated iSCSI params:************************HeaderDigest: NoneDataDigest: NoneMaxRecvDataSegmentLength: 262144MaxXmitDataSegmentLength: 262144FirstBurstLength: 65536MaxBurstLength: 262144ImmediateData: YesInitialR2T: YesMaxOutstandingR2T: 1************************Attached SCSI devices:************************Host Number: 2State: runningscsi2 Channel 00 Id 0 Lun: 0Attached scsi disk sdaState: running

Source: targetcli man page and Linux-iSCSI wiki.

Some advices

Before rebooting, set up  a virtual console, this can be helpful!

If you need to shut down target and initiator, shut down the initiator first. If you shut down the target first, the initiator won’t be able to unmount the remote resource and will be stuck in the shutdown process.

During the exam, as an extra precaution, unmount the remote resource before rebooting the initiator, you will avoid any bad surprise.

Additional resources

In addition, you can watch CalPOP’s video Creating iSCSI SAN Storage on Linux (CentOS 7.0) (10min/2015),Venkat Nagappan’s video Setting up iSCSI Target & Initiator (19min/2015) or follow thisIBM iScsi tutorial.

Check your knowledge

Test yourself!

0 0