Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 8. Configuring an iSCSI target
			Red Hat Enterprise Linux uses the targetcli shell as a command-line interface to perform the following operations:
		
- Add, remove, view, and monitor iSCSI storage interconnects to utilize iSCSI hardware.
- Export local storage resources that are backed by either files, volumes, local SCSI devices, or by RAM disks to remote systems.
			The targetcli tool has a tree-based layout including built-in tab completion, auto-complete support, and inline documentation.
		
8.1. Installing targetcli
				Install the targetcli tool to add, monitor, and remove iSCSI storage interconnects .
			
Procedure
- Install the - targetclitool:- yum install targetcli - # yum install targetcli- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Start the target service: - systemctl start target - # systemctl start target- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Configure target to start at boot time: - systemctl enable target - # systemctl enable target- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Open port - 3260in the firewall and reload the firewall configuration:- firewall-cmd --permanent --add-port=3260/tcp - # firewall-cmd --permanent --add-port=3260/tcp Success- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - firewall-cmd --reload - # firewall-cmd --reload Success- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
Verification
- View the - targetclilayout:- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.2. Creating an iSCSI target
You can create an iSCSI target to let the iSCSI initiator of the client to access the storage devices on the server. Both targets and initiators have unique identifying names.
Prerequisites
- 
						Installed and running targetcli. For more information, see Installing targetcli.
Procedure
- Navigate to the iSCSI directory. You can also use the - cdcommand to navigate to the iSCSI directory.- /> iscsi/ - /> iscsi/- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Use one of the following options to create an iSCSI target: - Creating an iSCSI target using a default target name: - /iscsi> create Created target iqn.2003-01.org.linux-iscsi.hostname.x8664:sn.78b473f296ff Created TPG1 - /iscsi> create Created target iqn.2003-01.org.linux-iscsi.hostname.x8664:sn.78b473f296ff Created TPG1- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Creating an iSCSI target using a specific name: - /iscsi> create iqn.2006-04.com.example:444 Created target iqn.2006-04.com.example:444 Created TPG1 Here iqn.2006-04.com.example:444 is target_iqn_name - /iscsi> create iqn.2006-04.com.example:444 Created target iqn.2006-04.com.example:444 Created TPG1 Here iqn.2006-04.com.example:444 is target_iqn_name- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Replace iqn.2006-04.com.example:444 with the specific target name. 
 
- Verify the newly created target: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.3. iSCSI Backstore
An iSCSI backstore enables support for different methods of storing an exported LUN’s data on the local machine. Creating a storage object defines the resources that the backstore uses.
An administrator can choose any of the following backstore devices that Linux-IO (LIO) supports:
- fileiobackstore
- 
							Create a fileiostorage object if you are using regular files on the local file system as disk images. For creating afileiobackstore, see Creating a fileio storage object.
- blockbackstore
- 
							Create a blockstorage object if you are using any local block device and logical device. For creating ablockbackstore, see Creating a block storage object.
- pscsibackstore
- 
							Create a pscsistorage object if your storage object supports direct pass-through of SCSI commands. For creating apscsibackstore, see Creating a pscsi storage object.
- ramdiskbackstore
- 
							Create a ramdiskstorage object if you want to create a temporary RAM backed device. For creating aramdiskbackstore, see Creating a Memory Copy RAM disk storage object.
8.4. Creating a fileio storage object
				fileio storage objects can support either the write_back or write_thru operations. The write_back operation enables the local file system cache. This improves performance but increases the risk of data loss.
			
				It is recommended to use write_back=false to disable the write_back operation in favor of the write_thru operation.
			
Prerequisites
- 
						Installed and running targetcli. For more information, see Installing targetcli.
Procedure
- Navigate to the - fileio/from the- backstores/directory:- /> backstores/fileio - /> backstores/fileio- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a - fileiostorage object:- /backstores/fileio> create file1 /tmp/disk1.img 200M write_back=false Created fileio file1 with size 209715200 - /backstores/fileio> create file1 /tmp/disk1.img 200M write_back=false Created fileio file1 with size 209715200- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
Verification
- Verify the created - fileiostorage object:- /backstores/fileio> ls - /backstores/fileio> ls- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.5. Creating a block storage object
				The block driver allows the use of any block device that appears in the /sys/block/ directory to be used with Linux-IO (LIO). This includes physical devices, such as HDDs, SSDs, CDs, and DVDs, and logical devices, such as software or hardware RAID volumes, or LVM volumes.
			
