Fedora 28
Sponsored Link

Configure iSCSI Target(tgt)2018/05/10

 
Configure Storage Server with iSCSI.
This is the example of configuring iSCSI Target with scsi-target-utils. (tgt)
A storage on a network is called iSCSI Target, a Client which connects to iSCSI Target is called iSCSI Initiator.
This example is based on the environment below.
+----------------------+          |          +----------------------+
| [   iSCSI Target   ] |10.0.0.30 | 10.0.0.31| [ iSCSI Initiator  ] |
|     dlp.srv.world    +----------+----------+    www.srv.world     |
|                      |                     |                      |
+----------------------+                     +----------------------+

[1] Install administration tools first.
[root@dlp ~]#
dnf -y install scsi-target-utils
[2] Configure iSCSI Target.
For example, create an disk-image under the [/var/lib/iscsi_disks] directory and set it as a SCSI device.
# create a disk image

[root@dlp ~]#
mkdir /var/lib/iscsi_disks

[root@dlp ~]#
dd if=/dev/zero of=/var/lib/iscsi_disks/disk01.img count=0 bs=1 seek=10G
[root@dlp ~]#
vi /etc/tgt/conf.d/target01.conf
# create new

# if you set some devices, add - and set the same way with follows

# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]

<target iqn.2018-05.world.srv:dlp.target01>
    # provided devicce as a iSCSI target
    backing-store /var/lib/iscsi_disks/disk01.img
    # iSCSI Initiator's IQN you allow to connect
    initiator-name iqn.2018-05.world.srv:www.initiator01
    # authentication info ( set anyone you like for "username", "password" )
    incominguser username password
</target> 
[3] If SELinux is enabled, change SELinux Context.
[root@dlp ~]#
dnf -y install policycoreutils-python-utils
[root@dlp ~]#
chcon -R -t tgtd_var_lib_t /var/lib/iscsi_disks

[root@dlp ~]#
semanage fcontext -a -t tgtd_var_lib_t /var/lib/iscsi_disks

[root@dlp ~]#
vi my-tgtd.te
# create new

module my-tgtd 1.0;

require {
        type tgtd_t;
        type var_run_t;
        class dir create;
}

#============= tgtd_t ==============
allow tgtd_t var_run_t:dir create;

[root@dlp ~]#
checkmodule -m -M -o my-tgtd.mod my-tgtd.te

[root@dlp ~]#
semodule_package --outfile my-tgtd.pp --module my-tgtd.mod

[root@dlp ~]#
semodule -i my-tgtd.pp

[4] If Firewalld is running, allow iSCSI Target service.
[root@dlp ~]#
firewall-cmd --add-service=iscsi-target --permanent

success
[root@dlp ~]#
firewall-cmd --reload

success
[5] Start tgtd and verify status.
[root@dlp ~]#
chmod 644 /usr/lib/systemd/system/tgtd.service

[root@dlp ~]#
systemctl start tgtd

[root@dlp ~]#
systemctl enable tgtd

# show status

[root@dlp ~]#
tgtadm --mode target --op show

Target 1: iqn.2018-05.world.srv:dlp.target01
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: rdwr
            Backing store path: /var/lib/iscsi_disks/disk01.img
            Backing store flags:
    Account information:
        username
    ACL information:
        ALL
        iqn.2018-05.world.srv:www.initiator01
Matched Content