NFS (Network File System) shared storage service configuration

NFS dependencies

NFS relies on RPC (remote procedure call) to
install the nfs-untils, rpcbind software package
System service: nfs, rpcbind
shared configuration file: /etc/exports

Install nfs-untils, rpcbind packages

[root@localhost ~]# yum -y install nfs -untils rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind

Set up a shared directory

[root@localhost ~]# mkdir -p /opt/wwwroot
[root@localhost ~]# vi /etc/exports
/opt/wwwroot //共享目录  192.168.7.0/24(rw,sync,no_root_squash) //括号中为权限
/var/ftp/pub  192.168.4.11(ro) 192.168.4.110(rw)

ro: read-only permissions rw: read-write permissions
sync: open services between the server and the client
no_root_squash: indicate that the server can be accessed as root

Start the NFS service program

View the NFS shared directory published by the machine

[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# netstat -anpt| grep rpc
tcp 0   0 0.0.0.0:20048  0.0.0.0:*  LISTEN  10508/rpc.mountd
tcp 0   0 0.0.0.0:52732  0.0.0.0:*  LISTEN  10495/rpc.statd
tcp6    0 0 :::20048     :::*       LISTEN  10508/rpc.mountd
tcp6    0 :::52732       :::*       LISTEN  10495/rpc.statd
[root@localhost ~]# showmount -e
/opt/wwwroot 192.168.7.0/24
/var/ftp/pub 192.168.4.110, 192.168.4.11

Install the rpcbind package and start the rpcbind service

[root@localhost ~]# yum -y install rpcbind nfs-utils
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# showmount -e 192.168.7.250 //客户机ip
Export list for 192.168.7.250:
/opt/wwwroot 192.168.7.0/24
/var/ftp/pub 192.168.4.110, 192.168.4.11

Mount the NFS shared directory manually

[root@localhost ~]# mount 192.168.7.250:/opt/wwwroot /var/www/html
[root@localhost ~]# tail -1 /etc/mtab
192.168.7.250:/opt/wwwroot /var/www/html nfs4
rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=O,
 timeo=600,retrans=2,sec=sys,clientaddr=192.168.7.21,local_lock=none,
 addr=192.168.7.250 0 0
[root@localhost ~]# vi /var/www/html/index.html
Real Web Server Document

Fstab auto mount settings

[root@localhost ~]# vi /etc/fstab
...... //省略部分信息
192.168.7.250:/opt/wwwroot /var/www/html nfs defaults,_netdev 0 0 //设置需要网络

Force uninstall NFS

[root@localhost ~]# umount /mnt
umount:/mnt: device is busy
[root@localhost ~]# umount -lf /mnt
[root@localhost ~]# 

Sketch of NFS working principle

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_49343462/article/details/109435283