Introduction iSCSI (Internet SCSI) technology developed by IBM Research, is a hardware device used by the upper layer of the IP protocol can run the SCSI instruction set, which can be implemented on the IP network to run the SCSI protocol, Allows routing to be routed on such high-speed Gigabit Ethernet. iSCSI technology is a new storage technology that combines existing SCSI interfaces with Ethernet (Ethernet) technology to enable servers to Exchange data with storage devices that use IP networks.
iSCSI is a TCP/IP-based protocol used to establish and manage inter-connectivity between IP storage devices, hosts, and clients, and to create a storage area network (SAN). SAN makes it possible for the SCSI protocol to be applied to high-speed data transmission networks, which are performed across multiple data storage networks at block level (block-level). The SCSI architecture is based on the C/S mode, and the typical application environment is that the devices are close to each other and the devices are connected by a SCSI bus.
The main functionality of ISCSI is the encapsulation and reliable transmission of large amounts of data between host systems (initiator initiator) and storage devices (target targets) on TCP/IP networks.
The topology of the complete iSCSI system is as follows:
iSCSI simply means that the SCSI instructions are encapsulated in the TCP/IP protocol and transmitted over Ethernet. ISCSI enables the transfer and operation of the SCSI protocol over an IP network, enabling it to perform data access on such high-speed Gigabit Ethernet networks, enabling data transmission and management. The Storage Area network (SAN) based on iSCSI has a good price/performance ratio compared to fiber-based Fc-san.
iSCSI is an end-to-end session-level protocol that defines a SCSI-to-TCP/IP mapping (e.g., initiator) that encapsulates SCSI instructions and data into iSCSI protocol data units, submits down to the TCP layer, and finally encapsulates IP packets over an IP network. When Target is reached, it is converted to SCSI instruction and data by unpacking, and then sent to the specified drive by the storage controller, which realizes the transparent transmission of SCSI command and data on IP network. It integrates the existing storage protocol SCSI and network protocol TCP/IP to achieve a seamless integration of storage and TCP/IP networks. In this article, the initiator initiator is called the client, which is called the target server to facilitate understanding.
Second, the Environment preparation
Operating system: CentOS release 6.5
ISCSI target:192.168.8.42/scsi-target-utils-1.0.24-12.el6_5.i686
ISCSI initiator:192.168.8.39/iscsi-initiator-utils-6.2.0.873-10.el6.i686
Firewall, SELinux is off
# Service Iptables Status
Iptables:firewall is not running.
# Getenforce
Disabled
III. installation configuration iSCSI target Server # yum Install-y scsi-target-utils
Add a piece of hard disk SDB and create a new two partition: SDB1, SDB2 analog SAN storage, two hard drives in initiator view
# fdisk / dev / sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe714b1f2.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w (rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk / dev / sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors / track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical / physical): 512 bytes / 512 bytes
I / O size (minimum / optimal): 512 bytes / 512 bytes
Disk identifier: 0xe714b1f2
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10443, default 1):
Using default value 1
Last cylinder, + cylinders or + size {K, M, G} (1-10443, default 10443): + 20G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (2613-10443, default 2613):
Using default value 2613
Last cylinder, + cylinders or + size {K, M, G} (2613-10443, default 10443): + 30G
Command (m for help): p
Disk / dev / sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors / track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical / physical): 512 bytes / 512 bytes
I / O size (minimum / optimal): 512 bytes / 512 bytes
Disk identifier: 0xe714b1f2
Device Boot Start End Blocks Id System
/ dev / sdb1 1 2612 20980858+ 83 Linux
/ dev / sdb2 2613 6529 31463302+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl () to re-read partition table.
Syncing disks.
Make the configuration effective
# partx -a / dev / sdb
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
# cat / proc / partitions
major minor #blocks name
8 0 125829120 sda
8 1 512000 sda1
8 2 125316096 sda2
8 16 83886080 sdb
8 17 20980858 sdb1
8 18 31463302 sdb2
253 0 4096000 dm-0
253 1 20480000 dm-1
253 2 25600000 dm-2
253 3 30720000 dm-3
Start the target service, through ss -tnl you can see that port 3260 has been opened
# service tgtd start
Fourth, the use of server-side configuration management tool tgtadm 1. Create a target id of 1 name for iqn.
# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2016-04.com.chinasoft.san: 1
2. Display all targets
# tgtadm -L iscsi -o show -m target
3. Add a new LUN to a device with ID 1 and its number is 1, and this device is provided to the initiator. / dev / sdb1 is the path of a "block device". This block device can also be a raid or lvm device. lun0 has been reserved by the system
# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 1 -b / dev / sdb1
4. Define a host-based access control list for a target. 192.168.8.0/24 indicates the list of initiator clients allowed to access this target:
Such as open to the host in the 192.168.8.0/24 network to access:
# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.8.0/24
Add a new LUN to the device with ID 1 again, number 2
# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 2 -b / dev / sdb2
# tgtadm -L iscsi -o show -m target
5. Remove the target's host-based access control list permission
# tgtadm -L iscsi -o unbind -m target -t 1 -I 192.168.8.0/24
# tgtadm -L iscsi -o show -m target
6. Delete the LUN in the target
# tgtadm -L iscsi -o delete -m target -t 1
# tgtadm -L iscsi -o show -m target
Fifth, the client initiator configures the use of the iscsiadm tool Install the iscsi-initiator-utils tool
# yum install -y iscsi-initiator-utils
# echo "InitiatorName =` iscsi-iname -p iqn.2016-04.com.chinasoft` "> /etc/iscsi/initiatorname.iscsi
# echo "InitiatorAlias = initiator1" >> /etc/iscsi/initiatorname.iscsi
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName = iqn.2016-04.com.chinasoft: 59b0936b38a3
InitiatorAlias = initiator1
# service iscsi start
# chkconfig iscsi on
# chkconfig --list iscsi
iscsi 0: off1: off 2: on3: on 4: on5: on 6: off
iscsiadm is a modeled tool. Its mode can be specified with the -m or --mode option. Common modes are discovery, node, fw, session, host, and iface. If no other options are specified, then discovery and node will Display all related records; session is used to display all active sessions and connections, fw displays all boot firmware values, host displays all iSCSI hosts, and iface displays all ifaces settings in the / var / lib / iscsi / ifaces directory .
iscsiadm -m discovery [-d debug_level] [-P printlevel] [-I iface -t type -p ip: port [-l]]
iscsiadm -m node [-d debug_level] [-P printlevel] [-L all, manual, automatic] [-U all, manual, automatic] [[-T tar-getname -p ip: port -I iface] [- l | -u | -R | -s]] [[-o operation]
-d, --debug = debug_level display debug information, level 0-8;
-l, --login
-t, --type = type The types that can be used here are sendtargets (which can be abbreviated as st), slp, fw, and isns. This option is only used in discovery mode, and currently only supports st, fw, and isns; where st means allowed Each iSCSI target sends a list of available targets to the initiator;
-p, --portal = ip [: port] specify the IP and port of the target service;
-m, --mode op Available modes are discovery, node, fw, host iface and session
-T, --targetname = targetname is used to specify the target name
-u, --logout
-o, --op = OPEARTION: specify the operation for the discoverydb database, which can only be one of new, delete, update, show, and nonpersistent;
-I, --interface = [iface]: Specify the iSCSI interface to perform the operation, these interfaces are defined in / var / lib / iscsi / ifaces;
Discover the device
# iscsiadm -m discovery -t st -p 192.168.8.42
Starting iscsid: [OK]
192.168.8.42:3260,1 iqn.2016-04.com.chinasoft.san: 1
# iscsiadm -m node -T iqn.2016-04.com.chinasoft.san: 1 -p 192.168.8.42 -l
Logging in to [iface: default, target: iqn.2016-04.com.chinasoft.san: 1, portal: 192.168.8.42,3260] (multiple)
Login to [iface: default, target: iqn.2016-04.com.chinasoft.san: 1, portal: 192.168.8.42,3260] successful.
Verify that you can see the server device
# fdisk -l / dev / sd [a-z]
Sdc partition device
# fdisk / dev / sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe3266877.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w (rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-20489, default 1):
Using default value 1
Last cylinder, + cylinders or + size {K, M, G} (1-20489, default 20489): + 3G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (3074-20489, default 3074):
Using default value 3074
Last cylinder, + cylinders or + size {K, M, G} (3074-20489, default 20489): + 2G
Command (m for help): w
The partition table has been altered!
Calling ioctl () to re-read partition table.
Syncing disks.
# partx -a / dev / sdc
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
# cat / proc / partitions
major minor #blocks name
8 0 125829120 sda
8 1 512000 sda1
8 2 125316096 sda2
8 16 83886080 sdb
253 0 30720000 dm-0
253 1 4096000 dm-1
253 2 25600000 dm-2
253 3 30720000 dm-3
253 4 10240000 dm-4
8 48 31463302 sdd
8 32 20980858 sdc
8 33 3146736 sdc1
8 34 2098176 sdc2
format
# mke2fs -t ext4 / dev / sdc1
Mount
# mount / dev / sdc1 / mnt
# cd / mnt
# ls
lost + found
# cp /etc/rc.d/rc.sysinit ./
# ls
lost + found rc.sysinit
# vim rc.sysinit
At this time, by viewing the target partition of the server, it has not changed
Close the iSCSI server
Turn off iSCSI to automatically reconnect the target when powering on or restarting the iscsi service, you need to delete the target entry information completely on the client:
Log out of the target session:
# iscsiadm -m node -T iqn.2016-04.com.chinasoft.san: 1 -p 192.168.8.42 -u
Logging out of session [sid: 1, target: iqn.2016-04.com.chinasoft.san: 1, portal: 192.168.8.42,3260]
Logout of [sid: 1, target: iqn.2016-04.com.chinasoft.san: 1, portal: 192.168.8.42,3260] successful.
Delete the record of the target entry:
# iscsiadm -m node -T iqn.2016-04.com.chinasoft.san: 1 -p 192.168.8.42 -o delete
After the client deletes the available target entry found by the previous discovery, it will not automatically reconnect after restarting or restarting the service.
# ls / var / lib / iscsi / send_targets /
192.168.8.42,3260
# ls / var / lib / iscsi /
ifaces isns nodes send_targets slp static
# rm -rf / var / lib / iscsi / *
# ls / var / lib / iscsi /
Six, define the target server by editing the file # cd / etc / tgt /
[# ls
targets.conf
[[email protected] tgt] # vim targets.conf
Add definition:
<target iqn.2016-04.com.chinasoft.san: 2>
backing-store / dev / sdb2
initiator-address 192.168.8.0/24
</ target>
# service tgtd restart
Stopping SCSI target daemon: [OK]
Starting SCSI target daemon: [OK]
# tgtadm -L iscsi -o show -m target
So far, the common configuration of the iscsi server target and client initiator tool has been explained
The centos 6.5 environment uses iscsi to build a SAN network storage service and server target and client initiator configuration details