Mount the remote server hard disk through NFS on CentOS

NFS (Network File System) is a protocol for sharing files and directories between different computer systems. It allows one computer system to expose part or all of its file system to other computer systems, allowing them to access the contents as if they were local files. In this blog, we will introduce how to mount the hard disk of a remote server through NFS on a CentOS system.

Step 1: Configure the remote server

On the remote server that holds the hard disk contents, the following configuration is required:

  1. Install NFS server software:

    sudo yum install nfs-utils
    
  2. Edit the NFS server configuration file /etc/exportsand add the directories to be shared and their permission settings. For example, to share /dataa directory:

    /data 192.168.1.0/24(rw,sync,no_root_squash)
    

    Here 192.168.1.0/24is the client IP range that is allowed to access, rwindicating read and write permissions, syncindicating synchronous writing, and no_root_squashallowing access as the root user.

  3. Start the NFS service and set it to start at boot:

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

Step 2: Mount the remote hard disk on CentOS

Perform the following operations on the CentOS host that needs to mount the remote hard disk:

  1. Install NFS client software:

    sudo yum install nfs-utils
    
  2. Create a local mount point, for example /mnt/remote_disk:

    sudo mkdir /mnt/remote_disk
    
  3. Use mountthe command to mount the remote hard drive. Assume that the IP address of the remote server is 192.168.1.100and the shared directory is /data:

    sudo mount -t nfs 192.168.1.100:/data /mnt/remote_disk
    
  4. Verify that the mount is successful:

    df -h   # 查看挂载点是否显示
    

Step 3: Automount Settings

In order to automatically mount the remote hard disk when the system starts, you can set the following settings:

  1. Edit /etc/fstabthe file and add a line to automatically mount the remote hard drive:

    192.168.1.100:/data /mnt/remote_disk nfs defaults 0 0
    
  2. Reload /etc/fstabthe file using the following command, making sure there are no errors:

    sudo mount -a
    

Now, you have successfully mounted the remote server's hard disk via NFS on the CentOS system. You can /mnt/remote_diskaccess the contents of the remote hard drive in the directory. Remember to modify the IP address, directory and permission settings according to your actual situation.

Step 4: Test write speed

In order to test the writing speed of the client to the server, we can use ddthe command. Execute the following command on the client:

dd if=/dev/zero of=/mnt/remote_disk/testfile bs=1M count=1000

In the above command, we create a file named testfile under the client's mount point /mnt/remote_disk, read data from /dev/zero (a virtual zero device), and write with 1MB block size input, a total of 1000 blocks are written.

After executing the above command, you can calculate the writing speed by viewing the time it takes to write the file. Additionally, you can try different block sizes and data volumes to test different write scenarios.

Guess you like

Origin blog.csdn.net/qq_39997939/article/details/132517633