This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Storage Server: NFS and iSCSI

Storage server settings for NFS, iSCSI on AlmaLinux 9

This Document is actively being developed as a part of ongoing AlmaLinux learning efforts. Chapters will be added periodically.

AlmaLinux 9: Storage Server: NFS and iSCSI

1 - How to Configure NFS Server on AlmaLinux

Learn how to set up an NFS server on AlmaLinux with this comprehensive guide. Step-by-step instructions for installation, configuration, testing, and best practices.

How to Configure NFS Server on AlmaLinux

The Network File System (NFS) is a distributed file system protocol that allows multiple systems to share directories and files over a network. With NFS, you can centralize storage for easier management and provide seamless access to shared resources. Setting up an NFS server on AlmaLinux is a straightforward process, and it can be a vital part of an organization’s infrastructure.

This guide explains how to configure an NFS server on AlmaLinux, covering installation, configuration, and best practices to ensure optimal performance and security.


What is NFS?

The Network File System (NFS) is a protocol originally developed by Sun Microsystems that enables remote access to files as if they were local. It is widely used in UNIX-like operating systems, including Linux, to enable file sharing across a network.

Key features of NFS include:

  • Seamless File Access: Files shared via NFS appear as local directories.
  • Centralized Storage: Simplifies file management and backups.
  • Interoperability: Supports sharing between different operating systems.

Benefits of Using an NFS Server

  1. Centralized Data: Consolidate storage for easier management.
  2. Scalability: Share files across multiple systems without duplication.
  3. Cost Efficiency: Reduce storage costs by leveraging centralized resources.
  4. Cross-Platform Support: Compatible with most UNIX-based systems.

Prerequisites

To configure an NFS server on AlmaLinux, ensure the following:

  1. An AlmaLinux system with administrative (root or sudo) privileges.
  2. A static IP address for the server.
  3. Basic knowledge of Linux command-line operations.

Step 1: Install the NFS Server Package

  1. Update the System

    Before installing the NFS server, update your system packages:

    sudo dnf update -y
    
  2. Install the NFS Utilities

    Install the required NFS server package:

    sudo dnf install nfs-utils -y
    
  3. Enable and Start the NFS Services

    Enable and start the necessary NFS services:

    sudo systemctl enable nfs-server
    sudo systemctl start nfs-server
    

    Verify that the NFS server is running:

    sudo systemctl status nfs-server
    

Step 2: Create and Configure the Shared Directory

  1. Create a Directory to Share

    Create the directory you want to share over NFS. For example:

    sudo mkdir -p /srv/nfs/shared
    
  2. Set Permissions

    Assign appropriate ownership and permissions to the directory. In most cases, you’ll set the owner to nobody and the group to nogroup for general access:

    sudo chown nobody:nogroup /srv/nfs/shared
    sudo chmod 755 /srv/nfs/shared
    
  3. Add Files (Optional)

    Populate the directory with files for clients to access:

    echo "Welcome to the NFS share!" | sudo tee /srv/nfs/shared/welcome.txt
    

Step 3: Configure the NFS Exports

The exports file defines which directories to share and the permissions for accessing them.

  1. Edit the Exports File

    Open the /etc/exports file in a text editor:

    sudo vim /etc/exports
    
  2. Add an Export Entry

    Add an entry for the directory you want to share. For example:

    /srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)
    
    • /srv/nfs/shared: The shared directory path.
    • 192.168.1.0/24: The network allowed to access the share.
    • rw: Grants read and write access.
    • sync: Ensures data is written to disk before the server responds.
    • no_subtree_check: Disables subtree checking for better performance.
  3. Export the Shares

    Apply the changes by exporting the shares:

    sudo exportfs -a
    
  4. Verify the Exported Shares

    Check the list of exported directories:

    sudo exportfs -v
    

Step 4: Configure Firewall Rules

Ensure the firewall allows NFS traffic.

  1. Allow NFS Service

    Add NFS to the firewall rules:

    sudo firewall-cmd --add-service=nfs --permanent
    sudo firewall-cmd --reload
    
  2. Verify Firewall Settings

    Confirm that the NFS service is allowed:

    sudo firewall-cmd --list-all
    