Prerequisites
- 
						Installed and running targetcli. For more information, see Installing targetcli.
Procedure
- Navigate to the - block/from the- backstores/directory:- /> backstores/block/ - /> backstores/block/- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a - blockbackstore:- /backstores/block> create name=block_backend dev=/dev/sdb Generating a wwn serial. Created block storage object block_backend using /dev/sdb. - /backstores/block> create name=block_backend dev=/dev/sdb Generating a wwn serial. Created block storage object block_backend using /dev/sdb.- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
Verification
- Verify the created - blockstorage object:- /backstores/block> ls - /backstores/block> ls- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.6. Creating a pscsi storage object
				You can configure as a backstore any storage object that supports direct pass-through of SCSI commands without SCSI emulation and with an underlying SCSI device that appears with lsscsi in the /proc/scsi/scsi, such as a SAS hard drive. SCSI-3 and higher is supported with this subsystem.
			
					pscsi should only be used by advanced users. Advanced SCSI commands such as for Asymmetric Logical Unit Assignment (ALUAs) or Persistent Reservations (for example, those used by VMware ESX, and vSphere) are usually not implemented in the device firmware and can cause malfunctions or crashes. When in doubt, use block backstore for production setups instead.
				
Prerequisites
- 
						Installed and running targetcli. For more information, see Installing targetcli.
Procedure
- Navigate to the - pscsi/from the- backstores/directory:- /> backstores/pscsi/ - /> backstores/pscsi/- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a - pscsibackstore for a physical SCSI device, a TYPE_ROM device using- /dev/sr0in this example:- /backstores/pscsi> create name=pscsi_backend dev=/dev/sr0 Generating a wwn serial. Created pscsi storage object pscsi_backend using /dev/sr0 - /backstores/pscsi> create name=pscsi_backend dev=/dev/sr0 Generating a wwn serial. Created pscsi storage object pscsi_backend using /dev/sr0- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
Verification
- Verify the created - pscsistorage object:- /backstores/pscsi> ls - /backstores/pscsi> ls- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.7. Creating a Memory Copy RAM disk storage object
				Memory Copy RAM disks (ramdisk) provide RAM disks with full SCSI emulation and separate memory mappings using memory copy for initiators. This provides capability for multi-sessions and is particularly useful for fast and volatile mass storage for production purposes.
			
Prerequisites
- 
						Installed and running targetcli. For more information, see Installing targetcli.
Procedure
- Navigate to the - ramdisk/from the- backstores/directory:- /> backstores/ramdisk/ - /> backstores/ramdisk/- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a 1GB RAM disk backstore: - /backstores/ramdisk> create name=rd_backend size=1GB Generating a wwn serial. Created rd_mcp ramdisk rd_backend with size 1GB. - /backstores/ramdisk> create name=rd_backend size=1GB Generating a wwn serial. Created rd_mcp ramdisk rd_backend with size 1GB.- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
Verification
- Verify the created - ramdiskstorage object:- /backstores/ramdisk> ls - /backstores/ramdisk> ls- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.8. Creating an iSCSI portal
You can create an iSCSI portal. This adds an IP address and a port to the target that keeps the target enabled.
Prerequisites
- 
						Installed and running targetcli. For more information, see Installing targetcli.
- An iSCSI target associated with a Target Portal Groups (TPG). For more information, see Creating an iSCSI target.
Procedure
- Navigate to the TPG directory: - /iscsi> iqn.2006-04.com.example:444/tpg1/ - /iscsi> iqn.2006-04.com.example:444/tpg1/- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Use one of the following options to create an iSCSI portal: - Creating a default portal uses the default iSCSI port - 3260and allows the target to listen to all IP addresses on that port:- /iscsi/iqn.20...mple:444/tpg1> portals/ create Using default IP port 3260 Binding to INADDR_Any (0.0.0.0) Created network portal 0.0.0.0:3260 - /iscsi/iqn.20...mple:444/tpg1> portals/ create Using default IP port 3260 Binding to INADDR_Any (0.0.0.0) Created network portal 0.0.0.0:3260- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Creating a portal using a specific IP address: - /iscsi/iqn.20...mple:444/tpg1> portals/ create 192.168.122.137 Using default IP port 3260 Created network portal 192.168.122.137:3260 - /iscsi/iqn.20...mple:444/tpg1> portals/ create 192.168.122.137 Using default IP port 3260 Created network portal 192.168.122.137:3260- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
 
