How to Configure iSCSI Target with Targetcli on AlmaLinux
Categories:
How to Configure iSCSI Target Using Targetcli on AlmaLinux
The iSCSI (Internet Small Computer Systems Interface) protocol allows users to access storage devices over a network as if they were local. On AlmaLinux, configuring an iSCSI target is straightforward with the targetcli tool, a modern and user-friendly interface for setting up storage backends.
This guide provides a step-by-step tutorial on configuring an iSCSI target using Targetcli on AlmaLinux. We’ll cover prerequisites, installation, configuration, and testing to ensure your setup works seamlessly.
Understanding iSCSI and Targetcli
Before diving into the setup, let’s understand the key components:
- iSCSI Target: A storage device (or logical unit) shared over a network.
- iSCSI Initiator: A client accessing the target device.
- Targetcli: A command-line utility that simplifies configuring the Linux kernel’s built-in target subsystem.
Benefits of iSCSI include:
- Centralized storage management.
- Easy scalability and flexibility.
- Compatibility with various operating systems.
Step 1: Prerequisites
Before configuring an iSCSI target, ensure the following:
AlmaLinux Requirements:
- AlmaLinux 8 or later.
- Root or sudo access.
Networking Requirements:
- A static IP address for the target server.
- A secure and stable network connection.
Storage Setup:
- A block storage device or file to be shared.
Software Packages:
- The targetcli utility installed on the target server.
- iSCSI initiator tools for testing the configuration.
Step 2: Installing Targetcli
To install Targetcli, run the following commands:
sudo dnf install targetcli -y
Verify the installation:
targetcli --version
Step 3: Configuring the iSCSI Target
Start Targetcli: Launch the Targetcli shell:
sudo targetcli
Create a Backstore: A backstore is the storage resource that will be exported to clients. You can create one using a block device or file.
For a block device (e.g.,
/dev/sdb
):/backstores/block create name=block1 dev=/dev/sdb
For a file-based backstore:
/backstores/fileio create name=file1 file_or_dev=/srv/iscsi/file1.img size=10G
Create an iSCSI Target: Create an iSCSI target with a unique name:
/iscsi create iqn.2024-12.com.example:target1
The IQN (iSCSI Qualified Name) must be unique and follow the standard format (e.g.,
iqn.YYYY-MM.domain:identifier
).Add a LUN (Logical Unit Number): Link the backstore to the target as a LUN:
/iscsi/iqn.2024-12.com.example:target1/tpg1/luns create /backstores/block/block1
Configure Network Access: Define which clients can access the target by setting up an ACL (Access Control List):
/iscsi/iqn.2024-12.com.example:target1/tpg1/acls create iqn.2024-12.com.example:initiator1
Replace
initiator1
with the IQN of the client.Enable Listening on the Network Interface: Ensure the portal listens on the desired IP address and port:
/iscsi/iqn.2024-12.com.example:target1/tpg1/portals create 192.168.1.100 3260
Replace
192.168.1.100
with your server’s IP address.Save the Configuration: Save the current configuration:
saveconfig
Step 4: Enable and Start iSCSI Services
Enable and start the iSCSI service:
sudo systemctl enable target
sudo systemctl start target
Check the service status:
sudo systemctl status target
Step 5: Configuring the iSCSI Initiator (Client)
On the client machine, install the iSCSI initiator tools:
sudo dnf install iscsi-initiator-utils -y
Edit the initiator name in /etc/iscsi/initiatorname.iscsi
to match the ACL configured on the target server.
Discover the iSCSI target:
sudo iscsiadm -m discovery -t sendtargets -p 192.168.1.100
Log in to the target:
sudo iscsiadm -m node -T iqn.2024-12.com.example:target1 -p 192.168.1.100 --login
Verify that the iSCSI device is available:
lsblk
Step 6: Testing and Verification
To ensure the iSCSI target is functional:
On the client, format the device:
sudo mkfs.ext4 /dev/sdX
Mount the device:
sudo mount /dev/sdX /mnt
Test read and write operations to confirm connectivity.
Step 7: Troubleshooting
Issue: Targetcli Fails to Start
- Check for SELinux restrictions and disable temporarily for testing:
sudo setenforce 0
- Check for SELinux restrictions and disable temporarily for testing:
Issue: Client Cannot Discover Target
- Ensure the target server’s firewall allows iSCSI traffic on port 3260:
sudo firewall-cmd --add-port=3260/tcp --permanent sudo firewall-cmd --reload
- Ensure the target server’s firewall allows iSCSI traffic on port 3260:
Issue: ACL Errors
- Verify that the client’s IQN matches the ACL configured on the target server.
Conclusion
Configuring an iSCSI target using Targetcli on AlmaLinux is an efficient way to share storage over a network. This guide has walked you through the entire process, from installation to testing, ensuring a reliable and functional setup. By following these steps, you can set up a robust storage solution that simplifies access and management for clients.
Whether for personal or enterprise use, mastering Targetcli empowers you to deploy scalable and flexible storage systems with ease.