標籤:centos 6.4x64搭建nfs服務
網路檔案系統(NFS,NetworkFileSystem)是一種將遠程主機上的分區(目錄)經網路掛載到本地系統的一種機制,通過對網路檔案系統的支援,使用者可以在本地系統上像操作本地分區一樣來對遠程主機的共用分區(目錄)進行操作。
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6C/64/wKiom1VIXkvxVtvgAAEq1MeSNwA007.jpg" title="nfs.JPG" alt="wKiom1VIXkvxVtvgAAEq1MeSNwA007.jpg" />
一、環境
系統:CentOS 6.4x64位迷你安裝
nfs-server:192.168.3.54
nfs-client:192.168.3.55
二、server端安裝NFS服務
NFS軟體包由nfs-utils提供,依賴於rpcbind服務
[[email protected] ~]# yum install nfs-utils rpcbind -y
配置/etc/exports檔案,將/data/nfs共用出去
[[email protected] ~]# vim /etc/exports/data/nfs 192.168.3.0/24(rw,sync,all_squash)#sync 保持資料同步,也就是將資料同步寫入記憶體和硬碟。這可能導致效率降低#all_squash 將所有使用NFS伺服器共用目錄的使用者都映射為匿名帳號
配置完成後準備啟動服務,需要先啟動rpcbind,再啟動nfs
[[email protected] ~]# service rpcbind startStarting rpcbind: [ OK ][[email protected] ~]# service nfs startStarting NFS services: exportfs: Failed to stat /data/nfs: No such file or directory [ OK ]Starting NFS quotas: [ OK ]Starting NFS mountd: [ OK ]Starting NFS daemon: [ OK ]Starting RPC idmapd: [ OK ]#上面的報錯資訊,提示我們資料共用目錄不存在,建立資料共用目錄[[email protected] ~]# mkdir -p /data/nfs#重新啟動NFS服務[[email protected] ~]# service nfs restartShutting down NFS daemon: [ OK ]Shutting down NFS mountd: [ OK ]Shutting down NFS quotas: [ OK ]Shutting down NFS services: [ OK ]Shutting down RPC idmapd: [ OK ]Starting NFS services: [ OK ]Starting NFS quotas: [ OK ]Starting NFS mountd: [ OK ]Starting NFS daemon: [ OK ]Starting RPC idmapd: [ OK ]
為了避免對實驗過程造成影響,我們關閉iptables
[[email protected] ~]# service iptables stop
三、用戶端配置
用戶端只需要安裝nfs-utils即可
[[email protected] ~]# yum install nfs-utils -y
查看server端192.168.3.54提供了哪些資料共用服務
[[email protected] ~]# showmount -e 192.168.3.54Export list for 192.168.3.54:/data/nfs 192.168.3.0/24
掛載nfs目錄到/mnt目錄下
[[email protected] ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda3 18G 1.3G 16G 8% /tmpfs 495M 0 495M 0% /dev/shm/dev/sda1 194M 28M 156M 16% /boot#使用nfs協議將192.168.3.54:/data/nfs掛載到/mnt目錄下[[email protected] ~]# mount -t nfs 192.168.3.54:/data/nfs /mnt#查看掛載結果[[email protected] ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda3 18G 1.3G 16G 8% /tmpfs 495M 0 495M 0% /dev/shm/dev/sda1 194M 28M 156M 16% /boot192.168.3.54:/data/nfs 18G 1.6G 16G 10% /mnt
測試:在/mnt目錄下建立檔案nfs-client.txt
[[email protected] ~]# cd /mnt[[email protected] mnt]# touch nfs-client.txttouch: cannot touch `nfs-client.txt‘: Permission denied#結果顯示許可權拒絕,雖然我們在/etc/exports賦予了rw許可權,但是目錄本身並沒有寫入權限
修改nfs-server端/data/nfs的許可權
#nfs預設使用的使用者是匿名使用者nfsnobody,我們修改屬主為nfsnobody即可[[email protected] ~]# chown -R nfsnobody /data/nfs/[[email protected] ~]# ll /data/total 8drwxr-xr-x 2 nfsnobody root 4096 May 5 14:19 nfs
在nfs-client端重新建立檔案nfs-client
[[email protected] mnt]# pwd/mnt[[email protected] mnt]# touch nfs-client.txt #現在能夠正常建立檔案了[[email protected] mnt]# lltotal 0-rw-r--r-- 1 nfsnobody nfsnobody 0 May 5 14:36 nfs-client.txt
在nfs-server端查看檔案
[[email protected] ~]# ll /data/nfs/total 0-rw-r--r-- 1 nfsnobody nfsnobody 0 May 5 14:36 nfs-client.txt
在nfs-server端建立檔案nfs-server.txt檔案
[[email protected] ~]# touch /data/nfs/nfs-server.txt
在nfs-client端查看結果
[[email protected] mnt]# ll /mnt/total 0-rw-r--r-- 1 nfsnobody nfsnobody 0 May 5 14:36 nfs-client.txt-rw-r--r-- 1 root root 0 May 5 14:40 nfs-server.txt
註:nfs-sever端修改/etc/exports後,要使用/etc/init.d/nfs reload重新載入設定檔,千萬不要使用restart重啟nfs服務。因為在工作中nfs服務端可能是向多台伺服器提供資料共用服務,使用restart重啟nfs服務,會使前端程式的寫入操作失敗,這是不能容忍的。
本文出自 “ly36843營運” 部落格,請務必保留此出處http://ly36843.blog.51cto.com/3120113/1642063
CentOS 6.4x64搭建nfs服務