| 1 | == iSCSI Storage on CentOS 5.5 == |
| 2 | |
| 3 | There are two virtual machines running the CentOS 5.5 operating system: |
| 4 | |
| 5 | ip=192.168.228.152 hostname=el5-32 -- iSCSI server (target) |
| 6 | |
| 7 | ip=192.168.228.153 hostname=el5-32-2 -- iSCSI client (initiator) |
| 8 | |
| 9 | === Configure iSCSI server (target) === |
| 10 | |
| 11 | {{{ |
| 12 | # uname -nr |
| 13 | el5-32 2.6.18-194.32.1.el5 |
| 14 | # ifconfig eth0 | grep 'inet addr' |
| 15 | inet addr:192.168.228.152 Bcast:192.168.228.255 Mask:255.255.255.0 |
| 16 | # |
| 17 | # rpm -q scsi-target-utils |
| 18 | scsi-target-utils-0.0-6.20091205snap.el5_5.3 |
| 19 | # |
| 20 | }}} |
| 21 | |
| 22 | * Start the SCSI target daemon. |
| 23 | |
| 24 | {{{ |
| 25 | # service tgtd start |
| 26 | Starting SCSI target daemon: Starting target framework daemon |
| 27 | |
| 28 | # service tgtd status |
| 29 | tgtd (pid 2697 2696) is running... |
| 30 | # chkconfig tgtd on |
| 31 | # chkconfig --list tgtd |
| 32 | tgtd 0:off 1:off 2:on 3:on 4:on 5:on 6:off |
| 33 | # |
| 34 | }}} |
| 35 | |
| 36 | * Create target device, then check current configuration. |
| 37 | |
| 38 | In the following example {{{02130152}}} is a substitute for a random hexadecimal number, where {{{0213}}} represents current date (MMDD), {{{0}}} - just a zero, and {{{152}}} is the fourth octet in server's IP address. |
| 39 | |
| 40 | {{{ |
| 41 | # tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2001-04.com.stgt:`uname -n`-02130152 |
| 42 | # |
| 43 | # tgtadm --lld iscsi --op show --mode target |
| 44 | Target 1: iqn.2001-04.com.stgt:el5-32-02130152 |
| 45 | System information: |
| 46 | Driver: iscsi |
| 47 | State: ready |
| 48 | I_T nexus information: |
| 49 | LUN information: |
| 50 | LUN: 0 |
| 51 | Type: controller |
| 52 | SCSI ID: IET 00010000 |
| 53 | SCSI SN: beaf10 |
| 54 | Size: 0 MB |
| 55 | Online: Yes |
| 56 | Removable media: No |
| 57 | Backing store type: rdwr |
| 58 | Backing store path: None |
| 59 | Account information: |
| 60 | ACL information: |
| 61 | # |
| 62 | }}} |
| 63 | |
| 64 | * Add logical unit to the target, enable it to accept initiators from the local network. |
| 65 | |
| 66 | {{{ |
| 67 | # fdisk -l /dev/sdb |
| 68 | |
| 69 | Disk /dev/sdb: 8589 MB, 8589934592 bytes |
| 70 | 255 heads, 63 sectors/track, 1044 cylinders |
| 71 | Units = cylinders of 16065 * 512 = 8225280 bytes |
| 72 | |
| 73 | Device Boot Start End Blocks Id System |
| 74 | /dev/sdb1 1 1044 8385898+ 83 Linux |
| 75 | # |
| 76 | # mount |grep sdb |
| 77 | # |
| 78 | # |
| 79 | # tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1 |
| 80 | # |
| 81 | # tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.228.0/24 |
| 82 | # |
| 83 | # tgtadm --lld iscsi --op show --mode target |
| 84 | Target 1: iqn.2001-04.com.stgt:el5-32-02130152 |
| 85 | System information: |
| 86 | Driver: iscsi |
| 87 | State: ready |
| 88 | I_T nexus information: |
| 89 | LUN information: |
| 90 | LUN: 0 |
| 91 | Type: controller |
| 92 | SCSI ID: IET 00010000 |
| 93 | SCSI SN: beaf10 |
| 94 | Size: 0 MB |
| 95 | Online: Yes |
| 96 | Removable media: No |
| 97 | Backing store type: rdwr |
| 98 | Backing store path: None |
| 99 | LUN: 1 |
| 100 | Type: disk |
| 101 | SCSI ID: IET 00010001 |
| 102 | SCSI SN: beaf11 |
| 103 | Size: 8587 MB |
| 104 | Online: Yes |
| 105 | Removable media: No |
| 106 | Backing store type: rdwr |
| 107 | Backing store path: /dev/sdb1 |
| 108 | Account information: |
| 109 | ACL information: |
| 110 | 192.168.228.0/24 |
| 111 | # |
| 112 | }}} |
| 113 | |
| 114 | * Save current configuration. |
| 115 | |
| 116 | {{{ |
| 117 | # tgt-admin --dump >/etc/tgt/targets.conf |
| 118 | # |
| 119 | # cat /etc/tgt/targets.conf |
| 120 | default-driver iscsi |
| 121 | |
| 122 | <target iqn.2001-04.com.stgt:el5-32-02130152> |
| 123 | backing-store /dev/sdb1 |
| 124 | initiator-address 192.168.228.0/24 |
| 125 | </target> |
| 126 | |
| 127 | # |
| 128 | }}} |
| 129 | |
| 130 | === Configure iSCSI client (initiator) === |
| 131 | |
| 132 | {{{ |
| 133 | # uname -nr |
| 134 | el5-32-2 2.6.18-194.32.1.el5 |
| 135 | # ifconfig eth0 | grep 'inet addr' |
| 136 | inet addr:192.168.228.153 Bcast:192.168.228.255 Mask:255.255.255.0 |
| 137 | # |
| 138 | # rpm -q iscsi-initiator-utils |
| 139 | iscsi-initiator-utils-6.2.0.871-0.20.el5_5 |
| 140 | # |
| 141 | # cat /etc/iscsi/initiatorname.iscsi |
| 142 | InitiatorName=iqn.1994-05.com.redhat:d91b4739849 |
| 143 | # |
| 144 | # service iscsi status |
| 145 | iscsid (pid 1391) is running... |
| 146 | # chkconfig --list iscsi |
| 147 | iscsi 0:off 1:off 2:off 3:on 4:on 5:on 6:off |
| 148 | # |
| 149 | }}} |
| 150 | |
| 151 | * Query the storage server for available targets. |
| 152 | |
| 153 | {{{ |
| 154 | # iscsiadm --mode discovery --type sendtargets --portal 192.168.228.152 |
| 155 | 192.168.228.152:3260,1 iqn.2001-04.com.stgt:el5-32-02130152 |
| 156 | # |
| 157 | }}} |
| 158 | |
| 159 | * Acquire the target. |
| 160 | |
| 161 | {{{ |
| 162 | # iscsiadm --mode node --targetname iqn.2001-04.com.stgt:el5-32-02130152 --portal 192.168.228.152:3260 --login |
| 163 | Logging in to [iface: default, target: iqn.2001-04.com.stgt:el5-32-02130152, portal: 192.168.228.152,3260] |
| 164 | Login to [iface: default, target: iqn.2001-04.com.stgt:el5-32-02130152, portal: 192.168.228.152,3260]: successful |
| 165 | # |
| 166 | # grep "`date '+%b %e %H'`" /var/log/messages |
| 167 | Feb 13 22:24:06 el5-32-2 kernel: scsi1 : iSCSI Initiator over TCP/IP |
| 168 | Feb 13 22:24:07 el5-32-2 kernel: Vendor: IET Model: Controller Rev: 0001 |
| 169 | Feb 13 22:24:07 el5-32-2 kernel: Type: RAID ANSI SCSI revision: 05 |
| 170 | Feb 13 22:24:07 el5-32-2 kernel: scsi 1:0:0:0: Attached scsi generic sg1 type 12 |
| 171 | Feb 13 22:24:07 el5-32-2 kernel: Vendor: IET Model: VIRTUAL-DISK Rev: 0001 |
| 172 | Feb 13 22:24:07 el5-32-2 kernel: Type: Direct-Access ANSI SCSI revision: 05 |
| 173 | Feb 13 22:24:07 el5-32-2 kernel: SCSI device sdb: 16771797 512-byte hdwr sectors (8587 MB) |
| 174 | Feb 13 22:24:07 el5-32-2 kernel: sdb: Write Protect is off |
| 175 | Feb 13 22:24:07 el5-32-2 kernel: SCSI device sdb: drive cache: write back |
| 176 | Feb 13 22:24:07 el5-32-2 kernel: SCSI device sdb: 16771797 512-byte hdwr sectors (8587 MB) |
| 177 | Feb 13 22:24:07 el5-32-2 kernel: sdb: Write Protect is off |
| 178 | Feb 13 22:24:07 el5-32-2 kernel: SCSI device sdb: drive cache: write back |
| 179 | Feb 13 22:24:07 el5-32-2 kernel: sdb: unknown partition table |
| 180 | Feb 13 22:24:07 el5-32-2 kernel: sd 1:0:0:1: Attached scsi disk sdb |
| 181 | Feb 13 22:24:07 el5-32-2 kernel: sd 1:0:0:1: Attached scsi generic sg2 type 0 |
| 182 | Feb 13 22:24:07 el5-32-2 iscsid: connection1:0 is operational now |
| 183 | # |
| 184 | # iscsiadm --mode node --targetname iqn.2001-04.com.stgt:el5-32-02130152 --portal 192.168.228.152:3260 --op update -n node.startup -v automatic |
| 185 | # |
| 186 | }}} |
| 187 | |
| 188 | * Check client status. |
| 189 | |
| 190 | {{{ |
| 191 | # iscsiadm -m session |
| 192 | tcp: [1] 192.168.228.152:3260,1 iqn.2001-04.com.stgt:el5-32-02130152 |
| 193 | # |
| 194 | # iscsiadm -m session -P 1 |
| 195 | Target: iqn.2001-04.com.stgt:el5-32-02130152 |
| 196 | Current Portal: 192.168.228.152:3260,1 |
| 197 | Persistent Portal: 192.168.228.152:3260,1 |
| 198 | ********** |
| 199 | Interface: |
| 200 | ********** |
| 201 | Iface Name: default |
| 202 | Iface Transport: tcp |
| 203 | Iface Initiatorname: iqn.1994-05.com.redhat:d91b4739849 |
| 204 | Iface IPaddress: 192.168.228.153 |
| 205 | Iface HWaddress: <empty> |
| 206 | Iface Netdev: <empty> |
| 207 | SID: 1 |
| 208 | iSCSI Connection State: LOGGED IN |
| 209 | iSCSI Session State: LOGGED_IN |
| 210 | Internal iscsid Session State: NO CHANGE |
| 211 | # |
| 212 | }}} |
| 213 | |
| 214 | * Create new storage partition. Notice that disk geometry is different from that reported on the server (above). |
| 215 | |
| 216 | {{{ |
| 217 | # fdisk /dev/sdb |
| 218 | [...] |
| 219 | # fdisk -l /dev/sdb |
| 220 | |
| 221 | Disk /dev/sdb: 8587 MB, 8587160064 bytes |
| 222 | 64 heads, 32 sectors/track, 8189 cylinders |
| 223 | Units = cylinders of 2048 * 512 = 1048576 bytes |
| 224 | |
| 225 | Device Boot Start End Blocks Id System |
| 226 | /dev/sdb1 1 8189 8385520 83 Linux |
| 227 | # |
| 228 | }}} |
| 229 | |
| 230 | * Create new file system. |
| 231 | |
| 232 | {{{ |
| 233 | # mkfs -t ext3 /dev/sdb1 |
| 234 | mke2fs 1.39 (29-May-2006) |
| 235 | Filesystem label= |
| 236 | OS type: Linux |
| 237 | Block size=4096 (log=2) |
| 238 | Fragment size=4096 (log=2) |
| 239 | 1048576 inodes, 2096380 blocks |
| 240 | 104819 blocks (5.00%) reserved for the super user |
| 241 | First data block=0 |
| 242 | Maximum filesystem blocks=2147483648 |
| 243 | 64 block groups |
| 244 | 32768 blocks per group, 32768 fragments per group |
| 245 | 16384 inodes per group |
| 246 | Superblock backups stored on blocks: |
| 247 | 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 |
| 248 | |
| 249 | Writing inode tables: done |
| 250 | Creating journal (32768 blocks): done |
| 251 | Writing superblocks and filesystem accounting information: done |
| 252 | |
| 253 | This filesystem will be automatically checked every 24 mounts or |
| 254 | 180 days, whichever comes first. Use tune2fs -c or -i to override. |
| 255 | # |
| 256 | }}} |
| 257 | |
| 258 | * Configure new mount point, mount the file system. |
| 259 | |
| 260 | {{{ |
| 261 | # vi /etc/fstab |
| 262 | # tail -1 /etc/fstab |
| 263 | /dev/sdb1 /mnt ext3 _netdev,defaults 1 2 |
| 264 | # |
| 265 | # chkconfig netfs on |
| 266 | # chkconfig --list netfs |
| 267 | netfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off |
| 268 | # |
| 269 | # service netfs start |
| 270 | No devices found |
| 271 | Setting up Logical Volume Management: [ OK ] |
| 272 | Checking network-attached filesystems |
| 273 | /dev/sdb1: clean, 12/1048576 files, 70322/2096380 blocks |
| 274 | [ OK ] |
| 275 | Mounting other filesystems: [ OK ] |
| 276 | # |
| 277 | # |
| 278 | # mount |grep sdb |
| 279 | /dev/sdb1 on /mnt type ext3 (rw,_netdev) |
| 280 | # |
| 281 | # df -h /dev/sdb1 |
| 282 | Filesystem Size Used Avail Use% Mounted on |
| 283 | /dev/sdb1 7.9G 147M 7.4G 2% /mnt |
| 284 | # |
| 285 | }}} |
| 286 | |
| 287 | === iSCSI server status === |
| 288 | |
| 289 | {{{ |
| 290 | # tgtadm --lld iscsi --op show --mode target |
| 291 | Target 1: iqn.2001-04.com.stgt:el5-32-02130152 |
| 292 | System information: |
| 293 | Driver: iscsi |
| 294 | State: ready |
| 295 | I_T nexus information: |
| 296 | I_T nexus: 1 |
| 297 | Initiator: iqn.1994-05.com.redhat:d91b4739849 |
| 298 | Connection: 0 |
| 299 | IP Address: 192.168.228.153 |
| 300 | LUN information: |
| 301 | LUN: 0 |
| 302 | Type: controller |
| 303 | SCSI ID: IET 00010000 |
| 304 | SCSI SN: beaf10 |
| 305 | Size: 0 MB |
| 306 | Online: Yes |
| 307 | Removable media: No |
| 308 | Backing store type: rdwr |
| 309 | Backing store path: None |
| 310 | LUN: 1 |
| 311 | Type: disk |
| 312 | SCSI ID: IET 00010001 |
| 313 | SCSI SN: beaf11 |
| 314 | Size: 8587 MB |
| 315 | Online: Yes |
| 316 | Removable media: No |
| 317 | Backing store type: rdwr |
| 318 | Backing store path: /dev/sdb1 |
| 319 | Account information: |
| 320 | ACL information: |
| 321 | 192.168.228.0/24 |
| 322 | # |
| 323 | # |
| 324 | }}} |
| 325 | |
| 326 | === See Also === |
| 327 | |
| 328 | file:///usr/share/doc/scsi-target-utils-0.0/README.iscsi |
| 329 | |
| 330 | file:///usr/share/doc/scsi-target-utils-0.0/README.lu_configuration |
| 331 | |
| 332 | |