Step 5: Test the NFS Server

  1. Install NFS Utilities on a Client System

    On the client system, ensure the NFS utilities are installed:

    sudo dnf install nfs-utils -y
    
  2. Create a Mount Point

    Create a directory to mount the shared NFS directory:

    sudo mkdir -p /mnt/nfs/shared
    
  3. Mount the NFS Share

    Use the mount command to connect to the NFS share. Replace <server-ip> with the IP address of the NFS server:

    sudo mount <server-ip>:/srv/nfs/shared /mnt/nfs/shared
    
  4. Verify the Mount

    Check if the NFS share is mounted successfully:

    df -h
    

    Navigate to the mounted directory to ensure access:

    ls /mnt/nfs/shared
    
  5. Make the Mount Persistent

    To mount the NFS share automatically at boot, add the following line to the /etc/fstab file on the client:

    <server-ip>:/srv/nfs/shared  /mnt/nfs/shared  nfs  defaults  0  0
    

Step 6: Secure the NFS Server

  1. Restrict Access

    Use CIDR notation or specific IP addresses in the /etc/exports file to limit access to trusted networks or systems.

    Example:

    /srv/nfs/shared 192.168.1.10(rw,sync,no_subtree_check)
    
  2. Enable SELinux for NFS

    AlmaLinux uses SELinux by default. Configure SELinux for NFS sharing:

    sudo setsebool -P nfs_export_all_rw 1
    
  3. Use Strong Authentication

    Consider enabling Kerberos for secure authentication in environments requiring high security.


Troubleshooting Tips

  1. Clients Cannot Access the NFS Share

    • Verify that the NFS server is running:

      sudo systemctl status nfs-server
      
    • Check firewall rules and ensure the client is allowed.

  2. Mount Fails

    • Ensure the shared directory is correctly exported:

      sudo exportfs -v
      
    • Verify network connectivity between the client and server.

  3. Performance Issues

    • Use the sync and async options appropriately in /etc/exports to balance reliability and speed.
    • Monitor NFS performance with tools like nfsstat.

Best Practices for NFS Server Configuration

  1. Monitor Usage: Regularly monitor NFS server performance to identify bottlenecks.
  2. Backup Shared Data: Protect shared data with regular backups.
  3. Use Secure Connections: Implement Kerberos or VPNs for secure access in untrusted networks.
  4. Limit Permissions: Use read-only (ro) exports where write access is not required.

Conclusion

Configuring an NFS server on AlmaLinux is a powerful way to centralize file sharing and streamline data access across your network. By following this guide, you’ve learned how to install and configure the NFS server, set up exports, secure the system, and test the configuration.

With proper setup and maintenance, an NFS server can significantly enhance the efficiency and reliability of your network infrastructure. For advanced setups or troubleshooting, consider exploring the official NFS documentation or the AlmaLinux community forums.


2 - How to Configure NFS Client on AlmaLinux

Learn how to configure an NFS client on AlmaLinux. This comprehensive guide covers installation, setup, mounting, troubleshooting, and best practices for efficient file sharing.

How to Configure NFS Client on AlmaLinux

The Network File System (NFS) is a popular protocol used to share directories and files between systems over a network. Configuring an NFS client on AlmaLinux enables your system to access files shared by an NFS server seamlessly, as if they were stored locally. This capability is crucial for centralized file sharing in enterprise and home networks.

In this guide, we’ll cover the process of setting up an NFS client on AlmaLinux, including installation, configuration, testing, and troubleshooting.


What is an NFS Client?

An NFS client is a system that connects to an NFS server to access shared directories and files. The client interacts with the server to read and write files over a network while abstracting the complexities of network communication. NFS clients are commonly used in environments where file-sharing between multiple systems is essential.


Benefits of Configuring an NFS Client

  1. Centralized Access: Access remote files as if they were local.
  2. Ease of Use: Streamlines collaboration by allowing multiple clients to access shared files.
  3. Scalability: Supports large networks with multiple clients.
  4. Interoperability: Works across various operating systems, including Linux, Unix, and macOS.

Prerequisites

