![](/style/images/good.png)
![](/style/images/bad.png)
Linux系统nfs共享文件夹的配置
source link: https://www.51cto.com/article/722848.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Linux系统nfs共享文件夹的配置
![6476d1367bd08f426f524599b525cbee3117d6.jpg](https://s4.51cto.com/oss/202211/16/6476d1367bd08f426f524599b525cbee3117d6.jpg)
服务端配置
安装nfs-utils和rpcbind
检查下面的包是否已经安装
- nfs4-acl-tools-0.3.3-6.el6.x86_64.rpm
- nfs-utils-1.2.3-39.el6.x86_64.rpm
- nfs-utils-lib-1.1.5-6.el6.i686.rpm
- nfs-utils-lib-1.1.5-6.el6.x86_64.rpm
- rpcbind-0.2.0-11.el6.x86_64
没有安装的情况下,如果虚拟机可以连外网,则使用下面的命令进行安装
yum install nfs-utils rpcbind
没有安装的情况下,如果虚拟机不可以连外网,则使用下面的命令进行安装:
1)需要先将安装盘挂载到/mnt目录
将操作系统的安装包CentOS-6.5-x86_64-bin-DVD1.tar.gz传到mnt目录,然后解压
cd /mnt/Packages
2)使用下面的命令进行安装
- rpm -iv example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息;
- rpm -ivh example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息及安装进度;
设置开机启动服务
chkconfig nfs on
chkconfig rpcbind on
chkconfig iptables off
启动相关服务
service rpcbind restart
service nfs restart
service iptables stop
创建共享目录
mkdir -p /opt/apps_share
编辑/etc/exports文件添加如下内容
vi /etc/exports
/opt/apps_share *(rw,sync,root_squash)
意思就是192.168.21的网段在/test目录下有读和写的权限,当然还有其他很多权限:
w:read-write,可读写;
ro:read-only,只读;
sync:文件同时写入硬盘和内存;
async:文件暂存于内存,而不是直接写入内存;
no_root_squash:NFS客户端连接服务端时如果使用的是root的话,那么对服务端分享的目录来说,也拥有root权限。显然开启这项是不安全的。
root_squash:NFS客户端连接服务端时如果使用的是root的话,那么对服务端分享的目录来说,拥有匿名用户权限,通常他将使用nobody或nfsnobody身份;
all_squash:不论NFS客户端连接服务端时使用什么用户,对服务端分享的目录来说都是拥有匿名用户权限;
anonuid:匿名用户的UID值,通常是nobody或nfsnobody,可以在此处自行设定;
anongid:匿名用户的GID值。
刷新配置立即生效
exportfs -a
chown 760 /opt/apps_share
chgrp /opt/apps_share
客户端配置
设置开机启动服务
chkconfig nfs on
chkconfig rpcbind on
chkconfig iptables off
启动相关服务
service rpcbind restart
service nfs restart
service iptables stop
创建共享目录
mkdir -p /opt/apps_share
查看共享目录
showmount -e 192.168.21.14
下面这种显示目录的结果就是正确的
mount -t nfs 192.168.21.14: /opt/apps/idifile /opt/apps/idifile
检查共享目录挂载情况
输入df –h 命令查看
下面显示IP目录的就是共享的说明共享成功
![f61db479183b1112e9b3059ee6dea136fc6780.jpg](https://s6.51cto.com/oss/202211/16/f61db479183b1112e9b3059ee6dea136fc6780.jpg)
开机自动挂载
vi /etc/fstab最后一行加入
10.0.25.3:/opt/apps_share insecure,rw,async,no_root_squash 0 1
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK