NFS網路檔案系統
一,概述
網路檔案系統 (NFS) 是 Unix 系統和網路附加儲存檔案管理器常用的網路檔案系統 , 允許多個客戶端通過網路共享檔案訪問。它
可用於提供對共享二進位制目錄的訪問 , 也可用於允許使用者在同一工作組中從不同客戶端訪問其檔案
NFS 協議有多個版本 :Linux 支援版本 4 、版本 3 和版本 2, 而大多數系統管理員熟悉的是 NFSv3 。預設情況下 , 該協議並不
安全 , 但是更新的版本 ( 如 NFSv4) 提供了對更安全的身份驗證的支援 , 甚至可以通過 kerberos 進行加密
二,nfs安裝與基本操作
1,安裝,共享
[[email protected] ~]# yum install nfs-utils -y >>>>>服務端客戶端安裝nfs-utils
[ [email protected] ~]# yum install nfs-utils -y
[[email protected] ~]# showmount -e 172.25.254.200 >>>>>客戶端檢視服務端的共享檔案,為空
Export list for 172.25.254.200:
[[email protected] ~]# systemctl start nfs >>>>>服務端啟動nfs
[ [email protected] ~]# systemctl enable nfs-server
[[email protected] ~]# vim /etc/exports >>>>>>寫共享檔案
[[email protected] ~]# cat /etc/exports >>>>>> *表示所有人
/mnt *(sync,ro) >>>>>>共享/mnt目錄,允許進行資料傳輸,只讀掛載
[ [email protected] ~]# exportfs -rv >>>>>>服務端重新整理共享檔案
exporting *:/mnt >>>>>> *表示所有人
[[email protected] mnt]# showmount -e 172.25.254.200 >>>>>>顯示服務端的共享檔案
Export list for 172.25.254.200:
/mnt *
[[email protected] ~]# cd /mnt/ >>>>>>檢視服務端共享目錄的檔案
[[email protected] mnt]# ls
file1 file2 file3 file4 file5
[[email protected] ~]# mount 172.25.254.200:/mnt/ /mnt/ >>>>>>客戶端把服務端的/mnt目錄掛載在/mnt下
[[email protected] ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3152376 7321524 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17036 925624 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
172.25.254.200:/mnt 10473984 3159552 7314432 31% /mnt
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# ls >>>>>>客戶端看到了服務端共享的檔案
file1 file2 file3 file4 file5
[[email protected] mnt]# rm -rf * >>>>>>由於是隻讀掛載,刪除不了
rm: cannot remove ‘file1’: Read-only file system
rm: cannot remove ‘file2’: Read-only file system
rm: cannot remove ‘file3’: Read-only file system
rm: cannot remove ‘file4’: Read-only file system
rm: cannot remove ‘file5’: Read-only file system
[[email protected] mnt]# vim /etc/exports
[[email protected] mnt]# cat /etc/exports >>>>>>修改為可讀可寫掛載
/mnt *(sync,rw)
[[email protected] mnt]# systemctl restart nfs >>>>>>
[[email protected] mnt]# ls
file1 file2 file3 file4 file5
[[email protected] mnt]# rm -rf * >>>>>>還是無法刪除,是檔案系統的許可權不夠
rm: cannot remove ‘file1’: Permission denied
rm: cannot remove ‘file2’: Permission denied
rm: cannot remove ‘file3’: Permission denied
rm: cannot remove ‘file4’: Permission denied
rm: cannot remove ‘file5’: Permission denied
[[email protected] mnt]# ll
total 0
-rw-r--r--. 1 root root 0 Jun 3 08:14 file1
-rw-r--r--. 1 root root 0 Jun 3 08:14 file2
-rw-r--r--. 1 root root 0 Jun 3 08:14 file3
-rw-r--r--. 1 root root 0 Jun 3 08:14 file4
-rw-r--r--. 1 root root 0 Jun 3 08:14 file5
[[email protected] mnt]# chmod -R 777 /mnt/ >>>>>>服務端給滿許可權
[[email protected] mnt]# rm -rf * >>>>>>成功刪除
[[email protected] mnt]# ls
[[email protected] mnt]# touch file6 >>>>>>客戶端可以建立檔案
[[email protected] mnt]# ls
file6
[[email protected] mnt]# ls >>>>>>服務端也可以檢視到
file6
[[email protected] mnt]# ll
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Jun 5 03:30 file6 >>>>>>而且這個檔案的所有者和組都是nfsbody
2,no_root_squash登陸nfs時獲得root的身份
[[email protected] mnt]# vim /etc/exports
[[email protected] mnt]# cat /etc/exports
/mnt *(sync,rw,no_root_squash) >>>>>>>對於改目錄,具有root許可權
[[email protected] mnt]# systemctl restart nfs >>>>>>>可以不用重啟,但是要重新整理
[[email protected] mnt]# exportfs -rv
[[email protected] ~]# umount /mnt/
[[email protected] ~]# mount 172.25.254.200:/mnt /mnt/ >>>>>>>客戶端重新掛載
[[email protected] ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3152732 7321168 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17008 925652 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
172.25.254.200:/mnt 10473984 3159296 7314688 31% /mnt
[[email protected] ~]# showmount -e 172.25.254.200
Export list for 172.25.254.200:
/mnt *
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# touch file7 >>>>>>>以root身份建立檔案
[[email protected] mnt]# ll
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Jun 5 03:30 file6
-rw-r--r--. 1 root root 0 Jun 5 03:45 file7 >>>>>>>所有者和組都是root
3,使用者登陸時獲得指定的身份
[[email protected] mnt]# vim /etc/exports
[[email protected] mnt]# cat /etc/exports
/mnt *(sync,rw,anonuid=1000,anongid=1000) >>>>>>>使用者登陸時身份uid=1000,gid=10000
[[email protected] mnt]# exportfs -rv >>>>>>>重新整理
exporting *:/mnt
[[email protected] mnt]# touch file8
[[email protected] mnt]# ll
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Jun 5 03:30 file6
-rw-r--r--. 1 root root 0 Jun 5 03:45 file7
-rw-r--r--. 1 student student 0 Jun 5 03:47 file8 >>>>>>>客戶端uid=1000,gid=1000的時student使用者
[[email protected] mnt]# id student >>>>>>>檢視
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
5,特定ip訪問許可權
[[email protected] westos]# vim /etc/exports
[[email protected] westos]# cat /etc/exports
/mnt *(sync,rw,anonuid=1000,anongid=1000)
/westos 172.25.254.156(sync,rw) >>>>>>>只有172.25.254.156這臺主機才可以訪問
[[email protected] westos]# exportfs -rv
exporting 172.25.254.156:/westos
exporting *:/mnt
[[email protected] ~]# showmount -e 172.25.254.200
Export list for 172.25.254.200:
/mnt *
/westos 172.25.254.156
[[email protected] ~]# mount 172.25.254.200:/westos /mnt/ >>>>>>>檔案生效,100無法掛載
mount.nfs: access denied by server while mounting 172.25.254.200:/westos
[[email protected] ~]# mount 172.25.254.200:/westos /mnt/ >>>>>>>156可以掛載,可以檢視
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# ls
file filetest
6,特定網段訪問
[[email protected] ~]# vim /etc/exports
[[email protected] ~]# cat /etc/exports
/mnt *(sync,rw,anonuid=1000,anongid=1000)
/westos 172.25.254.0/24(sync) >>>>>>>該目錄只能由這個網段的ip訪問
[[email protected] ~]# exportfs -rv
exporting 172.25.254.0/24:/westos
exporting *:/mnt
注意:man 5 exports有很多特定條件訪問的例子
nfs的讀寫布林值是預設開啟的
[[email protected] ~]# getenforce
Enforcing
[[email protected] ~]# getsebool -a | grep nfs
cobbler_use_nfs --> off
ftpd_use_nfs --> off
git_cgi_use_nfs --> off
git_system_use_nfs --> off
httpd_use_nfs --> off
ksmtuned_use_nfs --> off
logrotate_use_nfs --> off
mpd_use_nfs --> off
nfs_export_all_ro --> on >>>>>>
nfs_export_all_rw --> on >>>>>>
nfsd_anon_write --> off
openshift_use_nfs --> off
polipo_use_nfs --> off
samba_share_nfs --> off
sanlock_use_nfs --> off
sge_use_nfs --> off
use_nfs_home_dirs --> off
virt_sandbox_use_nfs --> off
virt_use_nfs --> off
xen_use_nfs --> off
二,用時自動掛載,閒置時自動取消掛載
[[email protected] ~]# vim /etc/exports
[[email protected] ~]# cat /etc/exports
/mnt *(sync,rw,anonuid=1000,anongid=1000)
/westos *(sync,rw
[[email protected] ~]# exportfs -rv >>>>>>服務端建立兩個分享目錄
exporting *:/westos
exporting *:/mnt
[[email protected] ~]# showmount -e 172.25.254.200 >>>>>>客戶端可以檢視到
Export list for 172.25.254.200:
/westos *
/mnt *
[[email protected] ~]# yum install autofs -y >>>>>>>客戶端安裝自動掛載軟體autofs
[[email protected] ~]# systemctl start autofs >>>>>>>啟動
[[email protected] ~]# systemctl enable autofs
ln -s '/usr/lib/systemd/system/autofs.service' '/etc/systemd/system/multi-user.target.wants/autofs.service'
[[email protected] ~]# ls / >>>>>>>啟動之後在根目錄下就會出現一個net目錄
bin dev home lib64 misc net proc run srv tmp var
boot etc lib media mnt opt root sbin sys usr
[[email protected] ~]# cd /net/ >>>>>>>net目錄什麼都沒有
[[email protected] net]# ls
[[email protected] net]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3158460 7315440 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17012 925648 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup >>>>>>>因為此時還沒有進入共享檔案,所以還沒有掛載
[[email protected] net]# cd 172.25.254.200 >>>>>>>可以切進去!!!!!
[[email protected] 172.25.254.200]# pwd
/net/172.25.254.200
[[email protected] 172.25.254.200]# ls >>>>>>>172.25.254.200這個目錄下面有共享服務端共享目錄
mnt westos
[[email protected] 172.25.254.200]# df
Filesystem 1K-blocks Used Available Use% Mounted on >>>>>>>依然沒有掛載
/dev/vda1 10473900 3158460 7315440 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17012 925648 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
[[email protected] 172.25.254.200]# cd westos/
[[email protected] westos]# ls >>>>>>>>訪問westos共享檔案
file filetest
[[email protected] westos]# df >>>>>>>>掛載上,和手動掛載是,只不過掛載點不一樣
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3158000 7315900 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17012 925648 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
172.25.254.200:/westos 10473984 3159808 7314176 31% /net/172.25.254.200/westos
[[email protected] westos]# vim /etc/sysconfig/autofs >>>>>>設定閒置時間為5s,在不用共享檔案5s之後自動解除安裝
TIMEOUT=5 >>>>>>>預設是300s
[[email protected] westos]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3158024 7315876 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17012 925648 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
172.25.254.200:/westos 10473984 3159296 7314688 31% /net/172.25.254.200/westos
[[email protected] westos]# cd >>>>>>>>不要在共享目錄裡面,否則系統認為還在使用
[[email protected] ~]# systemctl restart autofs.service >>>>>>>>重啟系統
[[email protected] ~]# df >>>>>>>>等待5s之後,自動取消掛載
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3158004 7315896 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17012 925648 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
注意:就算不在共享目錄裡面,也不能在timeout時間內df一直檢視,這是不算作閒置時間的
三,修改自動掛載的掛載點
1,只讀掛載
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# showmount -e 172.25.254.200 >>>>>一定要開啟服務,確定能看到共享檔案
Export list for 172.25.254.200:
/westos *
/mnt *
[[email protected] ~]# ls -ld /westos
drwxr-xr-x. 2 root root 32 Jun 5 04:14 /westos
[[email protected] ~]# chmod 777 /westos/ >>>>>給滿許可權
[[email protected] ~]# vim /etc/auto.master
/misc /etc/auto.misc
/nfs /etc/auto.westos >>>>>>最終掛載點的上層目錄 指定要掛載的檔案
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
[[email protected] ~]# ls /etc/auto.westos
ls: cannot access /etc/auto.westos: No such file or directory
[[email protected] ~]# vim /etc/auto.westos >>>>>>建立指定要掛載的檔案
[[email protected] ~]# cat /etc/auto.westos
westos -ro 172.25.254.200:/westos >>>>>>最終掛載點上層目錄的剩餘部分 只讀掛載200主機的/westos
>>>>>>就是掛載/nfs/westos下
[[email protected] ~]# systemctl restart autofs.service >>>>>>>重啟服務
[[email protected] ~]# cd /nfs/
[[email protected] nfs]# ls
[[email protected] nfs]# cd westos
[[email protected] westos]# ls
file filetest
[[email protected] westos]# df >>>>>成功掛載
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3157260 7316640 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17012 925648 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
172.25.254.200:/westos 10473984 3159296 7314688 31% /nfs/westos
[[email protected] westos]# mount >>>>>可以看到掛載的詳細資訊
172.25.254.200:/westos on /nfs/westos type nfs4 (ro,relatime,vers=4.0,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=172.25.254.100,local_lock=none,addr=172.25.254.200)
2,可讀可寫掛載
[[email protected] ~]# vim /etc/auto.master
/misc /etc/auto.misc
/nfs /etc/auto.westos >>>>>>最終掛載點的上層目錄 指定掛載的檔案
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
[[email protected] ~]# vim /etc/auto.westos
[[email protected] ~]# cat /etc/auto.westos
westos -rw,vers=3 172.25.254.200:/westos >>>>>可讀可寫掛載
[[email protected] ~]# systemctl restart autofs.service
[[email protected] ~]# cd /nfs/
[[email protected] nfs]# ls
[[email protected] nfs]# cd westos
[[email protected] westos]# ls
file filetest
[[email protected] westos]# df >>>>>成功掛載
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3156796 7317104 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17012 925648 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
172.25.254.200:/westos 10473984 3159296 7314688 31% /nfs/westos
[[email protected] westos]# touch file1 >>>>>>可以建立檔案
[[email protected] westos]# ls
file file1 filetest
[[email protected] westos]# mount >>>>>>檢視掛載資訊
172.25.254.200:/westos on /nfs/westos type nfs (rw,relatime,vers=3,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=172.25.254.200,mountvers=3,mountport=20048,mountproto=udp,local_lock=none,addr=172.25.254.200)
相關推薦
Linux系統——NFS網路檔案系統
在企業叢集架構的工作場景中,NFS網路檔案系統一般被用來儲存共享視訊,圖片,附件等靜態資原始檔,通常網站使用者上傳的檔案都會放到NFS共享裡,然後前端所有的節點訪問這些靜態資源時都會讀取NFS儲存上的資源。NFS是當前網際網路系統架構中最常用的資料儲存服務之一。 叢集:多臺普通伺服器,多臺之
L028-老男孩實效教育-nfs網路檔案系統企業級優化實戰-12節
通過命令:mount -t nfs -o nosuid,noexec,nodev,rw 10.0.0.7:data/ /mnt 將mnt掛載。 掛載的時候因為加了noexec引數,雖然有x許可權,但是也會會導致指令碼不能正常執行
轉:iTOP-4412實現NFS網路檔案系統
[學習嵌入式開發板]iTOP-4412實現NFS網路檔案系統 <div class="extra ui horizontal list meta-wrap"> <div class="item">
紅帽7 NFS(網路檔案系統)
NFS(網路檔案系統)服務可以將遠端 Linux 系統上的檔案共享資源掛載到本地主機的目錄上,從而使得本地主機(Linux 客戶端)基於 TCP/IP 協議,像使用本地主機上的資源那樣讀寫遠端 Linux 系統上的共享檔案, RHEL 7 系統中預設已經安裝了 NFS 服務。 第一步:為了檢驗 N
配置 NFS 網路檔案系統
方法一: 1、進行 NFS 伺服器端與客戶端的安裝 [email protected]:/# sudo apt-get install nfs-kernel-server nfs-common rpcbind 提示是否需要繼續: Y Do you want to con
linux 的NFS網路檔案系統
NFS(Network File System)即網路檔案系統,是由Sun 公司開發的一種通過網路方式共享檔案系統的通用共享解決方案。目前NFS 有三個版本,分別為NFSv2、NFSv3、NFSv4。NFSv2 是
11.24 nfs--網路檔案系統
1.NFS的介紹 NFS(Network File System)即網路檔案系統,是FreeBSD支援的檔案系統中的一種,它允許網路中的計算機之間通過TCP/IP網路共享資源。在NFS的應用中,本地NFS的客戶端應用可以透明地讀寫位於遠端NFS伺服器上的檔案,就像訪問本地檔案一樣。 &nbs
01: 儲存技術與應用 iSCSI技術應用 、 udev配置 NFS網路檔案系統 、 Multipath多路徑 、 NFS網路檔案系統 、 udev配置
Top NSD CLUSTER DAY01 1 案例1:配置iSCSI服務 1.1 問題 本案例要求先搭建好一臺iSCSI伺服器,並將整個磁碟共享給客戶端: 伺服器上要額外配置一塊硬碟 服務端安裝target,並將新加的硬碟配置為iSCSI 的共享磁碟 在客
NFS網路檔案系統的搭建
sudo aptitude install nfs-kernel-server 新建一個NFS掛載目錄,該目錄用於共享NFS下的目錄,我的建立在家目錄下的nfs目錄下。修改其許可權,保證所有者都可以讀寫、可以執行。chmod 7
關於NFS網路檔案系統的小知識
關於NFS檔案作業系統,nfs依賴與rpcbind服務,NFS伺服器端需要安裝nfs-utiles和rpc-bind,nfs是對外隨機開放埠的,但是這些埠會被rpcbind服務收集到,NFS把自己埠向rpcbind進行註冊,rpcbind有固定的埠,而NFS客戶
RHCE7.0-搭建基於NFS網路檔案系統服務
Linux NFS伺服器的安裝與配置 一、NFS服務簡介 NFS 是Network File System的縮寫,即網路檔案系統。一種使用於分散式檔案系統的協定,由Sun公司開發,於1984年向外公佈。功能是通過網路讓不同的機器、不同的作業系統
Linux下的NFS網路檔案系統
NFS(Network File System)即網路檔案系統,是FreeBSD支援的檔案系統中的一種,它允許網路中的計算機之間通過TCP/IP網路共享資源。在NFS的應用中,本地NFS的客戶端應用可以透明地讀寫位於遠端NFS伺服器上的檔案,就像訪問本地檔案一樣。yum 下載安裝 insta
JZ2440 啟動NFS網路檔案系統_初試led驅動
http://blog.csdn.net/emdfans/article/details/12260969 u-boot ---> q 修改bootargs變數 預設: bootargs=noinitrd root=/dev/mtdblock3 init
NFS(網路檔案系統)
NFS(網路檔案系統) **作用:**將遠端 Linux 系統上的檔案共享資源掛載到本地主機的目錄上,從而使得本地主機(Linux 客戶端)基於 TCP/IP 協議,像使用本地主機上的資源那樣讀寫遠端 Linux 系統上的共享檔案 伺服器安裝包 yum -y instaall r
飛思卡爾的i.mx6dl開發板上實現nfs網路檔案系統掛載操作指南
問題描述:在MCIMX6DL_SDP上實現網路檔案掛載,要求從emmc中啟動uboot和kernel,從網路上掛載根檔案系統。 操作平臺: host :Ubuntu14.04LTS board:
Linux-nfs網路檔案系統
NFS(網路檔案系統) NFS(Network File System)即網路檔案系統,是FreeBSD支援的檔案系統中的一種,它允許網路中的計算機之間通過TCP/IP網路共享資源。在NFS的應用中,本地NFS的客戶端應用可以透明地讀寫位於遠端NFS伺服器上的檔案,就像訪
NFS網路檔案系統
一,概述網路檔案系統 (NFS) 是 Unix 系統和網路附加儲存檔案管理器常用的網路檔案系統 , 允許多個客戶端通過網路共享檔案訪問。它可用於提供對共享二進位制目錄的訪問 , 也可用於允許使用者在同一工作組中從不同客戶端訪問其檔案NFS 協議有多個版本 :Linux 支援版
L027-老男孩Linux高階運維課程-nfs網路檔案系統企業級深度講解
過濾nfs服務。 nfs重啟,超過四個OK表示nfs服務正常。 exportfs:(加)不但可以載入配置生效,也可以通過命令直接共享目錄,越過/etc/exports。但是重啟失效。 mount:(加)配置nfsserver,分別在服務端
cifs網路檔案系統訪問、nfs網路檔案系統訪問、autofs自動掛載服務、
####cifs網路檔案系統訪問####1.安裝共享訪問客戶端yum install samba-client.x86_64 -y2.識別共享伺服器共享目錄smbclient -L //172.25.254.250 ##檢視伺服器的共享檔案有那些3.訪問
linux開發板掛載NFS網路檔案系統
1、前提:主機(伺服器)已經安裝並啟動NFS服務 2、主機配置: 首先配置主機能夠被掛接的資料夾:配置檔案在 /eetc/exports vi /etc/exports 在後面新增內容 /work/nfs_root/first_fs *(rw,sync,no_root_squash) 其中前面為要被