Verification
- Verify the newly created portal: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.9. Creating an iSCSI LUN
Logical unit number (LUN) is a physical device that is backed by the iSCSI backstore. Each LUN has a unique number.
Prerequisites
- 
						Installed and running targetcli. For more information, see Installing targetcli.
- An iSCSI target associated with a Target Portal Groups (TPG). For more information, see Creating an iSCSI target.
- Created storage objects. For more information, see iSCSI Backstore.
Procedure
- Create LUNs of already created storage objects: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Verify the created LUNs: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Default LUN name starts at - 0.Important- By default, LUNs are created with read-write permissions. If a new LUN is added after ACLs are created, LUN automatically maps to all available ACLs and can cause a security risk. To create a LUN with read-only permissions, see Creating a read-only iSCSI LUN. 
- Configure ACLs. For more information, see Creating an iSCSI ACL.
8.10. Creating a read-only iSCSI LUN
By default, LUNs are created with read-write permissions. You can create a read-only LUN.
Prerequisites
- 
						Installed and running targetcli. For more information, see Installing targetcli.
- An iSCSI target associated with a Target Portal Groups (TPG). For more information, see Creating an iSCSI target.
- Created storage objects. For more information, see iSCSI Backstore.
Procedure
- Set read-only permissions: - /> set global auto_add_mapped_luns=false Parameter auto_add_mapped_luns is now 'false'. - /> set global auto_add_mapped_luns=false Parameter auto_add_mapped_luns is now 'false'.- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - This prevents the auto mapping of LUNs to existing ACLs allowing the manual mapping of LUNs. 
- Navigate to the initiator_iqn_name directory: - /> iscsi/target_iqn_name/tpg1/acls/initiator_iqn_name/ - /> iscsi/target_iqn_name/tpg1/acls/initiator_iqn_name/- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create the LUN: - /iscsi/target_iqn_name/tpg1/acls/initiator_iqn_name> create mapped_lun=next_sequential_LUN_number tpg_lun_or_backstore=backstore write_protect=1 - /iscsi/target_iqn_name/tpg1/acls/initiator_iqn_name> create mapped_lun=next_sequential_LUN_number tpg_lun_or_backstore=backstore write_protect=1- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example: - /iscsi/target_iqn_name/tpg1/acls/2006-04.com.example:888> create mapped_lun=1 tpg_lun_or_backstore=/backstores/block/block2 write_protect=1 Created LUN 1. Created Mapped LUN 1. - /iscsi/target_iqn_name/tpg1/acls/2006-04.com.example:888> create mapped_lun=1 tpg_lun_or_backstore=/backstores/block/block2 write_protect=1 Created LUN 1. Created Mapped LUN 1.- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Verify the created LUN: - /iscsi/target_iqn_name/tpg1/acls/2006-04.com.example:888> ls o- 2006-04.com.example:888 .. [Mapped LUNs: 2] | o- mapped_lun0 .............. [lun0 block/disk1 (rw)] | o- mapped_lun1 .............. [lun1 block/disk2 (ro)] - /iscsi/target_iqn_name/tpg1/acls/2006-04.com.example:888> ls o- 2006-04.com.example:888 .. [Mapped LUNs: 2] | o- mapped_lun0 .............. [lun0 block/disk1 (rw)] | o- mapped_lun1 .............. [lun1 block/disk2 (ro)]- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - The mapped_lun1 line now has ( - ro) at the end (unlike mapped_lun0’s (- rw)) stating that it is read-only.
- Configure ACLs. For more information, see Creating an iSCSI ACL.
8.11. Creating an iSCSI ACL
				The targetcli service uses Access Control Lists (ACLs) to define access rules and grant each initiator access to a Logical Unit Number (LUN).
			
				Both targets and initiators have unique identifying names. You must know the unique name of the initiator to configure ACLs. The /etc/iscsi/initiatorname.iscsi file, provided by the iscsi-initiator-utils package, contains the iSCSI initiator names.
			
