NFS局域网目录共享
- 安装配置nfs服务
yum install rpcbind nfs-utils -y
vim /etc/exports
--------------/etc/exports-----------------
/data 172.16.1.0/24(rw,sync,all_squash)
--------------/etc/exports 结束-------------
mkdir /data
chown -R nfsnobody.nfsnobody /data/
systemctl enable nfs
systemctl start nfs
yum install nfs-utils -y
showmount -e 172.16.1.31
mount -t nfs 172.16.1.31:/data /mnt
df -h
nfs参数 | 作用 |
---|
rw | 读写权限 |
ro | 只读权限 |
sync | 同时将数据写入内存与硬盘种,保证不丢失数据 |
async | 优先将数据保存到内存,然后写入硬盘,效率提高但易丢失数据 |
root_squash | 当NFS客户端以root访问时,映射为NFS服务器的匿名用户(不常用) |
no_root_squash | 当客户端以root身份访问时,映射为NFS的root管理员(不常用) |
no_all_squash | 无论NFS客户端使用什么身份访问,都不进行压缩(kvm热迁移) |
all_squash | 不论客户端以什么身份访问,都映射为NFS的匿名用户 |
anonuid | 配置all_squash使用,指定NFS的用户UID,必须存在于系统 |
anongid | 配置all_squash使用,指定NFS的用户GID,必须存在于系统 |
- 验证ro权限
vim /etc/exports
-------------/etc/exports----------------
/data1 172.16.1.0/24(ro,sync,all_squash)
-------------/etc/exports结束-------------
mkdir /data1
chown nfsnobody.nfsnobody /data1/
systemctl restart nfs
mount -t nfs 172.16.1.31:/data1 /mnt
echo "123" >> /mnt/test
-bash: /mnt/test: 只读文件系统
- 验证all_squash、anonuid、anongid权限
vim /etc/exports
--------------/etc/exports-------------
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
--------------/etc/exports结束----------
mkdir -p /data
chown -R www.www /data
systemctl restart nfs
groupadd -g 666 www
useradd -u 666 -g666 www
mount -t nfs 172.16.1.31:/data /mnt
echo "132" >> /mnt/test
ll /mnt/
-rw-r--r-- 1 666 666 4 Apr 16 11:11 test
groupadd -g 666 www
useradd -u 666 -g666 www