服務端
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/118912.html
標籤:專題技術討論區
上一篇:安裝ubuntu server16.04最后一步安裝程序出現這個,是怎么回事啊?
下一篇:ubuntu啟動報錯
