Build a shared disk (iscsi disk sharing)

1. Overview of iscsi disk sharing

The implementation principle of iSCSI disk sharing is mainly based on iSCSI Target software and TCP/IP network protocol. The storage space of the server is allocated to the client. The client can use the iSCSI disk like a local hard disk, including partitioning and formatting it. And reading and writing, etc.

Specifically, iSCSI uses standard IP networks to package the SCSI protocol in TCP/IP packets for transmission, allowing computers to access remote storage devices through the network and treat them as local disks. Its working principle is to map the iSCSI disk that needs to be shared (i.e. LUN, Logical Unit Number) to a logical unit of the local computer, and then read and write it like a local hard disk.

When implementing iSCSI disk sharing, you need to pay attention to the following points:

  1. Network protocols and network equipment: iSCSI storage solutions rely on the TCP/IP network protocol, so high-quality network equipment and Gigabit Ethernet switches are required to ensure the stability and speed of data transmission. It is recommended to use Gigabit Ethernet switches in the iSCSI network and try to choose a device configuration that does not contain any points of failure, such as equipping two independent ports in each independent array with a switch and connecting them to ensure that the storage system of uninterrupted operation.
  2. Data security: Since iSCSI disk sharing involves data transmission and processing, data security is very important. Data needs to be encrypted and access rights to network devices must be strictly controlled to prevent unauthorized access and data leakage.
  3. Availability and performance: When performing iSCSI disk sharing, the availability and performance of the storage device need to be considered. For example, you can consider using multipath I/O (MPIO) technology to improve data availability and performance, while also achieving load balancing.
  4. Management and maintenance: The management and maintenance of iSCSI disk shares requires professional IT personnel to operate and maintain, and factors such as data backup and recovery also need to be considered.

2. Implementation process

Server related operations

1. The server prepares a disk for sharing (the sdb disk of node1 node is taken as an example)

# Partition the disk to be shared
fdisk /dev/sdb

Enter n > p >1 > Enter > + 2G > Enter to complete the partitioning of the first disk.
Enter n > p >2 > Enter > + 2G > Enter to complete the partitioning of the second disk.
Enter n > p >3 > Enter > + 2G > Enter to complete the partitioning of the third disk.
Enter n > p >4 > Enter > + 3G > Enter to complete the fourth disk partition
w Save the new partition and exit

The situation after partitioning is as follows

2. Install targetcli, start it and set it to start automatically at boot

#Install targetcli package
yum -y install targetcli

#Set the target service to start at boot and start the service
systemctl enable target

systemctl start target

3.targetcli server configuration

targetcli enters configuration

View existing configuration

/>ls
o-/........................................ ................................................................. ........................ [...]
  o-backstores ............................................. ................................................................. ............. [...]
  | o-block ........................................ ................................................................. .. [Storage Objects: 0]
  | o-fileio ........................................ ................................................................. . [Storage Objects: 0]
  | o-pscsi ........................................ ................................................................. .. [Storage Objects: 0]
  |o-ramdisk........................................ ................................................................. [Storage Objects: 0]
  o-iscsi ............................................. ................................................................. ........... [Targets: 0]
  o- loopback ............................................. ................................................................. ........ [Targets: 0]

Create storage backend

#1. Enter the /backstores/block path to create a backend storage
/backstores/block create dev=/dev/sdb name=dm

Create target tag

#2. Enter the /iscsi/ path and create a target tag. iqn.xxxx-xx is a fixed format. The subsequent domain name can be changed at will by writing it in reverse.
/> iscsi/ create iqn.2023-10.com.dm

Bind the storage backend to the target tag

#3. Perform lun association (add the storage backend in the first step to the tag)
/> iscsi/iqn.2023-10.com.dm/tpg1/luns create /backstores/block/dm

Set password

#4. Create a new ACL (equivalent to the password for the client to identify the node1 node)
/> iscsi/iqn.2023-10.com.dm/tpg1/acls create iqn.2023-10.com.dm:client

Modify the server listening IP and port

#5. Set the listening IP address and port number of the iSCSI server (the default 0.0.0.0 represents that all IPs on the server can provide external monitored services, and can be changed according to the actual situation after deletion)
/> iscsi/iqn.2023-10.com.dm/tpg1/portals/ delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/> iscsi/iqn.2023-10.com.dm/tpg1/portals/ create 192.168.75.104

Check whether the configuration takes effect

exit

Restart target service

# Restart target service
[root@server ~]# systemctl restart target

# Set the target service to start at boot
[root@server ~]# systemctl enable target

# Turn off the firewall
[root@server ~]# systemctl stop firewalld.service 

Client related operations

#Install iscsi-initiator-utils
[root@client ~] yum install -y iscsi-initiator-utils

#Edit the configuration file /etc/iscsi/initiatorname.iscsi and change the name to the name claimed by the client in the server

[root@client ~]# vi /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2023-06.com.dm:client
 
[root@CentOS7-NTP ~]# sudo systemctl status iscsid  ##View iscsi service status
[root@CentOS7-NTP ~]# sudo systemctl restart iscsid   ##Start iscsi service
[root@CentOS7-NTP ~]# sudo systemctl enable iscsid    ##Set up the iscsi service to start at boot

# Discover shared devices
 sudo iscsiadm -m discovery -t st -p 192.168.75.104

# Connect to shared device
 sudo iscsiadm -m node -T iqn.2023-10.com.dm -p 192.168.75.104 -l
 
#Set automatic mounting at boot
iscsiadm -m node -T iqn.2023-10.com.dm -p 192.168.75.104 --op update -n node.startup -v automatic

At this time, use the fdisk -l or lsblk command on the client to view the corresponding shared disk.

At this point node1 has successfully shared the disk to the node1 node.