Document Name:Linux service configuration document-NFS
Server Configuration:192.168.0.8-redhat-2.6.9-5.el 192.168.0.6 redhat-2.6.18-8.el5
Document address:Http://blog.chinaunix.net/u1/40306/
NFS is short for Network File System, which was first developed by Sun. Generally, NFS is widely used on cluster servers. Its biggest feature is that different machines can be connected over the network, different operating systems can share files with each other, so it can be considered as a simple file server. NFS can be regarded as an RPC service program. Before starting the RPC program, we must map the port. This is Portmap, portmap means that when the client wants to connect to the server, it must know an idle port of the server. Then, the client will request a port from the Portmap of the server, the server then tells the client that this port can be used to establish a connection. Therefore, you must start Portmap before starting NFS.
[WDS @ localhost ~] # Rpm-Qa | grep NFS & rpm-Qa | grep Portmap # Check whether the two are installed
[WDS @ localhost ~] # Vi/etc/exports # This file is the main NFS configuration file
[WDS @ localhost ~] #/Usr/sbin/exportfs # This file is an NFS shared resource command
[WDS @ localhost ~] #/Usr/sbin/showmount # view the shared directory of the remote server
[WDS @ localhost ~] #/Var/lib/nfs/xtab # NFS Log File
[WDS @ localhost ~] # Vi/etc/exports
[The shared directory you want] + IP address (parameter 1, parameter 2) [host name 2] (parameter 3, parameter 4)
Parameter List
RW: Write Permission
RO: Read-Only permission
No_root_squash: If the root user logs on to the NFS host shared directory, the permission is also root, but this is not safe.
Root_squash: If the logged-on user is root, its permissions will become nobody.
All_squash: no matter what the login user is, all users are granted anonymous permissions.
Sync: data is synchronized to the hard disk and memory.
Async: data is temporarily stored in the memory instead of written to the hard disk.
Anounid: You can set UID, but it must be the same as the uid in the/etc/passwd directory.
Anongid: Same as anonuid, but changed to group ID
Server Configuration
[WDS @ localhost ~] # Service Portmap start # first open Portmap
[WDS @ localhost ~] # Service NFS start # Enable NFS
[WDS @ localhost ~] # I iptables-F # clear firewall commands
[WDS @ localhost ~] #
For example, if I want to share the/var/www/html directory, but only allow machines with a network segment to access the network segment 192.168.0.0/24 to read or write, others can only read, then, publish a private directory/home/WDS/which is only open to 192.168.0.8.
This IP Address
[WDS @ localhost ~] # Vi/etc/exports
/Var/www/html 192.168.0.0/24 (RW) * (RO)
/Home/WDS 192.168.0.8 (RW)
Now I want machines in the * .chinaunix.com CIDR block to log on to my NFS and access my/home/WDS/. But when they are stored, I want both their UID and GID to become 40 identities.
[WDS @ localhost ~] # Vi/etc/exports
/Var/www/html 192.168.0.0/24 (RW) * (RO)
/Home/WDS 192.168.0.8 (RW)
/Home/WDS * .chinaunix.com (RW, all) squash, anounid = 40, anongid = 40)
If we modify the/etc/exports file, do we need to restart NFS? The answer is no. You only need to use exportfs to scan the/etc/exports file again and load the file from the new settings.
Syntax:
[WDS @ localhost ~] # Exportfs [-aruv]
Parameter description:
-A: All mounting (or unmounting)/etc/exports File Settings
-R: set it in the new mount/etc/exports. In addition, synchronously update the/etc/exports and/var/lib/nfs/xtab content.
-U: unmount a directory
-V: displays the shared directory on the screen during export.
For example:
[WDS @ localhost ~] # Exportfs-RV all re-export once
[WDS @ localhost ~] # Detach exportfs-Au
Showmount is used to check whether mounting exists.
Syntax:
[WDS @ localhost ~] # Showmount [-AE] hostname
Parameter description:
-A: displays the status of directories used after connecting to the current client on the screen.
-E: displays the shared information in/etc/exports of the hostname host.
[WDS @ localhost log] # showmount-e localhost
Export list for localhost:
/Var/www/html (everyone)
Rpcinfo [-p] hostname [or IP]
-P: display port and program information
[WDS @ localhost log] # rpcinfo-P localhost
Program vers proto Port
100000 2 TCP 111 Portmapper
100000 2 UDP 111 Portmapper
100024 1 udp 1024 status
100024 1 tcp 1024 status
100011 1 udp 837 rquotad
100011 2 UDP 837 rquotad
100011 1 tcp 840 rquotad
100011 2 TCP 840 rquotad
100003 2 UDP 2049 NFS
100003 3 UDP 2049 NFS
100003 4 UDP 2049 NFS
100003 2 TCP 2049 NFS
100003 3 TCP 2049 NFS
100003 4 TCP 2049 NFS
100021 1 udp 1026 nlockmgr
100021 3 UDP 1026 nlockmgr
100021 4 UDP 1026 nlockmgr
100021 1 tcp 1026 nlockmgr
100021 3 TCP 1026 nlockmgr
100021 4 TCP 1026 nlockmgr
100005 1 udp 858 mountd
100005 1 tcp 861 mountd
100005 2 UDP 858 mountd
100005 2 TCP 861 mountd
100005 3 UDP 858 mountd
100005 3 TCP 861 mountd
ClientTerminal settings
After the server is configured, connect the client to the server! To connect to the server, follow these steps:
1. Scan the available server directory:
2. Create a mount point on the client
3. Use the mount command to remotely mount the remote shared directory
4. Solve possible problems (filtered out by the firewall)
Showmount is used to display resources shared by remote hosts.
[WDS @ localhost ~] # Showmount-e 192.168.0.8
Export list for 192.168.0.8:
/Var/www/html (everyone)
/Home/WDS * .chinaunix.com, 192.168.0.6
[WDS @ localhost ~] # Mount-t nfs 192.168.0.8:/var/www/html/mnt mount remote/var/www/html to local
[WDS @ localhost ~] # Umount/mnt unmount the remote directory
If you want to automatically load the NFS server export directory at startup, add the following line to the NFS/etc/fstab file:
192.168.0.8:/var/www/html/mnt NFS rsize = 8192, wsize = 8192, timeo = 14, Intr