Building NFS File Sharing--instance parsing

Source: Internet
Author: User

1 Introduction to NFS

NFS is the abbreviation for the network file system, which is the web filesystem. A protocol used for distributed file systems by the Sun public

Ple was released in 1984. The function is to allow different machines, different operating systems to share individual data with each other through the network.

Having the application access data on the server's disk over the network by the client is a way to implement disk file sharing.

The basic principle of NFS is "allow different clients and services to share the same file system through a set of RPCs", which is independent of the operation

system, allowing different hardware and operating system systems to share the files together.


2 Configuration of Server for NFS

Server for NFS is relatively simple to configure, just set it up in the appropriate configuration file, and then start Server for NFS.

Common Directories for NFS

/etc/exports Primary configuration file for NFS services

/USR/SBIN/EXPORTFS Management commands for NFS services

View commands for/usr/sbin/showmount clients

/var/lib/nfs/etab record full permission SetPoint for NFS-shared directory

/var/lib/nfs/xtab Logging of client information that has been logged on

The NFS service configuration file is/etc/exports, which is the primary NFS configuration file, but the system does not have a default value, so this file does not necessarily exist, it may be created manually using Vim, and then write the configuration content in the file.

/etc/exports File Content format:

< output directory > [Client 1 options (access rights, user mappings, others)] [Client 2 options (access rights, user mappings, others)]


The output directory is the directory that the NFS system needs to share with the client;

A client is a computer in the network that can access the NFS output directory;

option to set the access permissions, user mappings, and so on for the output directory.

There are 3 main types of NFS options:

Access Permissions Options

Set output Directory read-only: RO

Set output directory Read/write: RW

User mapping Options

All_squash: Maps all normal users and groups that are accessed remotely to anonymous users or user groups (Nfsnobody);

No_all_squash: Reverse with All_squash (default setting);

Root_squash: The root user and the owning group are mapped to anonymous users or groups of users (default setting);

No_root_squash: Reverse with Rootsquash;

ANONUID=XXX: Maps All remote access users to anonymous users and specifies that the user is a local user (uid=xxx);

ANONGID=XXX: Maps All remote Access user groups to anonymous user group accounts and specifies that the anonymous user group account is a local user group account (GID=XXX);

Other options

Secure: Restrict clients from connecting to Server for NFS (default setting) only from TCP/IP ports less than 1024;

Insecure: Allow clients to connect to the server from TCP/IP ports greater than 1024;

Sync: It is inefficient to write data synchronously to memory buffer and disk, but it can guarantee the consistency of data;

Async: Save the data in the memory buffer first, and write to disk if necessary;

Wdelay: Check if there is a related write operation, if any, then perform these writes together, which can improve the efficiency (default setting);

No_wdelay: If a write operation is performed immediately, it should be used in conjunction with sync;

Subtree: If the output directory is a subdirectory, the NFS server will check the permissions of its parent directory (default setting);

No_subtree: Even if the output directory is a subdirectory, the NFS server does not check the permissions of its parent directory, which can improve efficiency;


3 Example parsing

Server-side Configuration 192.168.1.6

Share the/home/web of host 192.168.1.6 with/home/data through NFS service

[Email protected] ~]# yum install-y nfs-utils rpcbind #安装nfs和rpcbind

[Email protected] ~]# rpm-qa|grep nfs-utils #查看安装结果

Nfs-utils-lib-1.1.5-11.el6.x86_64

Nfs-utils-1.2.3-70.el6_8.2.x86_64

[Email protected] ~]# rpm-qa|grep rpcbind #查看安装结果

Rpcbind-0.2.0-12.el6.x86_64


[Email protected] ~]# Mkdir/home/{web,data} #创建共享目录

[Email protected] ~]# chmod a+w/home/web #给共享目录添加写权限

[Email protected] ~]# vim/etc/exports #添加配置文件内容

/home/web 192.168.1.5 (Rw,async,no_root_squash)

/home/data 192.168.1.5 (Ro,sync)

[Email protected] ~]# /etc/init.d/rpcbind restart #重启rpc

Stop rpcbind: [OK]

Starting rpcbind: [OK]

[Email protected] ~]# /etc/init.d/nfs restart #重启nfs

Turn off the NFS daemon: [Failed]

Turn off NFS mountd: [Failed]

Turn off NFS quotas: [Failed]

Start NFS service: [OK]

Turn off NFS quotas: [OK]

Start NFS mountd: [OK]

Start the NFS daemon: [OK]

Starting RPC IDMAPD: [OK]

[Email protected] ~]# chkconfig rpcbind on #添加到开机启动

[[email protected] ~]# chkconfig NFS on


Client Operation 192.168.1.5

[Email protected] ~]# showmount-e 192.168.1.6 #查看服务器端列表

Export list for 192.168.1.6:

/home/data 192.168.1.5

/home/web 192.168.1.5

[Email protected] ~]# mkdir/web #创建挂载目录

[Email protected] ~]# mkdir/data

[[email protected] ~]# DF

Filesystem 1k-blocks used Available use% mounted on

/dev/sda3 18344828 1017808 16388476 6%/

Tmpfs 502384 0 502384 0%/dev/shm

/DEV/SDA1 95054 27170 62764 31%/boot

[Email protected] ~]# mount 192.168.1.6:/home/web/web #将服务端的共享挂载

[Email protected] ~]# Mount 192.168.1.6:/home/data/data

[[email protected] ~]# DF

Filesystem 1k-blocks used Available use% mounted on

/dev/sda3 18344828 1017812 16388472 6%/

Tmpfs 502384 0 502384 0%/dev/shm

/DEV/SDA1 95054 27170 62764 31%/boot

192.168.1.6:/home/web 18244480 6994432 10316544 41%/web

192.168.1.6:/home/data 18244480 6994432 10316544 41%/data

[[email protected] ~]# echo "192.168.1.6:/home/web/web NFS defaults 0 0" >>/etc/fstab

Setting up the Boot mount

[[email protected] ~]# echo "192.168.1.6:/home/data/data NFS defaults 0 0" >>/etc/fstab

[Email protected] ~]# chmod a+w/web #添加写权限

[Email protected] ~]# Cd/web

[[email protected] web]# ls

[Email protected] web]# mkdir test

[[email protected] web]# Touch text

[email protected] web]# LL

Total Dosage 4

Drwxr-xr-x. 2 root root 4096 January 2 16:18 test

-rw-r--r--. 1 root root 0 January 2 16:18 text


Back to Client 192.168.1.6 view

[[email protected] ~]# Cd/home/web show everything is OK

[[email protected] web]# ls

Test text


This article is from the "Practical Linux knowledge and Skills sharing" blog, please be sure to keep this source http://superleedo.blog.51cto.com/12164670/1888324

Building NFS File Sharing--instance parsing

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.