返回列表 发帖

[转帖]liunx 下 NFS 服务 配置教程

nfs配置教程 -------------------------------------------------------------------------------- NFS 24.1 Overview File sharing service. RPC based service, so it requires Portmap. Packages: nfs-utils Provides: nfsd - Provides userland portion of NFS service. lockd - NFS lock manager (kernel module) rpciod - rpc.mountd - Provides mounting services. rpc.rquotad - Returns quota information. rpc.statd - Used by lockd to recovery locks after a server crash. portmap Provides portmap program. Portmap maps calls made by other hosts to the correct RPC service. Because portmap is compiled with tcp wrappers support (libwrap), those that need to access portmap must be given access via /etc/hosts.allow and/or /etc/hosts.deny. Ports TCP/UDP 111 - portmap UDP 2049 - nfsd The other NFS related services vary in the port numbers they use. Clients contact portmap to find out the port number the other RPC services use. Required Services Listed in startup order: NFS Server portmap nfs NFS Client portmap nfslock 24.2 Configuration /etc/exports NFS server configuration file. Format: (options) (options) ...... It is critical that there not be any spaces between the host/network and it';s options. Example: # Allow all hosts in the somewhere.com domain to mount /var/ftp/pub read-only /var/ftp/pub *.somewhere.com(ro) # Allow all hosts to mount /var/www/html read-only and allow certain hosts # mount it read-write /var/www/html *(ro) 192.168.1.0/255.255.255.0(rw) 192.168.2.10(rw) # Allow certain hosts to mount /usr read-only and another read-write as root /usr 172.16.0.0/255.255.0.0(ro) 172.16.1.10(rw,no_root_squash) # Allow access to /usr/local by everyone, but only as the anonymous user /usr/local *(ro,all_squash,anonuid=100,anongid=100) Restrictions Root can';t mount an nfs share as root unless no_root_squash is used. Normally when root mounts a share, NFS maps root to the local user nobody. You can';t export a directory that is a parent or child of another exported directory within the same file system. e.g. You can';t export both /usr and /usr/local unless /usr/local is a separate file system. Common Export Options no_root_squash - Remote hosts can access local shares as root (Dangerous!) ro - Read-only rw - Read/Write sync - All file system writes must be committed to disk before the request can be completed. all_squash - All remote users are mapped to a local anonymous user. anonuid - Specify the uid to user for anonymous access. anongid - Specify the gid to user for anonymous access. /etc/fstab Used for NFS client configuration Example: server:/usr /usr nfs user,soft,intr,rsize=8192,wsize=8192 0 0 Common NFS related mount options soft - Processes return with an error on a failed I/O attempt hard - If a process tries to access an unavailable share, it will hang until data is retrieved. intr - Allows NFS requests to be interrupted or killed if the server is unreachable nolock - Disable file locking in order to work with older NFS servers rsize - Sets the number of bytes NFS reads from a share at one time (default 1024) wsize - Sets the number of bytes NFS writes to a share at one time (default 1024) * Setting rsize and wsize to 8192 greatly increases performance. 24.3 Auto Mounting NFS shares Requires autofs package to be installed. Create entry in /etc/auto.misc for the NFS share: ftp -fstype=nfs,intr,soft 192.168.1.20:/var/pub/ftp If the default autofs setup is used, whenever someone accesses /misc/ftp, the remote NFS share on 192.168.1.20 will be automatically mounted. The options specified in the /etc/auto.misc have the same meaning as when they are used in /etc/fstab. 24.4 NFS Utilities exportfs Used to maintain the table of exported file systems. Example Usage: exportfs -r # Refresh the share listing after modifying /etc/exports. # This MUST be done in order for your changes to take effect. exportfs -v # Display a list of shared directories exportfs -a # Exports all shares listed in /etc/exports # To export a filesystem not in /etc/exports exportfs 192.168.1.0/255.255.255.0:/tmp # Unexport a filesystem exportfs -u 192.168.1.0/255.255.255.0:/tmp showmount Show mount information for an NFS server. Does not require that any local NFS services be running in order to use it. Example Usage: showmount -e 192.168.1.67 # Shows available shares on host 192.168.1.67 showmount -a 192.168.1.67 # Shows the clients connected to host 192.168.1.67 # and the shares they have mounted. rpcinfo Reports RPC information. Can determine if RPC services are running on a host. Example Usage: rpcinfo -p 192.168.1.77 # Display list of RPC services running on 192.168.1.77

返回列表 回复 发帖