Network File Sharing Service-NFS

Source: Internet
Author: User
NFS service
NFS: Network File System: A kernel-based file system. Developed by Sun, with NFS, users and programs can access files on the remote system just like accessing local files. RPC is implemented based on Remote Procedure Call Protocol Remote Procedure Call: the C/S mode is used. The client requests the calling process to send a call information with process parameters to the service process, and then waits for the response information. On the server side, the process remains sleep until the call information reaches. When a call Information arrives, the server obtains the process parameters, calculates the results, sends the reply information, and waits for the next call Information. Finally, the client calls the process to receive the reply information and obtain the process results, next, call and execute to continue with the NFS advantages: saving local storage space and storing commonly used data, such as the home directory, on the NFS server and accessible through the network, the local terminal can reduce the use of its own storage space
NFS File System

Comparison of NFS versions

NFS service Introduction
? Software Package: nfs-utils? Kernel support: NFS. Ko? Port: 2049 (nfsd). Other ports are allocated by Portmap (111? Configuration File:/etc/exports,/etc/exports. d/*. Exports? Centos7 does not support NFS and Samba sharing in the same directory because the locking mechanism is different? Related Software Packages: rpcbind (required), TCP_WRAPPERS? In centos6, The Portmap Process is replaced by rpcbind? Main processes of the NFS service: RPC. the most important NFS process of NFSD is to manage whether the client can log on to RPC. MOUNTD mounts and unmounts NFS file systems, including permission management RPC. lockd is not necessary to manage file locks to avoid simultaneous RPC writing errors. STATD is not necessary. Check file consistency. Can files be repaired? Log:/var/lib/nfs/
Configure Firewall
? Configure the firewall and enable the NFS service (which is required for centos 6 and not required for centos 7 )? Configure NFS to use a fixed port? Vim/etc/sysconfig/nfs rquotad_port = 875 lockd_tcpport = 32803 lockd_udpport = 32769 mountd_port = 892 statd_port = 662 statd_outgoing_port = 2020? In addition to opening the above ports, the firewall also needs to open TCP and UDP ports 111 and 2049.
NFS configuration file
1. Format of the exported file system:/dir host 1 (opt1, opt2) Host 2 (opt1, opt2 )... 2. # Start with comment 3. Host format: single host: IPv4, IPv6, and fqdn ip networks: both mask formats support 172.18.0.0/255.255.255.0.0 172.18.0.0/16 wildcards: Host Name configuration, for example, * .magedu.com, the IP address cannot be netgroups: The Host group of the NIS domain, @ group_name anonymous: indicates using * to configure all clients. 4. Each entry specifies the hosts to which directories are exported, and Related permissions and options default options: (RO, sync, root_squash, no_all_squash) Ro, RW read-only and read/write async asynchronous, do not write disk immediately after data changes, high-performance sync (default after 1.0.0) synchronization. Data is immediately written to the shared no_all_squash (default) upon request. The UID and GID all_squash of the shared file are retained for all remote users (including root) all are changed to nfsnobody root_squash (default) remote root ing is nfsnobody, uid is 65534, and earlier versions are 4294967294 (nfsnobody) no_root_squash remote root ing to the root user anonuid and anongid indicates that the anonymous user maps to the specific user UID and group GID instead of the nfsnobody, which can be used with all_squash
NFS tools
Rpcinfo-P hostname rpcinfo-s hostname view RPC registration program exportfs-V view all NFS shares on the local machine-r reread the configuration file, and shared directory-A outputs all shares of the Local Machine-Au stops all shares of the Local Machine showmount-e hostnamemount. NFS mounting tool nfsv4 allows you to mount the NFS server's shared root to view the list of shared directories on the NFS server. Mount nfsserver: // MNT/nfs
Client NFS mounting
For security considerations, we recommend that you use the NFS-related mounting options of nosuid, nodev, and noexec: FG (default) Foreground mounting, and BG background mounting hard (default) persistent requests, soft non-continuous request intr and hard cooperation, the request can interrupt the maximum number of bytes of rsize and wsize for one read and write data, rsize = 32768 _ netdev no network not mounted example: Mount-o rw, nosuid, FG, hard, Intr 192.168.137.56:/testdir/mnt/nfs/boot mount:/etc/fstab 192.168.137.56:/public/mnt/nfs NFS defaults 0 0
Simple NFS example
Install the NFS service [[email protected] ~] # Yum-y install nfs-utils to create a shared directory [[email protected] ~] # Mkdir/data/volume {1 .. 6} create a shared configuration file [[email protected] ~] # Vim/etc/exports. d/volume1.exports/data/volume1 192.168.137.0/24 (RO) start the service [[email protected] ~] # Systemctl start NFS client test, but the client also needs to install the corresponding tool [[email protected] ~] # Yum-y install nfs-utils on the client to check which mounting methods are available on the server [[email protected] ~] # Showmount-e 192.168.137.56 export list for 192.168.137.56:/data/volume1 (everyone) mount the shared directory of the server to the Local Machine [[email protected] ~] # Mount-t nfs 192.168.137.56:/data/volume1/mnt Add/data/volume1 ACL permissions to ilinux on the server, and then switch to ilinux, create a test file on/data/volume1 [[email protected] ~] # Setfacl-m u: ilinux: rwx/data/volume1 [[email protected] ~] # Su-ilinux [[email protected] ~] $ CD/data/volume1/[[email protected]/data/volume1] $ ls [[email protected]/data/volume1] $ touch a.txt [[email protected]/data/ volume1] $ ll total 0-RW-r -- 1 ilinux 0 Oct 23 a.txt client view the file you just created on the server and test whether you have write permission [[ email protected]/mnt] # ll total 0-RW-r -- 1 1001 1001 0 Oct 23 a.txt [[[email protected]/mnt] # Touch 1 touch: cannot touch '1': Read-Only file system: Modify the server shared directory permission and update [E Mail protected] ~] # Vim/etc/exports. d/volume1.exports/data/volume1 192.168.137.0/24 (RW) # exportfs-rav is equivalent to systemctl reload NFS [[email protected] ~ Exportfs-RAVs exporting 192.168.137.0/24:/data/volume1 client test write permission, create a local user with the same user ID on the server [[email protected]/mnt] # useradd-u 1001 user1 [[email protected]/mnt] # ID user1uid = 1001 (user1) gid = 1001 (user1) groups = 1001 (user1) [[email protected]/mnt] # Su-user1 [[email protected] ~] $ CD/mnt/[[email protected]/mnt?$lsa.txt [[[email protected]/mnt] $ echo "first line"> a.txt # Check whether the owner and owner group are user1. the real user is the ilinux user on the server, but they only have the same ID number. After V4, they can recognize strings with the same name, but it still cannot solve the same ID number as [[email protected]/mnt] $ ll total 4-rw-rw-r -- 1 user1 0 Oct 23 19 2-rw-rw-r -- 1 user1 user1 11 Oct 23 a.txt Allow client root users [email protected] ~] # Vim/etc/exports. d/volume1.exports/data/volume1 192.168.137.0/24 (RW, no_root_squash) Reload the configuration [[email protected] ~] # Exportfs-RAVs test [[email protected]/mnt] # Touch 1 [[email protected]/mnt] # rm-RF 1 [[email protected]/mnt] # touch. root [[email protected]/mnt] # Use the shared directory on the server on the client to act as the data storage path of the database [[email protected]/mnt] # Yum-y install mariadb-Server modify the database configuration file and change the data storage path to [[email protected]/mnt] # Vim/etc/My. CNF [mysqld] datadir =/mnt/mysqlsocket =/tmp/MySQL. sockskip_name_resolve = on, create a directory, and change the owner and group to MySQL [[email protected] /Mnt] # mkdir/mnt/MySQL [[email protected]/mnt] # chown MySQL. mySQL/mnt/MySQL/then start the database service, view the MNT/MySQL directory [[email protected]/mnt] # systemctl start mariadb [[email protected]/mnt] # ls MySQL/aria_log.00000001 ibdata1 ib_logfile1 performance_schemaaria_log_control ib_logfile0 MySQL test ing Anonymous Users example of a specified user: [[email protected]/data/volume1] # Vim/etc/exports. d/volume1.exports/data/volume1 192.168.137.0/24 (RW, all_s Quash, anonuid = 1001, anongid = 1001) re-export the configuration file [[email protected]/data/volume1] # create a user on the exportfs-ra client, then, use the new user to create a file to verify the permissions set on the server [[email protected]/mnt] # useradd user2 [[email protected]/mnt] # Su-user2 [[email protected] ~] $ CD/mnt/[[email protected]/mnt] $ touch user2.txt [[email protected]/mnt] $ [[email protected]/mnt] $ ll total 4-RW- RW-r -- 1 user1 user1 0 Oct 23 2-RW-r -- 1 Root 0 Oct 23. root-RW-r -- 1 user1 user1 11 Oct 23 a.txt drwxr-XR-x 5 MySQL 159 Oct 23 mysql-RW-r -- 1 user1 user1 0 oct 23 root. b-RW-r -- 1 user1 user1 0 Oct 23 14:55 user2.txt

Network File Sharing Service-NFS

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.