linux nfs

Asai. 2019-06-22 11:38:16
服务端 1,server(192.168.1.10),client(192.168.1.20)设置ip 2,[root@server Desktop]# yum -y install nfs* //安装nfs服务 3,[root@server Desktop]# systemctl restart rpcbind.service //启动rpc [root@server Desktop]# netstat -tpln | grep 111 //查看端口 tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 4898/rpcbind tcp6 0 0 :::111 :::* LISTEN 4898/rpcbind 4,[root@server Desktop]# mkdir /redhat //创建共享目录 [root@server redhat]# >nfs1 //创建测试文件 [root@server redhat]# >nfs2 5,[root@server Desktop]# vim /etc/exports //编辑配置文件 /redhat 192.168.1.0/255.255.255.0(rw,sync) 共享文件名 选项 6,[root@server Desktop]# exportfs -v //查看共享 /redhat 192.168.1.20/255.255.255.0(rw,wdelay,root_squash,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash) 7,[root@server redhat]# systemctl stop firewalld.service //关闭防火墙 [root@server redhat]# setenforce 0 //关闭selinux防火墙 客户端 8,[root@client Desktop]# showmount -e 192.168.1.10 //查看网络共享 Export list for 192.168.1.10: /redhat 192.168.1.0/255.255.255.0 9,[root@client mnt]# mount -t nfs 192.168.1.10:/redhat /mnt/chen //挂载 [root@client mnt]# df -h //查看挂载 Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 30G 3.2G 27G 11% / devtmpfs 904M 0 904M 0% /dev tmpfs 914M 140K 914M 1% /dev/shm tmpfs 914M 8.9M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 497M 124M 373M 25% /boot /dev/sr0 3.7G 3.7G 0 100% /run/media/root/RHEL-7.1 Server.x86_64 192.168.1.10:/redhat 38G 3.2G 35G 9% /mnt/chen [root@client mnt]# cd /mnt/chen/ [root@client chen]# ls nfs1 nfs2 创建文件和文件夹 Server上/redhat文件夹默认权限为644 ,client为其他人。故不能创建文件,应改权限777 [root@server redhat]# chmod 777 /redhat/ [root@server redhat]# ll / drwxrwxrwx. 2 root root 28 Jun 22 10:13 redhat [root@client chen]# > nfs3 [root@client chen]# ll total 0 -rw-r--r--. 1 root root 0 Jun 22 10:13 nfs1 -rw-r--r--. 1 root root 0 Jun 22 10:13 nfs2 -rw-r--r--. 1 nfsnobody nfsnobody 0 Jun 22 10:39 nfs3 解释nfsnobody [chen@client chen]$ >nfs4 //用普通用户创建文件 [chen@client chen]$ ll total 0 -rw-r--r--. 1 root root 0 Jun 22 10:13 nfs1 -rw-r--r--. 1 root root 0 Jun 22 10:13 nfs2 -rw-r--r--. 1 nfsnobody nfsnobody 0 Jun 22 10:39 nfs3 -rw-rw-r--. 1 chen chen 0 Jun 22 10:44 nfs4 用chen用户创建文件,所属用户所属组为chen 证明只有root用户为nfsnobody Nfsnobody区分客户端root用户和服务端root用户 让root用户也显示为root 选项root_squash:默认值,root写入显示为nfsnobody 让root用户也显示为root只需要更改选项为no_root_squash [root@server redhat]# vim /etc/exports //编辑配置文件 /redhat 192.168.1.0/255.255.255.0(rw,sync,no_root_squash) [root@server redhat]# systemctl restart nfs //刷新nfs服务 [root@server redhat]# exportfs -v //查看,选项更改成功 /redhat 192.168.1.0/255.255.255.0(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash) [root@client chen]# >nfs5 //测试 [root@client chen]# ll total 0 -rw-r--r--. 1 root root 0 Jun 22 10:13 nfs1 -rw-r--r--. 1 root root 0 Jun 22 10:13 nfs2 -rw-r--r--. 1 nfsnobody nfsnobody 0 Jun 22 10:39 nfs3 -rw-rw-r--. 1 chen chen 0 Jun 22 10:44 nfs4 -rw-r--r--. 1 root root 0 Jun 22 10:58 nfs5 //所属用户所属组为root 指定所属用户和所属组(为客户端存放的用户,组) [root@client chen]# useradd -u 1234 sai //创建用户 [root@client chen]# id sai uid=1234(sai) gid=1234(sai) groups=1234(sai) [root@client /]# umount /mnt/chen/ //卸载nfs [root@client /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 30G 3.2G 27G 11% / devtmpfs 904M 0 904M 0% /dev tmpfs 914M 140K 914M 1% /dev/shm tmpfs 914M 8.9M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 497M 124M 373M 25% /boot /dev/sr0 3.7G 3.7G 0 100% /run/media/root/RHEL-7.1 Server.x86_64 [root@server redhat]# vim /etc/exports //编辑配置文件 /redhat 192.168.1.0/255.255.255.0(rw,sync,no_root_squash,anonuid=1234,anongid=1234) [root@server redhat]# systemctl restart nfs //刷新nfs服务 [root@client /]# mount -t nfs 192.168.1.10:/redhat /mnt/chen/ //客户端重新挂载 [root@client /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 30G 3.2G 27G 11% / devtmpfs 904M 0 904M 0% /dev tmpfs 914M 140K 914M 1% /dev/shm tmpfs 914M 8.9M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 497M 124M 373M 25% /boot /dev/sr0 3.7G 3.7G 0 100% /run/media/root/RHEL-7.1 Server.x86_64 192.168.1.10:/redhat 38G 3.2G 35G 9% /mnt/chen
...全文
28 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

18,773

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