NFS網路共享檔案系統詳細配置
環境說明:
兩臺Linux Centos6.4版本
nfsServer:172.16.10.61
nfsClient:172.16.10.63
NFS共享檔案服務的應用場景說明
一.NFS軟體安裝
先檢查一下環境
[[email protected]~]#uname-r//檢視Linux核心版本號 2.6.32-358.el6.x86_64 [[email protected]~]#cat/etc/redhat-release//檢視centos版本號 CentOSrelease6.4(Final) [[email protected]~]#uname-m//檢視是32位還是64位系統 x86_64
rpm檢查當前伺服器是否有安裝 nfs-utils 和 rpcbind 這兩個服務
[[email protected]~]#rpm-qanfs-utilsrpcbind//如果沒有任何的結果就說明沒安裝過
這裡我們採用 yum install 方式進行安裝這兩個軟體
開始安裝:
[[email protected]~]#yuminstallnfs-utilsrpcbind-y開始安裝,如下圖片所示 Loadedplugins:fastestmirror,security
nfs-utils和rpcbind 安裝完畢 我們先檢查一下情況
[[email protected]~]#rpm-qanfs-utilsrpcbind rpcbind-0.2.0-11.el6_7.x86_64 nfs-utils-1.2.3-64.el6.x86_64
先開 rpcbind 服務 這個一定要先開的 不然後面可能會報錯什麼的....
[[email protected]~]#/etc/init.d/rpcbindstart//開啟rpc服務 Startingrpcbind:[OK] [[email protected]~]#ps-ef|grep-irpc//檢查是否有程序 rpc15501018:59?00:00:00rpcbind root15541410018:59pts/000:00:00grep-i--color=auto-irpc
[[email protected]~]#/etc/init.d/rpcbindstatus//檢查執行狀態 rpcbind(pid1550)isrunning...
開啟NFS服務
[[email protected]~]#/etc/init.d/nfsstart//開啟NFS服務向rpc註冊nfs連線埠資訊 StartingNFSservices:[OK] StartingNFSquotas:[OK] StartingNFSmountd:[OK] StartingNFSdaemon:[OK] StartingRPCidmapd:[OK] [[email protected]~]#/etc/init.d/nfsstatus//檢視nfs執行狀態 rpc.svcgssdisstopped rpc.mountd(pid1621)isrunning... nfsd(pid16361635163416331632163116301629)isrunning... rpc.rquotad(pid1617)isrunning... [[email protected]~]#rpcinfo-p172.16.10.61//檢視rpc資訊 programversprotoportservice 1000004tcp111portmapper 1000003tcp111portmapper 1000002tcp111portmapper 1000004udp111portmapper 1000003udp111portmapper 1000002udp111portmapper 1000111udp875rquotad 1000112udp875rquotad 1000111tcp875rquotad 1000112tcp875rquotad 1000051udp54898mountd 1000051tcp56474mountd 1000052udp41339mountd 1000052tcp51710mountd 1000053udp43880mountd 1000053tcp55842mountd 1000032tcp2049nfs 1000033tcp2049nfs 1000034tcp2049nfs 1002272tcp2049nfs_acl 1002273tcp2049nfs_acl 1000032udp2049nfs 1000033udp2049nfs 1000034udp2049nfs 1002272udp2049nfs_acl 1002273udp2049nfs_acl 1000211udp51604nlockmgr 1000213udp51604nlockmgr 1000214udp51604nlockmgr 1000211tcp33013nlockmgr 1000213tcp33013nlockmgr 1000214tcp33013nlockmgr
將nfs rpcbind這兩個服務加入到開機自啟動項裡面
[[email protected]~]#chkconfigrpcbindon [[email protected]~]#chkconfignfson [[email protected]~]#chkconfig--listrpcbind rpcbind0:off1:off2:on3:on4:on5:on6:off [[email protected]~]#chkconfig--listnfs nfs0:off1:off2:on3:on4:on5:on6:off
============================
服務端配置 NFS的檔案是/etc/exports
============================
現在我們要將服務端的 /data 目錄配置共享 如果根目錄下面沒有 那就建立一個 mkdir /data
******************************************************************************************
vi/etc/exports 配置檔案
[[email protected]~]# [[email protected]~]#vi/etc/exports #####thisismynfsserver /data172.16.10.0/16(rw,sync)
儲存wq 並檢查語法 優雅重起nfs服務
[[email protected]~]# [[email protected]~]#/etc/init.d/nfsreload//重啟nfs服務 [[email protected]~]#
重啟完畢之後 我們就自己檢查一下是否能成功掛載
在nfs伺服器自身檢查一下
[[email protected]~]# [[email protected]~]#showmount-e172.16.10.61 Exportlistfor172.16.10.61: /data172.16.10.0/16 [[email protected]~]#
在nfs客戶端上面檢查一下
[[email protected]~]#showmount-e172.16.10.61 clnt_create:RPC:Portmapperfailure-Unabletoreceive:errno113(Noroutetohost)
如果在檢查的時候 出現以上的問題 則說明 nfs服務端上面的防火牆是開啟狀態 不允許連線
那麼我們就要關閉防火牆!
關閉防火牆命令:
[[email protected]~]#/etc/init.d/iptablesstop iptables:Flushingfirewallrules:[OK] iptables:SettingchainstopolicyACCEPT:filter[OK] iptables:Unloadingmodules:
在關閉防火牆服務之後 我們再去檢查連線
[[email protected]~]#showmount-e172.16.10.61//有結果則說明連線成功... Exportlistfor172.16.10.61: /data172.16.10.0/16 [[email protected]~]#
客戶端掛載共享目錄mount -t nfs 172.16.10.61:/data /mnt/
[[email protected]~]#mount-tnfs172.16.10.61:/data/mnt/ [[email protected]~]#df-h FilesystemSizeUsedAvailUse%Mountedon /dev/sda318G1.8G15G11%/ tmpfs497M0497M0%/dev/shm /dev/sda1194M28M156M16%/boot 172.16.10.61:/data18G1.8G15G11%/mnt
[[email protected]mnt]#pwd /mnt [[email protected]mnt]#ll total0 -rw-r--r--.1rootroot0Mar1719:41index.php
*************************************************************
常見問題
在我們成功掛載網路檔案系統之後 我們是不可能把共享目錄裡面寫入資料的
因為我們沒有對共享目錄有許可權,預設的使用者是nfsnobosy
[[email protected]mnt]# [[email protected]mnt]#touchnews.php touch:cannottouch`news.php':Permissiondenied//提示沒有許可權
[[email protected]nfs]#cat/var/lib/nfs/etab//檢視nfs訪問使用者及其它的引數
[[email protected]nfs]#cat/etc/passwd|grep65534 nfsnobody:x:65534:65534:AnonymousNFSUser:/var/lib/nfs:/sbin/nologin
可以看的到是 網路訪問是通過 nfsnobody 這個使用者進行訪問的
所以這裡我們要在服務端上面 把 /data 的屬主和屬組都修改在 nfsnoboy
這樣子就可以實現讀寫許可權的功能
[[email protected]/]#chownnfsnobody.nfsnobodydata [[email protected]/]#ll-lddata drwxr-xr-x.2nfsnobodynfsnobody4096Mar1719:41data [[email protected]/]#
到這裡 nfs基本上就配置好了 你可以從客戶端上面新建檔案了
轉載於:https://blog.51cto.com/771541213/1752036