Prerequisites
- 
						The targetcliservice is installed and running.
- An iSCSI target associated with a Target Portal Groups (TPG).
Procedure
- Optional: To disable auto mapping of LUNs to ACLs see Creating a read-only iSCSI LUN.
- Navigate to the acls directory: - /> iscsi/target_iqn_name/tpg_name/acls/ - /> iscsi/target_iqn_name/tpg_name/acls/- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Use one of the following options to create an ACL: - Use the initiator_iqn_name from the - /etc/iscsi/initiatorname.iscsifile on the initiator:- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Use a custom_name and update the initiator to match it: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - For information about updating the initiator name, see Creating an iSCSI intiator. 
 
Verification
- Verify the created ACL: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.12. Setting up the Challenge-Handshake Authentication Protocol for the target
				By using the Challenge-Handshake Authentication Protocol (CHAP), users can protect the target with a password. The initiator must be aware of this password to be able to connect to the target.
			
Prerequisites
- Created iSCSI ACL. For more information, see Creating an iSCSI ACL.
Procedure
- Set attribute authentication: - /iscsi/iqn.20...mple:444/tpg1> set attribute authentication=1 Parameter authentication is now '1'. - /iscsi/iqn.20...mple:444/tpg1> set attribute authentication=1 Parameter authentication is now '1'.- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Set - useridand- password:- /tpg1> set auth userid=redhat Parameter userid is now 'redhat'. /iscsi/iqn.20...689dcbb3/tpg1> set auth password=redhat_passwd Parameter password is now 'redhat_passwd'. - /tpg1> set auth userid=redhat Parameter userid is now 'redhat'. /iscsi/iqn.20...689dcbb3/tpg1> set auth password=redhat_passwd Parameter password is now 'redhat_passwd'.- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Navigate to the - aclsdirectory:- /> iscsi/target_iqn_name/tpg1/acls/initiator_iqn_name/ - /> iscsi/target_iqn_name/tpg1/acls/initiator_iqn_name/- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Set attribute authentication: - /iscsi/iqn.20...:605fcc6a48be> set attribute authentication=1 Parameter authentication is now '1'. - /iscsi/iqn.20...:605fcc6a48be> set attribute authentication=1 Parameter authentication is now '1'.- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Set - useridand- password:- /iscsi/iqn.20...:605fcc6a48be> set auth userid=redhat Parameter userid is now 'redhat'. /iscsi/iqn.20...:605fcc6a48be> set auth password=redhat_passwd Parameter password is now 'redhat_passwd'. - /iscsi/iqn.20...:605fcc6a48be> set auth userid=redhat Parameter userid is now 'redhat'. /iscsi/iqn.20...:605fcc6a48be> set auth password=redhat_passwd Parameter password is now 'redhat_passwd'.- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
8.13. Removing an iSCSI object using targetcli tool
				You can remove the iSCSI objects by using the targetcli tool.
			
Procedure
- Log off from the target: - iscsiadm -m node -T iqn.2006-04.com.example:444 -u - # iscsiadm -m node -T iqn.2006-04.com.example:444 -u- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - For more information about how to log in to the target, see Creating an iSCSI initiator. 
- Remove the entire target, including all ACLs, LUNs, and portals: - /> iscsi/ delete iqn.2006-04.com.example:444 - /> iscsi/ delete iqn.2006-04.com.example:444- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Replace iqn.2006-04.com.example:444 with the target_iqn_name. - To remove an iSCSI backstore: - /> backstores/backstore-type/ delete block_backend - /> backstores/backstore-type/ delete block_backend- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Replace backstore-type with either - fileio,- block,- pscsi, or- ramdisk.- Replace block_backend with the backstore-name you want to delete. 
- To remove parts of an iSCSI target, such as an ACL: - /> /iscsi/iqn-name/tpg/acls/ delete iqn.2006-04.com.example:444 - /> /iscsi/iqn-name/tpg/acls/ delete iqn.2006-04.com.example:444- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
 
Verification
- View the changes: - /> iscsi/ ls - /> iscsi/ ls- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow