注意:先配置好防火墙,或者试验阶段直接停用防火墙
# 停用防火墙
systemctl status firewalld 状态
systemctl stop firewalld 停止
systemctl start firewalld 启动
systemctl enable firewalld 开机启动
systemctl disable firewalld 开机不启动
systemctl stop iptables
vi /etc/selinux/config 永久关闭selinux
SELINUX=enforcing 改为 disabled
wq
NAS重新挂在目录权限
mount -o remount, rw /ycx/upload
服务端
################
## 服务端配置 ##
################
mkdir -p /ycx/upload
chmod -R 777 /ycx/upload
# 安装nfs
yum -y install nfs-utils rpcbind
# 启动服务
systemctl start nfs #CentOs7 nfs CentOS8 nfs-server
systemctl start rpcbind
# 开机启用
systemctl enable nfs #CentOS7 nfs CentOS8 nfs-server
systemctl enable rpcbind
# 配置防火墙 允许 rpc-bind nfs mountd 服务通过防火墙
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload
# 配置共享文件夹,客户端IP
vi /etc/exports
/ycx/upload 10.10.10.98(rw,sync,no_root_squash)
/ycx/app 10.10.10.98(rw,sync,no_root_squash)
# IP段访问配置
/ycx/upload 10.10.*.*(rw,no_root_squash,sync)
/deya/vhost 10.10.10.0/24(rw,no_root_squash,sync)
# 重新挂载
exportfs -rv
# 检查共享目录是否设置正确
showmount -e
客户端#################
## 客户端配置 ##
#################
mkdir -p /ycx/upload
# 安装nfs
yum -y install nfs-utils
# 启动nfs
systemctl start nfs #CentOS7 nfs CentOS8 nfs-server
# 开机启用
systemctl enable nfs #CentOS7 nfs CentOS8 nfs-server
# 检查共享目录是否设置正确,服务端IP
showmount -e 10.10.10.98
# 挂载服务端硬盘到客户端服务器
mount -t nfs 10.10.10.98:/ycx/upload /ycx/upload
mount -t nfs -o ro,hard,intr,proto=tcp 10.10.10.98:/ycx/upload /ycx/upload
# 取消挂载
umount 10.10.10.198:/ycx/upload
# 重新挂载赋权限
mount -o remount, rw /ycx/upload
# 开机自动挂载
vim /etc/fstab
10.10.10.98:/ycx/upload /ycx/upload nfs4 defaults 0 0
fstab
第一个device 用来挂载每个文件系统的分区设备文件名或 UUID
第二个字dir 挂载点
第三个type 文件系统的类型
第四个options 各种挂载参数和 mount 命令的挂载参数一致
第五个 dump 指定分区是否被 dump 备份 0 代表不备份,1 代表备份,2 代表不定期备份。
第六个 fsck 指定分区是否被 fsck 检测 0 代表不检测,1 的优先级比 2 高
注意:df 卡住没反应,大概率是由于 mount 的目录被删除了,但是没有提前执行 umount 操作,因此报错
解决方案:查看 /etc/fstab 文件中是否有 mount 相关的目录,使用 umount -l 命令卸载无效挂载目录,同时从 /etc/fstab 中删除相关目录
umount -l 10.176.22.132:/ycx/upload
ro 在此NFS卷上允许读取请求(默认)
rw 在此NFS卷上同时允许读取和写入请求
root_squash 在登入 NFS 主机使用分享之目录的使用者如果是 root 时,那么这个使用者的权限将被压缩成为匿名使用者,通常他的 UID 与 GID 都会变成 nobody 那个系统账号的身份
no_root_squash 登入 NFS 主机使用分享目录的使用者,如果是 root 的话,那么对于这个分享的目录来说,他就具有 root 的权限!这个项目『极不安全』,不建议使用!
no_all_squash 保留共享文件的UID和GID(默认)
sync 将更改提交到稳定存储后
CentOS8
systemctl restart nfs-server
systemctl enable nfs-server
exportfs 命令
-a 全部挂载或者全部卸载
-r 重新挂载
-u 卸载某一个目录
-v 显示共享目录
defaults表示挂载类型,rw,suid.dev,exec,auto,nouser,async 大多是默认值.async是异步,写入内存.效率高,安全稍低.sync写入磁盘效率低一些.
rw 读写
suid 可以有suid权限
exec 可执行文件
async/sync 设置是否为同步方式运行,默认为async
auto/noauto 当下载mount -a 的命令时,此文件系统是否被主动挂载。默认为auto
rw/ro 是否以以只读或者读写模式挂载
exec/noexec 限制此文件系统内是否能够进行"执行"的操作
user/nouser 是否允许用户使用mount命令挂载
suid/nosuid 是否允许SUID的存在
usrquota 启动文件系统支持磁盘配额模式
grpquota 启动文件系统对群组磁盘配额模式的支持
defaults 同时具有rw,suid,dev,exec,auto,nouser,async等默认参数的设置