Home  >  Article  >  Operation and Maintenance  >  How to set up network storage (like NFS) on Linux

How to set up network storage (like NFS) on Linux

WBOY
WBOYOriginal
2023-07-05 15:39:071858browse

How to set up network storage (such as NFS) on Linux

Introduction:
NFS (Network File System) is a protocol that allows files to be shared on the network. It allows multiple Linux servers to share files over the network, providing efficient file access and data sharing. This article will introduce how to set up NFS on Linux to build network storage.

Step 1: Install NFS server software

First you need to install NFS server software on the server. On most Linux distributions, it can be installed through a package manager. Taking Ubuntu as an example, you can install it with the following command:

sudo apt-get install nfs-kernel-server

Step 2: Create a shared directory

Next, we need to select a directory as the shared directory. You can select an existing directory or create a new one. Taking the new directory as an example, you can use the following command to create a directory named nfs_share:

sudo mkdir /nfs_share

Step 3: Configure the NFS server

Before configuring the NFS server, we need to edit/ etc/exports file to specify the shared directory and access permissions. Open the terminal and enter the following command to edit the /etc/exports file:

sudo nano /etc/exports

In the open file, add the following content:

/nfs_share *(rw,sync,no_root_squash,no_subtree_check)

hererw means allowing read and write permissions, sync means synchronous writing, no_root_squash means allowing root user access, no_subtree_check means turning off subdirectory checking. If you need to restrict access, you can adjust this as needed.

Save and close the file.

Step 4: Reload the configuration

After the configuration is completed, you need to reload the NFS server configuration. Enter the following command in the terminal:

sudo exportfs -r

Step 5: Start the NFS server

Enter the following command to start the NFS server:

sudo systemctl start nfs-server

Step 6: Configure the NFS client

NFS client software also needs to be installed on the client. Taking Ubuntu as an example, you can install it through the following command:

sudo apt-get install nfs-common

Step 7: Mount the NFS shared directory

On the client, use the following command to mount the NFS shared directory:

sudo mount server_ip:/nfs_share /mnt

Here server_ip is the IP address of the NFS server, /nfs_share is the path to the shared directory, and /mnt is the path to the mount point. Other suitable mount points can be selected as needed.

Step 8: Test the NFS share

On the client, use the following command to test whether the NFS share is normal:

cd /mnt
touch testfile

If no error message appears, it means the NFS share The configuration has been successful.

Note:

  1. Ensure that the network connection between the server and the client is normal.
  2. Pay attention to the access permissions when configuring the NFS server to ensure security.
  3. If you want to implement automatic mounting, you can add the corresponding entries in the /etc/fstab file.

Summary:

NFS is a very convenient and efficient network storage solution that can share files between Linux servers. This article describes the steps to set up NFS on Linux and provides corresponding code examples. Hope this article helps you!

The above is the detailed content of How to set up network storage (like NFS) on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn