NFS settings under Linux

NFS (Network File System ) is a network file system, which is one of the file systems supported by FreeBSD. It allows computers in the network to share resources through the TCP/IP network. In NFS applications, local NFS client applications can transparently read and write files located on remote NFS servers, just like accessing local files

 

1. List of software required by NFS server :

nfs-utils: This is the main program of the NFS service (including rpc.nfsd, rpc.mountd, daemons)

rpcbind: This is the RPC main program of CentOS6.X (portmap for CentOS5.X)

 

2. Check if the software is installed

rpm -qa nfs-utils rpcbind #Check installed packages

if there is not

yum install nfs-utils rpcbind -y

 

3. Start the software

/etc/init.d/nfs start

/etc/init.d/rpcbind start

 

4. Check the startup result

/etc/init.d/nfs status

/etc/init.d/rpcbind status

ps –ef | grep nfs | grep –v grep #The effect is the same as above

ps -ef | grep rpcbind | grep -v grep #The     effect is the same as above

netstat –ntulp | grep rpcbind #The     effect is the same as above

lsof –i:111 #rpc ’s main port ID is     111 #The effect is the same as above

 

5. Check and add boot auto-start

chkconfig | grep –E “rpcbind|nfs”

chkconfig /etc/init.d/nfs on

chkconfig /etc/init.d/rpcbind on

 

6. View the services started by rpc

rpcinfo -p localhost     

In the process of NFS service, you must start rpcbind first, and then start nfs, so that NFS can be successfully registered on rpcbind.

 

7. Check nfs and rpcbind self-starting sequence

less /etc/init.d/rpcbind #Line 5

less /etc/init.d/nfs #Line 5

< It can be seen from the above that the system will start the rpcbind service first, and then start the nfs service by default, but in the actual production environment, it is best not to use chkconfig to control the self-starting of the service. In our production environment, we generally use rc. local to manage. It is mainly to facilitate the future review of which services are turned on, and to control the sequence>

echo "/etc/init.d/nfs start" >> /etc/rc.local

echo "/etc/init.d/rpcbind start" >> /etc/rc.local

 

8. Create a shared directory and set permissions

Create /data first

mkdir /data

Change owner and group to control permissions

chown -R nfsnobody.nfsnobody /data

 

9. Configure NFS server

/etc/exports is the configuration file for NFS programs. and defaults to empty

vim /etc/exports

write:

/data 192.168.1.0/24(rw,no_root_squash,no_all_squash,sync)

/data 192.168.1.0/24(rw,sync) #The easiest configuration The effect is the same as above

Authorize the network segment 192.168.1.0/24 to access /data

Common parameters are:

Description of parameter value    content

rw   ro    The permissions shared by this directory are read-write or read-only, but whether or not they can read and write ultimately depends on the rwx and identity of the file system.

sync   async sync means that the data will be written to the memory and hard disk synchronously, async means that the data will be temporarily stored in the memory instead of being written directly to the hard disk!

no_root_squash   root_squash    If the account of the NFS file system used by the client is root, how should the system determine the identity of this account? By default, the identity of the client root will be compressed into nfsnobody by the setting of root_squash, so the system of the server will be more secure. But if you want to open the client to use the root identity to operate the server's file system, then you have to open no_root_squash here!

all_squash    Regardless of the identity of the user logging in to NFS , his identity will be compressed into an anonymous user, usually nobody (nfsnobody)!

anonuid   anongid anon means anonymous (anonymous) The UID setting value of the anonymous user mentioned above about *_squash, usually nobody (nfsnobody), but you can set the value of this UID by yourself! Of course, this UID must exist in your /etc/passwd! anonuid refers to the UID and anongid is the GID of the group.

 

10. After configuring exports, restart NFS service gracefully

/etc/init.d/nfs reload #2 commands have the same effect

exportfs –rv # 2 commands have the same effect

 

11. Test the online function

showmount -e localhost

 

12. Client Configuration

install software

yum install nfs-utils rpcbind –y

 

13. Start the software

/etc/init.d/nfs start

/etc/init.d/rpcbind start #If necessary, you can make rpcbind start automatically at boot.

chkconfig /etc/init.d/rpcbind on #optional

 

14. Create a mount directory

mkdir /xxw

 

15. Test mount

showmount -e 172.16.1.5

 

16. Mount to the created directory

mount -t nfs 172.16.1.31:/data /xxw #The easiest setup

mount -t nfs 172.16.1.8:/data /xxw -o proto=tcp -o nolock

#In order to improve the stability of NFS, use TCP protocol to mount, NFS uses UDP protocol by default

 

17. Check the mount status

df –h

 

Put the mount into autostart

echo  "mount -t nfs172.16.1.31:/data /xxw">> /etc/rc.local 

 

 

Unmount the mounted NFS

umount /xxw


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325935285&siteId=291194637