centos7实现NFS磁盘共享

本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。

NFS服务端配置
安装nfs-utils和rpcbind

yum -y update 
yum -y install nfs-utils rpcbind 

启用rpcbind,nfs-server,nfs-lock,nfs-idmap

systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap

打开NFS相关服务

systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap 

创建需要共享的目录

mkdir -p /application/share
chmod -R 777 /application/share

配置需要共享的目录到/etc/exports下,10.192.7.0/24为需要共享的对象IP地址段或者具体IP

echo "/application/share 10.192.7.0/24(rw,sync,no_root_squash,no_all_squash)"  >> /etc/exports 

服务器端的设定都是在/etc/exports这个文件中进行设定的,设定格式如下:
欲分享出去的目录 主机名称1或者IP1(参数1,参数2) 主机名称2或者IP2(参数3,参数4)
上面这个格式表示,同一个目录分享给两个不同的主机,但提供给这两台主机的权限和参数是不同的,所以分别设定两个主机得到的权限.
可以设定的参数主要有以下这些:
rw:可读写的权限;
ro:只读的权限;
no_root_squash:登入到NFS 主机的用户如果是ROOT用户,他就拥有ROOT的权限,此参数很不安全,建议不要使用.
root_squash:在登入 NFS协议主机使用分享之目的使用者如果是使用者的都成 nobody 身份;
all_squash:不管登陆NFS主机的用户是什么都会被重新设定为nobody.
anonuid:将登入NFS主机的用户都设定成指定的user id,此ID必须存在于/etc/passwd中.
anongid:同 anonuid ,但是?成 group ID 就是了!
sync:资料同步写入存储器中.
async:资料会先暂时存放在内存中,不会直接写入硬盘.
insecure 允许从这台机器过来的非授权访问.

重新加载配置

exportfs -a 

检查共享目录是否设置正确

showmount -e 

调整防火墙配置

firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload 

NFS客户端配置
安装nfs-utils

yum -y update 
yum -y install nfs-utils 

检查共享目录是否设置正确,10.192.7.1为nfs服务端的IP

showmount -e 10.192.7.1 

创建本地挂载点

mkdir -p /application/share

挂载远程服务器NFS分区到本地挂载点

mount -t nfs 10.192.7.1:/application/share /application/share

取消挂载

umount /application/share 

如果挂载失败,在服务器上执行cat /var/log/messages | grep mount
查看挂载失败原因

你可能感兴趣的:(centos)