Before configuring an NFS client, ensure the following:

  1. An AlmaLinux system with administrative (root or sudo) privileges.
  2. An NFS server set up and running on the same network. (Refer to our guide on configuring an NFS server on AlmaLinux if needed.)
  3. Network connectivity between the client and the server.
  4. Knowledge of the shared directory path on the NFS server.

Step 1: Install NFS Utilities on the Client

The NFS utilities package is required to mount NFS shares on the client system.

  1. Update the System

    Ensure your system is up-to-date:

    sudo dnf update -y
    
  2. Install NFS Utilities

    Install the NFS client package:

    sudo dnf install nfs-utils -y
    
  3. Verify the Installation

    Confirm that the package is installed:

    rpm -q nfs-utils
    

Step 2: Create a Mount Point

A mount point is a directory where the NFS share will be accessed.

  1. Create the Directory

    Create a directory on the client system to serve as the mount point:

    sudo mkdir -p /mnt/nfs/shared
    

    Replace /mnt/nfs/shared with your preferred directory path.

  2. Set Permissions

    Adjust the permissions of the directory if needed:

    sudo chmod 755 /mnt/nfs/shared
    

Step 3: Mount the NFS Share

To access the shared directory, you need to mount the NFS share from the server.

  1. Identify the NFS Server and Share

    Ensure you know the IP address of the NFS server and the path of the shared directory. For example:

    • Server IP: 192.168.1.100
    • Shared Directory: /srv/nfs/shared
  2. Manually Mount the Share

    Use the mount command to connect to the NFS share:

    sudo mount 192.168.1.100:/srv/nfs/shared /mnt/nfs/shared
    

    In this example:

    • 192.168.1.100:/srv/nfs/shared is the NFS server and share path.
    • /mnt/nfs/shared is the local mount point.
  3. Verify the Mount

    Check if the NFS share is mounted successfully:

    df -h
    

    You should see the NFS share listed in the output.

  4. Access the Shared Files

    Navigate to the mount point and list the files:

    ls /mnt/nfs/shared
    

Step 4: Make the Mount Persistent

By default, manual mounts do not persist after a reboot. To ensure the NFS share is mounted automatically at boot, update the /etc/fstab file.

  1. Edit the /etc/fstab File

    Open the /etc/fstab file in a text editor:

    sudo vim /etc/fstab
    
  2. Add an Entry for the NFS Share

    Add the following line to the file:

    192.168.1.100:/srv/nfs/shared  /mnt/nfs/shared  nfs  defaults  0  0
    
    • Replace 192.168.1.100:/srv/nfs/shared with the server and share path.
    • Replace /mnt/nfs/shared with your local mount point.
  3. Test the Configuration

    Test the /etc/fstab entry by unmounting the share and remounting all entries:

    sudo umount /mnt/nfs/shared
    sudo mount -a
    

    Verify that the share is mounted correctly:

    df -h
    

Step 5: Configure Firewall and SELinux (if required)

If you encounter access issues, ensure that the firewall and SELinux settings are configured correctly.

Firewall Configuration

  1. Check Firewall Rules

    Ensure the client can communicate with the server on the necessary ports (typically port 2049 for NFS).

    sudo firewall-cmd --list-all
    
  2. Add Rules (if needed)

    Allow NFS traffic:

    sudo firewall-cmd --add-service=nfs --permanent
    sudo firewall-cmd --reload
    

SELinux Configuration

  1. Check SELinux Status

    Verify that SELinux is enforcing policies:

    sestatus
    
  2. Update SELinux for NFS

    If necessary, allow NFS access:

    sudo setsebool -P use_nfs_home_dirs 1
    

Step 6: Troubleshooting Common Issues

  1. NFS Share Not Mounting

    • Verify the server and share path are correct.
    • Ensure the server is running and accessible:
      ping 192.168.1.100
      
    • Check if the NFS server is exporting the directory:
      showmount -e 192.168.1.100
      
  2. Permission Denied

    • Confirm that the server’s /etc/exports file allows access from the client’s IP.
    • Check directory permissions on the NFS server.
  3. Slow Performance

    • Use the async option in the /etc/fstab file for better performance:
      192.168.1.100:/srv/nfs/shared  /mnt/nfs/shared  nfs  defaults,async  0  0
      
  4. Mount Fails After Reboot

    • Verify the /etc/fstab entry is correct.
    • Check system logs for errors:
      sudo journalctl -xe
      

Best Practices for Configuring NFS Clients

  1. Document Mount Points: Maintain a list of NFS shares and their corresponding mount points for easy management.
  2. Secure Access: Limit access to trusted systems using the NFS server’s /etc/exports file.
  3. Monitor Usage: Regularly monitor mounted shares to ensure optimal performance and resource utilization.
  4. Backup Critical Data: Back up data regularly to avoid loss in case of server issues.

Conclusion

Configuring an NFS client on AlmaLinux is a simple yet powerful way to enable seamless access to remote file systems. By following this guide, you’ve learned how to install the necessary utilities, mount an NFS share, make the configuration persistent, and troubleshoot common issues.

NFS is an essential tool for collaborative environments and centralized storage solutions. With proper setup and best practices, it can significantly enhance your system’s efficiency and reliability.

For further support, explore the official NFS documentation or join the AlmaLinux community forums.


3 - Mastering NFS 4 ACLs on AlmaLinux

Learn how to configure and manage NFS 4 ACLs on AlmaLinux. This step-by-step guide covers installation, setup, and advanced usage tips for efficient file-sharing.

The Network File System (NFS) is a powerful tool for sharing files between Linux systems. AlmaLinux, a popular and stable distribution derived from the RHEL ecosystem, fully supports NFS and its accompanying Access Control Lists (ACLs). NFSv4 ACLs provide granular file permissions beyond traditional Unix permissions, allowing administrators to tailor access with precision.

This guide will walk you through the steps to use the NFS 4 ACL tool effectively on AlmaLinux. We’ll explore prerequisites, installation, configuration, and troubleshooting to help you leverage this feature for optimized file-sharing management.


Understanding NFS 4 ACLs

NFSv4 ACLs extend traditional Unix file permissions, allowing for more detailed and complex rules. While traditional permissions only offer read, write, and execute permissions for owner, group, and others, NFSv4 ACLs introduce advanced controls such as inheritance and fine-grained user permissions.

Key Benefits:

  1. Granularity: Define permissions for specific users or groups.
  2. Inheritance: Automatically apply permissions to child objects.
  3. Compatibility: Compatible with modern file systems like XFS and ext4.

Prerequisites

Before proceeding, ensure the following prerequisites are met:

  1. System Requirements:

    • AlmaLinux 8 or later.
    • Administrative (root or sudo) access to the server.
  2. Installed Packages:

    • NFS utilities (nfs-utils package).
    • ACL tools (acl package).
  3. Network Setup:

    • Ensure both the client and server systems are on the same network and can communicate effectively.
  4. Filesystem Support:

    • The target filesystem (e.g., XFS or ext4) must support ACLs.

Step 1: Installing Required Packages

To manage NFS 4 ACLs, install the necessary packages:

sudo dnf install nfs-utils acl -y

This command installs tools needed to configure and verify ACLs on AlmaLinux.


Step 2: Configuring the NFS Server

  1. Exporting the Directory:

    • Edit the /etc/exports file to specify the directory to be shared:

      /shared_directory client_ip(rw,sync,no_root_squash,fsid=0)
      
    • Replace /shared_directory with the directory path and client_ip with the client’s IP address or subnet.

  2. Enable ACL Support:

    • Ensure the target filesystem is mounted with ACL support. Add the acl option in /etc/fstab:

      UUID=xyz /shared_directory xfs defaults,acl 0 0
      
    • Remount the filesystem:

      sudo mount -o remount,acl /shared_directory
      
  3. Restart NFS Services: Restart the NFS server to apply changes:

    sudo systemctl restart nfs-server
    

Step 3: Setting ACLs on the Server

Use the setfacl command to define ACLs:

  • Granting Permissions:

    sudo setfacl -m u:username:rw /shared_directory
    

    This grants read and write permissions to username.

  • Verifying Permissions: Use the getfacl command to confirm ACLs:

    getfacl /shared_directory
    
  • Setting Default ACLs: To ensure new files inherit permissions:

    sudo setfacl -d -m u:username:rwx /shared_directory
    

