Introduction to Services for NFS
NFS is the network file system. The main function is to allow different servers to share files or directories across the network. NFS clients are typically application servers (such as web, load balancing, and so on) that can be mounted to mount the NFS server-side shared directory to the NFS client local directory.
NFS relies on protocol with RPC (remote procedure Call) during file transfer. NFS itself does not provide the protocol and function of transmitting information, but it can use the network to share functions such as pictures, videos, attachments and so on. The RPC service needs to be started wherever NFS is used, whether it is the server or Client of NFS.
NFS and RPC relationships: it can be understood that NFS is a network file system (likened to renting a homeowner), while RPC is responsible for the transmission (intermediary) of information, the client (equivalent to renting a tenant)
View current system Environment information
[Email protected]~]# cat/etc/issue # #查看系统版本信息 Red Hat Enterprise Linux Server Release 6.6 (Santiago) [Email Protect ed]~]# uname-r # #查看内核信息 2.6.32-754.3.5.el6.x86_64[[email protected]~]# uname-m # #查看系统是32位还是64位的 x86_64
Description
Server side: RHEL6.6 [192.168.2.131/24]
Client: RHEL6.6 [192.168.2.130/24]
Man NFS can view mount's information
RPC Port 111
NFS Primary Port 2049
Server-side configuration [192.168.2.131]
Description:
1. Before starting the NFS service, you first start the RPC service (CentOS5 is the Portmap service, CentOS6.6 later is the Rpcbind service), or the NFS server cannot register with the RPC service.
2. If the RPC service restarts, the original and some NFS ports will be lost, so as long as the RPC service restarts, the NFS service will restart to re-register the new random port number to RPC.
Required: Stop nfs-> stop rpcbind service after restarting Rpcbind-> restart NFS Service
3. After the NFS configuration file is modified, you do not need to restart the service, direct smooth restart
Command:/etc/init.d/nfs Reload or EXPORTFS-RV can modify the/etc/exports to take effect.
/etc/init.d/nfs Reload's role is: Let the request has reached the server to him, but did not reach the server's request, it broke off.
1. Viewing NFS packages [NFS and RPC are not installed by default and require Yum installation]
[Email protected] ~]# Rpm-qa nfs-utils rpcbind
2. Install the NFS software using the Yum install nfs-utils rpcbind-y command [you can check it after installation]
[Email protected]]# yum Install nfs-utils rpcbind
[Email protected]]# rpm-qa nfs-utils Rpcbind
3. Start the NFS service
First step: Start the RPC service first
[[email protected] ~]#/etc/init.d/rpcbind start #启动rpc服务 [[email protected] ~]#/etc/init.d/rpcbind status # View RPC Service Status
Step Two: Start the NFS service
[Email protected] ~]#/etc/init.d/nfs start #启动nfs服务 [[email protected] ~]#/ETC/INIT.D/NFS status #查看nfs服务状
[[email protected] ~]# Ps-ef|grep NFS | Grep-v ' grep NFS ' # [optional], view NFS Services
Note: You must start the RPC service before you start the NFS service (RPC will have port mappings), and if you start the NFS service, the service will fail
4. Viewing NFS and RPC port information [optional]
RPC Port 111
NFS Primary Port 2049
The first step: the server port checks its own RPC service:
rpcinfo-p localhost # to view the port information registered to RPC by the NFS service, the primary port number is: 111
[[email protected] ~]# Netstat-lntup|grep 111 # View 111 port information [email protected] ~]# lsof-i 4:111 # View 111 port Information
Step Two: View NFS
[Email protected] ~]# netstat-lntup|grep 2049 [[email protected] ~]# Ps-ef|grep NFS
Step Three: Check the NFS service on this machine
SHOWMOUNT-E localhost
5. Service Start-up
The first step: chkconfig Open Service
Chkconfig--list | Egrep "Nfs|rpcbind"
Step Two: Write Rc.local
Vim/etc/rc.local /etc/init.d/rpcbind start /etc/init.d/nfs start
Description: Operation and maintenance specification put the service's start command into/etc/rc.local
6. Configure the NFS server
First step: Create a shared directory (note permissions)
Mkdir/nfs-m777chown-r Nfsnobody:nfsnobody/data # Nfsnobody user created by default for NFS
Step Two: Configure the server files
NFS Default file:/etc/exports
#/etc/exports configuration file format is: # NFS shared Directory NFS client address (parameter 1, parameter 2) vim/etc/exports /data 192.168.2.130/24 (rw,sync) # One configuration for NFS config file # where:/data:nfs the actual directory to be shared on the server side, note the local permissions of the shared directory, require read and write permissions, make sure that the local directory can be read and written by the user of the NFS client #192.168.2.130/24: NFS Client Address for NFS server-side authorized accessible shared directory (can be a separate IP address or host name, domain name, address of the entire network segment) # (Rw,sync), where RW stands for read and write permissions, and sync represents data synchronously written to the NFS server side of the hard drive. It can also be used when the Async,async is big data, which is written to the buffer and then written to disk.
Optional: NFS Server Parameters
RW: Read and write RO: The client writes the data to the server, and after the successful completion of the service, a successful token is written to the client. but the data is safe, but the performance is poor async: The asynchronous write data writes to the memory to show that the write succeeds, high performance, but once the power outage data is lost, the e-commerce seconds Kill is asynchronous. Large Web sites are asynchronous and have inconsistent data for short periods of time. No_root_squash: The user who accesses the shared Directory of NFS server is root, and it has root permissions on the shared directory Root_squash: The user who accesses the shared Directory of NFS server is root, It compresses permissions for the shared directory to anonymous users all_squash: It is recommended to use shared directory permissions regardless of the NFS server that is accessed, and it compresses the permissions for that shared directory to anonymous users
Step Three: Restart the NFS service
Fourth step: Server-side testing (servers ports check their NFS services)
SHOWMOUNT-E localhost
#showmount-e 192.168.2.130 client after successful viewing
Fifth step: Test this machine (server side itself) mount
Mount-t NFS 192.168.2.131:/data/mnt
Description: View the default configuration
Cat/var/lib/nfs/etab
Other: Uninstalling network mounts
# Force Unload
UMOUNT-LF /mnt # L (lazy) f (Force)
Client configuration [192.168.2.130]
1. As with the client and server, install the NFS and RPM installation packages as well. (Configuration See server side)
2. The client needs to start the RPC service and join the boot. You do not need to start the NFS service. (Configuration See server side)
3. Client Configuration:
First step: Test whether the server/client IP is in the same network segment
Ping 192.168.2.130 # client IP
Step Two: Check if the server's port 111 is OK
Telnet 192.168.2.131 11
Step Three: Showmount server
SHOWMOUNT-E 192.168.2.131
Fourth step: Mount the server locally for file sharing
Mount-t NFS 192.168.2.131:/data//mnt
Df–h
==> cat/proc/mounts # Effect with
# cat/proc/mounts # Effect with
Fifth Step: Write Rc.local
Vim/etc/rc.local /etc/init.d/rpcbind start mount-t NFS 192.168.2.131:/data//mnt
Other: Uninstalling network mounts
# Force Unload
UMOUNT-LF /mnt # L (lazy) f (Force)
Test mounts
Build an enterprise-class NFS network file Sharing Service