NFS(网络文件系统)共享存储服务配置

NFS依赖关系

NFS依赖于RPC(远端过程调用)
需安装nfs-untils、rpcbind软件包
系统服务:nfs、rpcbind
共享配置文件:/etc/exports

安装nfs-untils、rpcbind软件包

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

设置共享目录

[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:为只读权限  rw:为读写权限
sync:服务器与客户机间开启服务
no_root_squash:表示可以是root身份访问服务器

启动NFS服务程序

查看本机发布的NFS共享目录

[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

安装rpcbind软件包,并启动rpcbind服务

[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

手动挂载NFS共享目录

[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自动挂载设置

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

强制卸载NFS

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

NFS工作原理简图

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_49343462/article/details/109435283
今日推荐