1,NFS服務器的安裝
在CentOS系統中,默認情況下已經安裝了NFS文件系統,如果沒有安裝就需要手工安裝了
#rpm –q nfs-utils portmap
2, 查看NFS是否啓動
#service nfs starus #service portmap status
3,啓動NFS
#service nfs start #service portmap status
4,修改NFS系統配置文件
#vim /etc/exports
/home/yaronli/nfs_space *(sync,rw)
解釋說明:
/home/yaronli/nfs_space:共享目錄名
*:表示所有主機都可以連接改NFS
(sync,rw):設置選項
sync:設置NFS服務器同步寫磁盤,這樣不會輕易丟失數據,建議所有的NFS共享目錄都使用該選項 ro:設置輸出的共享目錄只讀,與rw不能共同使用 rw:設置輸出的共享目錄可讀寫,與ro不能共同使用
exports文件中“客戶端主機地址”字段可以使用多種形式表示主機地址
192.168.152.13 指定IP地址的主機 nfsclient.test.com 指定域名的主機 192.168.1.0/24 指定網段中的所有主機 *.test.com 指定域下的所有主機 * 所有主機
5,生效配置文件
命令#exportfs –rv 可以讓新設置的exports文件內容生效
以上是Server端的配置步驟
Client端的配置步驟如下:
1,直接mount到nfs server即可
# mount -t nfs 10.60.1.91:/home/yangguang/nfs_space /mnt/ 說明: 10.60.1.91:是nfs server的ip地址 /home/yangguang/nfs_space: 是nfs server中的共享目錄 /mnt:爲本地的目錄
執行成功後,即可在/mnt目錄中看到nfs server 掛載的內容
2,卸載已經掛載的nfs共享目錄
#umount /mnt/
常見問題:
>: mount -o nolock 10.78.28.103:/usr/n300 /mnt
mount: RPC: Unable to receive; errno = No route to host
mount: nfsmount failed: Bad file descriptor
mount: Mounting 10.78.28.103:/usr/n300 on /mnt failed: Bad file descriptor
如果有上面類似錯誤,有可能是如下原因
a:先ping客戶端能否連通服務器ip
RPC: Unable to receive; errno = No route to host 的原因
b:nfs服務器是否有防火牆屏蔽了對應端口
c:/etc/hosts.deny /etc/hosts.allow 是否屏蔽了客戶端ip
Bad file descriptor的原因
d:/etc/exports配置有問題,確保文件中的"()"是英文的,如果你從其他地方copy有可能 出現如上問題
解決辦法:
[root@localhost n300]# service iptables stop
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
[root@localhost n300]# service iptables status
Firewall is stopped.
[root@localhost n300]# cat /etc/hosts
hosts hosts.allow hosts.deny
[root@localhost n300]# cat /etc/hosts.deny
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
[root@localhost n300]# cat /etc/hosts.allow
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
[root@localhost n300]#
5: 解決上面問題後應該可以正確的mount了
>: mount -o nolock 10.78.28.103:/usr /mnt
mount: 10.78.28.103:/usr failed, reason given by server: Permission denied #還是有錯,iptable在作怪
mount: nfsmount failed: Bad file descriptor
mount: Mounting 10.78.28.103:/usr on /mnt failed: Bad file descriptor
>:
>:
>:####自給解決上面的錯誤
>:
>: mount -o nolock 10.78.28.103:/usr/n300 /mnt ##正確了
>:
>:
>: df
Filesystem Size Used Available Use% Mounted on
/dev/root 6.6M 6.6M 0 100% /
/dev/mtdblock/5 1.0M 68.0k 956.0k 7% /info
/dev/mtdblock/6 42.0M 3.3M 38.7M 8% /apps
/dev/mtdblock/7 5.0M 196.0k 4.8M 4% /logs
10.78.28.218:/home/webserver 8.4G 7.2G 780.8M 90% /tmp/mnt
10.78.28.103:/usr/n300 9.6G 6.7G 2.4G 73% /mnt
常用命令:
顯示當前主機中NFS服務器的輸出列表 # showmount -e 顯示當前主機NFS服務器中已經被NFS客戶機掛載使用的共享目錄 # showmount -d 顯示NFS服務器的輸出 # showmount -e 10.60.1.91