Install and Configure NFS servers in Ubuntu

Source: Internet
Author: User

Install and Configure NFS servers in Ubuntu

As the lab project needs to establish NFS on CephFS, record the installation and configuration process of the NFS server in the Ubuntu environment.

1. Introduction to the NFS service:
NFS is short for Network File System. It is a distributed File System protocol developed by Sun 1984. Its core function is to allow different clients to access the common file system through the network to share files. For example, many other protocols are built on the Remote Procedure Call (RPC) of open network computing. NFS is an open standard defined in RFC that allows anyone to implement the Protocol.

The NFS server allows the client to directly mount the directories shared by remote NFS servers to local machines. Local machines can synchronize to the NFS server by Directly Reading and Writing the mounted directory.

Version change
NFS V2
2 is one of the earliest versions of NFS, and a stateless server version is implemented based on UDP protocol. It only supports 32-bit systems and files not larger than 2 GB.
NFS V3
Version 3 has been greatly improved based on version 2. Supports file reads and writes larger than 2 GB, uses the TCP protocol for data interaction, and supports asynchronous reads and writes on the client to improve the performance of the file system (It also produces a headache for us)
NFS V4
Version 4 improves security, implements a stateful server version through the TCP protocol, and implements read/write synchronization between multiple clients through the lock lease mechanism. In version 4.1, pNFS is introduced to provide a parallel distributed file system through a similar HDFS architecture.

2. system environment:
System Platform: Ubuntu 14.04

NFS Server IP: 192.168.1.2

Disable iptables: Firewall is disable. (NFS port usage is not fixed by default. Therefore, if you need to configure an NFS server with a Firewall, configure a fixed port)

SELINUX = disabled

3. NFS Server installation:
To install NFS, you only need to install rpcbind and nfs-server to provide external services.

Rpcbind
NFS services are implemented through RPC. To use NFS services normally, you need to start rpcbind to implement port ing. Run the following command to install and start rpcbind:

Sudo apt-get install rpcbind

Nfs-kernel-server
Provides nfs server software and complete file system functions. Note that the NFS server will directly use the kernel module, so the kernel must support NFS. If the OS version is a self-compiled kernel, pay attention to compiling NFS Kernel support.

Sudo apt-get install nfs-kernel-server

4. NFS Server Configuration:
The main configuration file of the NFS server is/etc/exports. However, this configuration file may not exist. You may need to use vim to create this file.

The/etc/exports file is composed of the following options:

[Shared directory] [host name or IP address (parameter, parameter)]
At the beginning of each line is the directory to be shared. The directory can be shared to different hosts according to different permissions. If there are more than one permission parameter, separate them with commas. The Host Name and parentheses are connected! The parameters are optional. If no parameter is specified, nfs uses the default option. The default sharing options are sync, ro, root_squash, and no_delay. If the host name or IP address is empty, it means that the shared IP address is used by any client to provide services.

Below are some common NFS sharing parameters:

Access permission options

Set output directory read-only: ro
Set output directory read/write: rw
User ing options

All_squash: maps all common users and groups remotely accessed to anonymous users or user groups (nfsnobody );
No_all_squash: returns an inverse value from all_squash (default );
Root_squash: maps root users and groups to anonymous users or user groups (default );
No_root_squash: returns the inverse of rootsquash;
Anonuid = xxx: maps all remotely accessed users to anonymous users and specifies the user as a local user (UID = xxx );
Anongid = xxx: maps all remotely accessed user groups to anonymous user group accounts, and specifies this anonymous user group account as a local user group account (GID = xxx );

Other options

Secure: restrict the client to connect to the nfs server from a TCP/IP Port less than 1024 (default );
Insecure: allows the client to connect to the server from a TCP/IP Port greater than 1024;
Sync: write data synchronously to the memory buffer and disk, which is less efficient, but can ensure data consistency;
Async: stores data in the memory buffer before writing data to the disk if necessary;
Wdelay: Check whether there are related write operations. If yes, execute these write operations together to improve the efficiency (the default setting );
No_wdelay: if there is a write operation, it will be executed immediately and should be used with sync;
Subtree: If the output directory is a sub-directory, the nfs server checks the permissions of its parent directory (default );
No_subtree: even if the output directory is a sub-directory, the nfs server does not check the permissions of its parent directory, which improves efficiency;

The NFS v3 configuration is used here, as shown in:

5. Start the NFS server:
After configuring/etc/exports, start the NFS server.

To enable the NFS server to work properly, you need to start the rpcbind and nfs-kernel-server services, and the rpcbind must be started before the nfs-kernel-server.

Sudo service rpcbind start
Sudo service nfs-kernel-server start

To enable the nfs service, you can use sysv-rc-conf to configure the service.

Sudo sysv-rc-conf -- level 35 rpcbind on
Sudo sysv-rc-conf -- level 35 nfs-kernel-server on

6. Mount the NFS client:

It is very easy to mount the client. first create a mount directory

Sudo mkdir/mnt/nfs
Sudo mount-t nfs 192.168.12:/tmp/mnt/nfs

Then, the corresponding file system is mounted to the file directory corresponding to the client.

7. Start automatic mounting of the NFS file system:
The client can use commands to configure the NFS-mounted file system.

Format:
<Server>: </remote/export> </local/directory> nfs <options> 0 0
Mount-t nfs 192.168.12:/tmp/mnt/nfs
Add it to/etc/rc. d/local. Do not try to mount it directly in/etc/fstab/

Cause analysis:
In the Linux kernel startup process, the network is started after the local file system is mounted, so when you try to mount NFS directly using/etc/fstab, the system has not started the network, it cannot be mounted successfully.

Summary: the installation and configuration of the NFS server under Ubuntu are summarized. Of course, the release of the RedHat series is similar. If you have any omissions, please give me some advice.

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151384.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.