服务器端的配置
检查是否有安装rpc与nfs
rpm -qa nfs-utils rpcbind
如没有安装则进行安装:
yum -y install rpcbind nfs-utils
查看运行状态
systemctl status rpcbind
systemctl status nfs
启动rpc服务并设置开机自动启动
systemctl start rpcbind
systemctl enable rpcbind
启动nfs服务并设置开机自动启动
systemctl start nfs
systemctl enable nfs
创建共享目录并添加配置
如创建在data/nfs_share
mkdir -p /data/nfs_share
chmod 777 /data/nfs_share
修改/etc/exports,配置共享信息,如:
# nfs配置
/data/nfs_share 10.77.110.145/24(rw,sync)
/data/nfs_share 10.77.110.146/24(rw,sync)
/data/nfs_share 10.77.110.148/24(rw,sync)
//其中参数ro代表只读,rw代表读写
//sync代表同步的将数据写入到内存与硬盘中
//async代表异步的先将数据保存到内存,然后再写入硬盘
重新加载NFS服务,使配置文件生效
systemctl reload nfs
exportfs -r
检验服务端是否配置成功
客户端的配置
rpc与nfs的安装
此处仅安装rpc应该也行。
同服务端,检查是否安装,并启动
创建挂载目录并挂载
检查是都否看到服务端,输入以下命令应该能看到服务端的挂载信息
showmount -e 10.77.110.147
创建目录
mkdir /data/nfs_share
挂载:
mount -t nfs 10.77.110.147:/data/nfs_share/ /data/nfs_share
查看挂载信息,检验是否挂载成功
df -h
Permission denied问题
是nfs服务端的问题。
法一:客服端想访问相当于others,需要chmod给nfs文件夹所有权限。
法二:或者在服务端修改/etc/exports那一步添加参数,如:
/data/nfs_share 10.77.110.145/24(rw,sync,no_root_squash)
//no_root_squash意思是,当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员。
法二存在一定的安全隐患。