安裝簡單的NFS服務器(CentOS 6.5)
阿新 • • 發佈:2017-05-16
重啟 簡單 程序 ber centos ports iptable tmpfs -h
一、環境
系統: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 start
Starting rpcbind: [ OK ]
[[email protected]/* */ ~] # service nfs start
Starting 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 restart
Shutting 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.54
Export list for 192.168.3.54:
/data/nfs 192.168.3.0 /24
|
掛載nfs目錄到/mnt目錄下
[[email protected] ~] # df -h
Filesystem 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 -h
Filesystem 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
192.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.txt
touch : 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 8
drwxr-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] # ll
total 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服務,會使前端程序的寫入操作失敗,這是不能容忍的。
安裝簡單的NFS服務器(CentOS 6.5)