Step 4: Configuring the NFS Client

  1. Mounting the NFS Share: On the client machine, mount the NFS share:

    sudo mount -t nfs4 server_ip:/ /mnt
    
  2. Ensuring ACL Functionality: Verify that the ACLs are accessible:

    getfacl /mnt/shared_directory
    

Step 5: Troubleshooting Common Issues

  • Issue: “Operation Not Permitted” when Setting ACLs

    • Ensure the filesystem is mounted with ACL support.
    • Verify user privileges.
  • Issue: NFS Share Not Mounting

    • Check network connectivity between the client and server.

    • Confirm NFS services are running:

      sudo systemctl status nfs-server
      
  • Issue: ACLs Not Persisting

    • Confirm the ACL options in /etc/fstab are correctly configured.

Advanced Tips

  1. Using Recursive ACLs: Apply ACLs recursively to an entire directory structure:

    sudo setfacl -R -m u:username:rw /shared_directory
    
  2. Auditing Permissions: Use ls -l and getfacl together to compare traditional and ACL permissions.

  3. Backup ACLs: Backup existing ACL settings:

    getfacl -R /shared_directory > acl_backup.txt
    

    Restore ACLs from backup:

    setfacl --restore=acl_backup.txt
    

Conclusion

The NFS 4 ACL tool on AlmaLinux offers administrators unparalleled control over file access permissions, enabling secure and precise management. By following the steps outlined in this guide, you can confidently configure and use NFSv4 ACLs for enhanced file-sharing solutions. Remember to regularly audit permissions and ensure your network is securely configured to prevent unauthorized access.

Mastering NFS 4 ACLs is not only an essential skill for Linux administrators but also a cornerstone for establishing robust and reliable enterprise-level file-sharing systems.

4 - How to Configure iSCSI Target with Targetcli on AlmaLinux

Learn how to configure iSCSI targets using Targetcli on AlmaLinux.

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:

  1. AlmaLinux Requirements:

    • AlmaLinux 8 or later.
    • Root or sudo access.
  2. Networking Requirements:

    • A static IP address for the target server.
    • A secure and stable network connection.
  3. Storage Setup:

    • A block storage device or file to be shared.
  4. 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

  1. Start Targetcli: Launch the Targetcli shell:

    sudo targetcli
    
  2. 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
      
  3. 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).

  4. 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
    
  5. 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.

  6. 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.

  7. 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:

  1. On the client, format the device:

    sudo mkfs.ext4 /dev/sdX
    
  2. Mount the device:

    sudo mount /dev/sdX /mnt
    
  3. Test read and write operations to confirm connectivity.


Step 7: Troubleshooting

  1. Issue: Targetcli Fails to Start

    • Check for SELinux restrictions and disable temporarily for testing:
      sudo setenforce 0
      
  2. 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
      
  3. 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.

5 - How to Configure iSCSI Initiator on AlmaLinux

Learn how to configure an iSCSI initiator on AlmaLinux. This detailed guide covers setup, discovery, and troubleshooting for seamless network storage access.

Here’s a detailed blog post on configuring an iSCSI initiator on AlmaLinux. This step-by-step guide ensures you can seamlessly connect to an iSCSI target.


How to Configure iSCSI Initiator on AlmaLinux

The iSCSI (Internet Small Computer Systems Interface) protocol is a popular solution for accessing shared storage over a network, offering flexibility and scalability for modern IT environments. Configuring an iSCSI initiator on AlmaLinux allows your system to act as a client, accessing storage devices provided by an iSCSI target.

In this guide, we’ll walk through the steps to set up an iSCSI initiator on AlmaLinux, including prerequisites, configuration, and troubleshooting.


What is an iSCSI Initiator?

An iSCSI initiator is a client that connects to an iSCSI target (a shared storage device) over an IP network. By using iSCSI, initiators can treat remote storage as if it were locally attached, making it ideal for data-intensive environments like databases, virtualization, and backup solutions.


Step 1: Prerequisites

