1 | <<How to setup an iSCSI target using tgtadm>>
2 | 3 | 1.Start the tgtd service
4 | #service tgtd start
5 | The tgtd service is provided by the package: scsi-target-utils.x86_64
6 | 7 | 2.Define an iSCSI target name: (for example)
8 | # tgtadm --lld iscsi --op new --mode target --tid=1 --targetname iqn.2001-04.com.example:storage.disk1.amiens.sys1.xyz
9 | 10 | 3.To view the currect configuration:
11 | # tgtadm --lld iscsi --op show --mode target
12 | 13 | For example, here we create a 10G file as the block device:
14 | # dd if=/dev/zero of=/disk1 bs=1M count=10240
15 | 16 | 4.Add it as a logical unit to the target:
17 | # tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /disk1
18 | 19 | 5.Enable the target to accept any initiators:
20 | # tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
21 | 22 | 6.View the current configuration again:
23 | # tgtadm --lld iscsi --op show --mode target
24 | Target 1: iqn.2001-04.com.example:storage.disk1.amiens.sys1.xyz
25 | System information:
26 | Driver: iscsi
27 | Status: running
28 | I_T nexus information:
29 | LUN information:
30 | LUN: 0
31 | Type: controller
32 | SCSI ID: deadbeaf1:0
33 | SCSI SN: beaf10
34 | Size: 0
35 | Backing store: No backing store
36 | LUN: 1
37 | Type: disk
38 | SCSI ID: deadbeaf1:1
39 | SCSI SN: beaf11
40 | Size: 55G
41 | Backing store: /disk1
42 | Account information:
43 | ACL information:
44 | ALL
45 | 46 | 7.Ensure TCP port 3260 can be accessed from remote host.
47 | 48 | 8.Start from Red Hat Enterprise Linux 5.3, tgt-admin and /etc/tgt/targets.conf can be used for make the setup persistent over reboot:
49 | # tgt-admin --dump > /etc/tgt/targets.conf
50 | # chkconfig tgtd on
51 | 52 | 9.In releases prior to Red Hat Enterprise Linux 5.3, you have to put the "tgtadm" commands into /etc/rc.local and enable the tgtd service:
53 | 54 | echo >> /etc/rc.local <<EOF
55 | tgtadm --lld iscsi --op new --mode target --tid=1 --targetname iqn.2001-04.com.example:storage.disk1.amiens.sys1.xyz
56 | tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /disk1
57 | tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
58 | EOF
59 | 60 | # chkconfig tgtd on
61 | 62 | 63 | <<How to configure the iscsi-initiator>>
64 | 65 | 1.First install the iscsi-initiator-utils package
66 | 67 | #yum install iscsi-initiator-utils
68 | 69 | 2.Second start the iscsid service and enable it to start when the system boots:
70 | 71 | #service iscsid start
72 | #chkconfig iscsid on
73 | 74 | 3.Then obtain a listing of available targets from a given host (please note that ipaddress listed below must be replaced with the resolvable hostname or ip address of the system providing the port if different than default):
75 | 76 | #iscsiadm -m discovery -t sendtargets -p ipaddress
77 | 78 | 4.Finally, use the following command to login to the available target (again, replace targetname with one from the output of the previous command and replace ipaddress below with that of the target system):
79 | 80 | #iscsiadm -m node -T targetname -p ipaddress -l
81 | 82 |
83 | 84 | This will enable the target to be accessed upon reboots and it stores it in a node database found in /var/lib/iscsi that is more thoroughly described in the /usr/share/doc/iscsi-initiator-utils-VERSION/README file.
85 | 86 | For a more verbose listing of possible options for the iscsiadm command in Red Hat Enterprise Linux 5 refer to the manual page using:
87 | 88 | #man iscsiadm