NFS (Network File System) file sharing for linux
Step 1: Configure the required environment
Use two Linux hosts
Host Name | operating system | IP addresses |
NFS | Centos7 | 192.168.218.139 |
FSA | Centos7 | 192.168.218.140 |
Configure yum source, install nfs service nfs server on empty iptables firewall default policy.
[root@NFS ~]# yum install nfs-utils -y
Step 2: Create a directory for NFS file sharing on the NFS server, and set up sufficient permissions to ensure that other people have written permission.
[root@NFS ~]# mkdir /nfs
[root@NFS ~]# chmod -Rf 777 /nfs
[root@NFS ~]# echo "Welcome to purple" > /nfs/hello
Step 3: Edit NFS service program configuration file / etc / exports.
Configuration parameters NFS service program profile
parameter | effect |
ro | Read-only |
rw | Read and write |
root_squash | When the NFS client access to the root administrator, mapped to the anonymous user NFS server |
no_root_squash | When the NFS client access to the root administrator, mapped to the root administrator of the NFS server |
all_squash | No matter what NFS client account access, are mapped to the NFS server anonymous users |
sync | At the same time the data is written to memory and hard drive to ensure that no data is lost |
async | Priority will save the data to memory, and then written to disk; this higher efficiency, but may lose data |
[root@NFS ~]# vim /etc/exports
/ nfs 192.168.218.0/24(rw,sync,root_squash)
Step 4: Start and start the NFS service program. Since before using the NFS file sharing service, you need to use the RPC (Remote Procedure Call, Remote Procedure Call) service sends information signals such as IP address and port the NFS server to the client.
[root@NFS ~]# systemctl restart rpcbind
[root@NFS ~]# systemctl enable rpcbind
[root@NFS ~]# systemctl start nfs-server
[root@NFS ~]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
NFS client uses the showmount command to query a remote NFS server to share information, the output format as "shared directory name allows the use of client addresses."
showmount command parameters and the role of available
parameter | effect |
-e | Display a list of shared NFS servers |
-a | Show file resources of the machine mount |
-v | It displays the version number |
[root@NFSa ~]# showmount -e 192.168.218.139
Export list for 192.168.218.139:
/nfs 192.168.218.*
In the NFS client creates a mount directory.
[root@NFSa ~]# mkdir /nfs
[root@NFSa ~]# mount -t nfs 192.168.218.139:/nfs /nfs
[root@NFSa ~]# cat /nfs/hello
Welcome to purple
Can write this boot automatically mount file
[root@NFSa ~]# vim /etc/fstab
192.168.10:/nfs /nfs nfs defaults 0 0