Before starting, ensure the following:

  1. System Requirements:

    • AlmaLinux 8 or later.
    • Root or sudo access to the system.
  2. Networking:

    • The iSCSI target server must be accessible via the network.
    • Firewall rules on both the initiator and target must allow iSCSI traffic (TCP port 3260).
  3. iSCSI Target:


Step 2: Install iSCSI Initiator Utilities

Install the required tools to configure the iSCSI initiator:

sudo dnf install iscsi-initiator-utils -y

Verify the installation:

iscsiadm --version

The command should return the installed version of the iSCSI utilities.


Step 3: Configure the Initiator Name

Each iSCSI initiator must have a unique IQN (iSCSI Qualified Name). By default, AlmaLinux generates an IQN during installation. You can verify or edit it in the configuration file:

sudo nano /etc/iscsi/initiatorname.iscsi

The file should look like this:

InitiatorName=iqn.2024-12.com.example:initiator1

Modify the InitiatorName as needed, ensuring it is unique and matches the format iqn.YYYY-MM.domain:identifier.

Save and close the file.


Step 4: Discover Available iSCSI Targets

Discover the targets available on the iSCSI server. Replace <target_server_ip> with the IP address of the iSCSI target server:

sudo iscsiadm -m discovery -t sendtargets -p <target_server_ip>

The output will list available targets, for example:

192.168.1.100:3260,1 iqn.2024-12.com.example:target1

Step 5: Log In to the iSCSI Target

To connect to the discovered target, use the following command:

sudo iscsiadm -m node -T iqn.2024-12.com.example:target1 -p 192.168.1.100 --login

Replace:

  • iqn.2024-12.com.example:target1 with the target’s IQN.
  • 192.168.1.100 with the target server’s IP.

Once logged in, the system maps the remote storage to a local block device (e.g., /dev/sdX).


Step 6: Verify the Connection

Confirm that the connection was successful:

  1. Check Active Sessions:

    sudo iscsiadm -m session
    

    The output should list the active session.

  2. List Attached Devices:

    lsblk
    

    Look for a new device, such as /dev/sdb or /dev/sdc.


Step 7: Configure Persistent Connections

By default, iSCSI connections are not persistent across reboots. To make them persistent:

  1. Enable the iSCSI service:

    sudo systemctl enable iscsid
    sudo systemctl start iscsid
    
  2. Update the iSCSI node configuration:

    sudo iscsiadm -m node -T iqn.2024-12.com.example:target1 -p 192.168.1.100 --op update -n node.startup -v automatic
    

Step 8: Format and Mount the iSCSI Device

Once connected, the iSCSI device behaves like a locally attached disk. To use it:

  1. Format the Device:

    sudo mkfs.ext4 /dev/sdX
    

    Replace /dev/sdX with the appropriate device name.

  2. Create a Mount Point:

    sudo mkdir /mnt/iscsi
    
  3. Mount the Device:

    sudo mount /dev/sdX /mnt/iscsi
    
  4. Verify the Mount:

    df -h
    

    The iSCSI device should appear in the output.


Step 9: Add the Mount to Fstab

To ensure the iSCSI device is mounted automatically on reboot, add an entry to /etc/fstab:

/dev/sdX /mnt/iscsi ext4 _netdev 0 0

The _netdev option ensures the filesystem is mounted only after the network is available.


Troubleshooting Common Issues

  1. Issue: Cannot Discover Targets

    • Ensure the target server is reachable:

      ping <target_server_ip>
      
    • Check the firewall on both the initiator and target:

      sudo firewall-cmd --add-port=3260/tcp --permanent
      sudo firewall-cmd --reload
      
  2. Issue: iSCSI Device Not Appearing

    • Check for errors in the system logs:

      sudo journalctl -xe
      
  3. Issue: Connection Lost After Reboot

    • Ensure the iscsid service is enabled and running:

      sudo systemctl enable iscsid
      sudo systemctl start iscsid
      

Conclusion

Configuring an iSCSI initiator on AlmaLinux is an essential skill for managing centralized storage in enterprise environments. By following this guide, you can connect your AlmaLinux system to an iSCSI target, format and mount the storage, and ensure persistent connections across reboots.

With iSCSI, you can unlock the potential of network-based storage for applications requiring flexibility, scalability, and reliability.