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

WBOY
Release: 2023-07-05 15:39:07
Original
1874 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

In the open file, add the following content:

/nfs_share *(rw,sync,no_root_squash,no_subtree_check)
Copy after login

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
Copy after login

Step 5: Start the NFS server

Enter the following command to start the NFS server:

sudo systemctl start nfs-server
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template