共享文件
关闭防火墙
[root@zsr ~]# systemctl stop firewalld
[root@zsr ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@zsr ~]# setenforce 0
[root@zsr ~]#
安装nfs服务
[root@zsr ~]# yum -y install nfs-utils
启动nfs服务
[root@zsr ~]# systemctl start nfs-server
[root@zsr ~]# systemctl start rpcbind
[root@zsr ~]#
创建文件和共享目录
[root@zsr ~]# mkdir -p /nfs/shared
[root@zsr ~]# vi /etc/exports
[root@zsr ~]# cat /etc/exports
/nfs/shared *(ro)
[root@zsr ~]#
···
客服端
下载nfs
```bash
[root@zsr2 ~]# yum -y install nfs-utils
关闭防火墙和seliunx
[root@zsr2 ~]# systemctl stop firewalld
[root@zsr2 ~]# setenforce 0
查看共享目录
[root@zsr2 ~]# showmount -e 192.168.17.132
Export list for 192.168.17.132:
/nfs/shared *
[root@zsr2 ~]#
创建挂载点目录
挂载
查看挂载是否成功
[root@zsr2 ~]# mkdir /123
[root@zsr2 ~]# mount 192.168.17.132:/nfs/shared /123
[root@zsr2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 877M 0 877M 0% /dev
tmpfs 896M 0 896M 0% /dev/shm
tmpfs 896M 8.7M 887M 1% /run
tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root 17G 1.7G 16G 10% /
/dev/sda1 1014M 214M 801M 22% /boot
tmpfs 179M 0 179M 0% /run/user/0
192.168.17.132:/nfs/shared 17G 1.7G 16G 10% /123
[root@zsr2 ~]#
在服务端创建文件在客服端查看
[root@zsr ~]# cd /nfs/shared/
[root@zsr shared]# touch zsr
[root@zsr shared]# ls
zsr
[root@zsr2 ~]# ls /123
zsr
[root@zsr2 ~]#
开放目录
创建共享目录
[root@zsr ~]# mkdir /nfs/upload
创建用户和组为nfsupload,指定UID GID为300
[root@zsr ~]# useradd -r -u 300 nfsupload
[root@zsr ~]# id nfsupload
uid=300(nfsupload) gid=300(nfsupload) groups=300(nfsupload)
[root@zsr ~]#
共享目录
[root@zsr ~]# vi /etc/exports
[root@zsr ~]# cat /etc/exports
/nfs/shared *(ro)
/nfs/upload 172.16.12.0/24(ro)
[root@zsr ~]#
重启服务
[root@zsr ~]# systemctl restart rpcbind nfs-server
查看共享目录
[root@zsr2 ~]# showmount -e 192.168.17.132
Export list for 192.168.17.132:
/nfs/shared *
/nfs/upload 172.16.12.0/24
[root@zsr2 ~]#
挂载目录
[root@zsr2 ~]# mount -t nfs 192.168.17.132:/nfs/upload /test
修改属主、组修改为ufsupload
[root@zsr ~]# chown -R 300 /nfs/upload
[root@zsr ~]# chgrp -R 300 /nfs/upload
[root@zsr ~]# ll /nfs/
total 0
drwxr-xr-x. 2 root root 17 Dec 22 20:11 shared
drwxr-xr-x. 2 nfsupload nfsupload 6 Dec 22 20:16 upload
[root@zsr ~]#