Server
(First make sure you can ping and the firewall is turned off)
1.Install the software
yum install -y samba samba-client nfs-utils
2. Configure the port (optional)
The default is as shown in the figure:
vim/etc/sysconfig/nfs
3. Create a shared directory
mkdir /shared
chmod 777 /shared
4.Set shared file permissions
vi /etc/exports
Add a line to the file: /home/nfs_dir *(rw,sync,no_root_squash,no_subtree_check)
Analysis:
/home/example/rootfs -->Shared folder path
192.168.2.* -->The IP number that allows access, of course, you can also specify one, such as 192.168.2.11, * means no limit
(rw,sync,no_root_squash) -->Permissions, etc.
PS: If you want to mount multiple directories, the method is the same
/home/nfs_dir_1 *(rw,sync,no_root_squash,no_subtree_check)
/home/nfs_dir_2 *(rw,sync,no_root_squash,no_subtree_check)
NFS server configuration parameter description:
ro: shared directory read-only
rw: The shared directory is readable and writable
all_squash: All access users are mapped to anonymous users or user groups
no_all_squash (default): Access users are first matched with local users, and then mapped to anonymous users or user groups after matching fails.
root_squash (default): Map the visiting root user to an anonymous user or user group
no_root_squash: The visiting root user maintains root account permissions
anonuid=<UID>: Specifies the local user UID of the anonymous access user, the default is nfsnobody (65534)
anongid=<GID>: Specifies the local user group GID of the anonymous access user, the default is nfsnobody (65534)
secure (default): Restrict clients to connect to the server only from TCP/IP ports smaller than 1024
insecure: Allow clients to connect to the server from TCP/IP ports greater than 1024
sync: Synchronously writes data to the memory buffer and disk, which is inefficient but can ensure data consistency.
async: save the data in the memory buffer first and write it to the disk when necessary
wdelay (default): Check whether there are related write operations, and if so, execute these write operations together, which can improve efficiency.
no_wdelay: If there is a write operation, it will be executed immediately. It should be used in conjunction with sync.
subtree_check (default): If the output directory is a subdirectory, the nfs server will check the permissions of its parent directory
no_subtree_check: Even if the output directory is a subdirectory, the nfs server does not check the permissions of its parent directory, which can improve efficiency
5. Restart nfs
service nfs restart / systemctl start nfs.service
service nfs status
6. Check the log if an error is reported
cat /var/log/messages | grep mount
7. Set up startup
systemctl enable rpcbind
systemctl enable nfs
systemctl enable nfs-lock
systemctl enable nfs-idmap
8. Set up automatic mounting at startup
vim /etc/fstab
10.19.208.170:/data/yonyou/ncc2005/nfs /data/yonyou/install/ncc2005/share nfs defaults,_rnetdev 1 1
Note: The first 1 indicates the backup file system, the second 1 indicates fsck disk detection starting from the order of /partition, and 0 indicates no detection.
_rnetdev means that the host cannot be mounted and skipped directly to avoid being unable to mount the host and unable to start.
client
1. Install the required software
yum -y install nfs-utils
showmount -e 192.168.1.13 //192.168.1.13 is the nfs server ip
2Create a directory and modify permissions
#Create mount point:
mkdir /mnt/data
chmod 777 /mnt/data //The permissions here need to be adjusted according to the actual situation. 777 permissions are too open for mounting.
3.Mount
sudo mount -t nfs 10.19.208.170:/data/yonyou/ncc2005/nfs /data/yonyou/install/ncc2005/share
4. Unmount
umount /data/yonyou/install/ncc2005/share
5. If umount prompts device is busy
fuser -mv /dev/sdc1
The -v option will print out the PID. At this time, kill it or just do this:
fuser -kmv /dev/sdc1 will kill it directly, no need to kill it separately.
Try umount again