Linux configuration NFS shared file system

Introduction to NFS

NFS is the abbreviation of Network File System. Different operating systems and different hosts can share resources (files or directories) with each other through the TCP/IP network.
NFS relies on the RPC (remote Procedure Call) protocol during file transfer or information transfer. The RPC protocol is a mechanism that enables clients to execute programs in other systems. NFS itself does not provide protocols and functions for information transmission.
The relationship between NFS and RPC Simply put, NFS is a file system, and RPC is responsible for the transmission of information

NFS service installation

Server

# 安装nfs-utils和rpcbind
yum -y install nfs-utils rpcbind
# 启动nfs和rpc服务并加入开机启动
systemctl enable rpcbind nfs --now
# 查看端口注册信息
rpcinfo -p localhost

insert image description here

client

# 安装nfs-utils和rpcbind
yum -y install nfs-utils
systemctl enable  nfs --now

NFS configuration

Create a shared directory on the server

# 创建共享目录
mkdir -p /data/share
# 给共享文件夹赋权
chmod 777 /data/share/
# 修改配置文件
vim /etc/exports
# 共享目录 授权挂载网段 挂载权限
/data/share 192.168.1.0/24(rw,sync,no_root_squash)
# 设置完挂载目录后需要重新加载下nfs配置文件
systemctl reload nfs

Commonly used NFS mount parameters

parameter illustrate
ro read-only access
rw read and write access
sync When data is written to memory, save data to disk at the same time
all_squash No matter which user the NFS client accesses as, it is mapped to the nfsnobody user of the NFS server
no_all_squash No matter what user is used, the permissions are not compressed, and the UID and GID of the shared file are reserved (default)
root_squash When the NFS client accesses as the root user, it is mapped to the nfsnobody user of the NFS server
no_root_squash When the NFS client accesses as root, it is mapped to the root user of the NFS server, that is, permissions must be reserved for the super user. This option will leave serious security risks and is generally not recommended
anunuid=“ ” Specifies the UID of the anonymous user of the nfs server
anonid=“ ” Specifies the GID of the anonymous user of the nfs server

View NFS shared directory

Test on the server

showmount -e localhost

insert image description here

Test on the client

showmount -e 192.168.1.200

insert image description here

NFS mount and use

Go to the client to mount the shared directory

# 此挂载方式是临时挂载机器一重启挂载就会丢失。
mount 192.168.1.200:/data/share /data/
     #服务端IP:共享目录          #挂载到本地那个目录

view mount

#df -Th|grep nfs

insert image description here
Unmount the mount directory

umount /data

insert image description here

Permanently mount the shared directory

The mount directory needs to be written into the /etc/fstab file to achieve permanent mount

vim /etc/fstab
192.168.1.200:/data/share       /data                  nfs     defaults        0 0

In this way, even if the server restarts, the directory can be automatically mounted

Guess you like

Origin blog.csdn.net/Habo_/article/details/128204549