NFS Service for Linux file sharing

Source: Internet
Author: User

The NFS network File system allows Linux hosts to share files across the network, and clients can read and write remote files as if they were local files!

1. Install NFS


Yum Install nfs-utils #其他依赖会自动安装


2. Configure NFS

NFS has only one configuration file, which is/etc/exports
Format: Shared directory host (permissions)
/home/test * (Rw,sync,no_root_squash)
Example 1:
Vi/etc/exports Edit the configuration file, add the following content
/home/test 172.16.10.51 (Rw,sync,no_root_squash)
/etc/init.d/rpcbind restart
/etc/init.d/nfs restart
[Email protected] ~]# Exportfs
/home/test 172.16.10.51
NFS Service Configuration Succeeded

Example 1:

/home/test 172.16.10.0/24 (Ro,async,no_root_squash)
/home/test * (Rw,sync,no_root_squash)
Permissions configuration parameters:
RW Read/write
RO Read Only
Async first Memory then hard drive
Sync to Hard drive
Root_squash compressed root permissions for anonymous users

No_root_squash do not compress

All_squash All users are compressed to anonymous user rights

Anonuid

3. Self-starter
Add the following services on the server to boot
Service Rpcbind Start
Service NFS Start
Chkconfig NFS On
Chkconfig Rpcbind on
4. Configure Iptables
NFS is generally used in local area networks, usually directly shutting down the firewall. If you have a higher security requirement, you may specify the ports that are used for NFS, and then add the appropriate ports to the firewall configuration.

Vi/etc/sysconfig/nfs

lockd_tcpport=32803

lockd_udpport=32769

mountd_port=892

rquotad_port=875

statd_port=662statd_outgoing_port=2020
Vi/etc/sysconfig/iptables
-A input-s 172.16.0.0/16-m state--state new-p UDP--dport 111-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p TCP--dport 111-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p TCP--dport 2049-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p TCP--dport 32803-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p UDP--dport 32769-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p TCP--dport 892-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p UDP--dport 892-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p TCP--dport 875-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p UDP--dport 875-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p TCP--dport 662-j ACCEPT
-A input-s 172.16.0.0/16-m state--state new-p UDP--dport 662-j ACCEPT
Service Iptables Restart

5. Client Connection
On the client mount, specify the mount type to NFS.

[Email protected] ~]# mount-t NFS 172.16.10.50:/home/test/mnt/

[Email protected] ~]# df-h

Filesystem Size used Avail use% mounted on

/dev/mapper/volgroup-lv_root 47G 3.0G 41G 7%/

Tmpfs 2.4G 0 2.4G 0%/dev/shm

/DEV/VDA1 477M 32M 420M 8%/boot

172.16.10.50:/home/test 47G 3.3G 41G 8%/mnt

Here is a pit, is manually mounted, once the server restarts, the mounted directory will be lost. Sometimes some infrequently used programs are easy to miss while maintaining. So it's a good idea to add the Mount command to boot.
Vi/etc/rc.local
Mount-t NFS 172.16.10.50:/home/test/mnt/

Note:
One of the more troublesome parts of NFS is file permissions. The above example is all executed as root, and does not have the ability to compress root, can use the above configuration in intranet or test environment, but it is still not very safe.
NFS recognition of the user is through the UID, when the client UID and the account and the server side UID and account is not on, the operation of the file may be problematic. A more secure approach is to use NIS services to authenticate users, or to lazily add a single user and specify the same UID on all machines that plan to use NFS before configuring NFS services.


NFS Service for Linux file sharing

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.