阿里雲ECS上實現NFS掛載

 

1. 背景

由於項目需要,現在需要在阿里雲上多臺服務器上共享一些靜態的文件數據。開始時選型方案有:OSS對象存儲、NAS存儲、自己搭建NFS;考慮成本需要,選擇了自己搭建NFS。 項目在阿里金融雲上,金融雲上產品比公有云貴多了。 下面講解過程。

注意:你的ECS是否在一個區,且是否在一個安全組。如果兩臺ECS不在同一個安全組,因此需要在各自的安全組設置規則,在內網進出方向分別添加對方的IP地址。

image

 

2. 過程

2.1 服務端

 

2.1.1 安裝    
yum install nfs-utils –y

 

2.1.2 修改配置文件    
[root@test02 home]# vim /etc/exports    
/home/nfstest 10.0.18.1(rw,sync,no_root_squash)    
/home/nfstest 10.0.16.120(rw,sync,no_root_squash)

#新建目錄

mkdir –p /home/nfstest

no_root_squash:登入 NFS 主機使用分享目錄的使用者,如果是 root 的話,那麼對於這個分享的目錄來說,他就具有 root 的權限!這個項目『極不安全』,不建議使用!    
root_squash:在登入 NFS 主機使用分享之目錄的使用者如果是 root 時,那麼這個使用者的權限將被壓縮成爲匿名使用者,通常他的 UID 與 GID 都會變成 nobody 那個系統賬號的身份;


2.1.3 啓動服務    
service rpcbind start #啓動端口轉發    
service nfs start #啓動NFS

chkconfig rpcbind on #rpcbind 加入啓動項  
chkconfig nfs on #nfs加入啓動項  
啓動後如果修改了目錄,可執行exprotfs -rv 實現刷新

 

2.1.4 添加防火牆規則

iptables -I INPUT -p tcp -m multiport --dports 875,2049,111,28300,5076,39927,46286 -j ACCEPT    
iptables -I INPUT -p udp -m multiport --dports 875,2049,111,37747,31166,9292,57181 -j ACCEPT

注意:由於要開放的端口較多且不連續,最好的做法是修改相應的端口。 可以參考我的另外一篇博文

http://pizibaidu.blog.51cto.com/1361909/1662428

 

2.2 客戶端

 

2.2.1 安裝    
yum install nfs-utils –y


2.2.2 掛載    
a. 立一個目錄用來作掛接點    
mkdir -p /home/nfs    
b、進行掛接    
mount -t nfs 10.0.16.122:/home/nfstest /home/nfs -o proto=tcp -o nolock    
c、取消掛接    
umount /home/nfs

 

3. 遇到的問題

 

3.1 如果客戶端不安裝nfs-utils會報如下錯誤:

mount: wrong fs type, bad option, bad superblock on 10.0.16.122:/home/nfstest,    
        missing codepage or helper program, or other error    
        (for several filesystems (e.g. nfs, cifs) you might    
        need a /sbin/mount.<type> helper program)    
        In some cases useful info is found in syslog - try    
        dmesg | tail  or so

解決方法:yum install nfs-utils –y

 

 

3.2 clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

掛載時報的錯誤。

解決方法: 由於服務端防火牆的阻止,需要把所有的端口都加進去。需要把那些端口加入防火牆,可以執行命令: rpcinfo -p 10.0.16.122

或者關掉防火牆

   # rpcinfo -p 10.0.16.122

    100000    4   tcp    111  portmapper    
     100000    3   tcp    111  portmapper    
     100000    2   tcp    111  portmapper    
     100000    4   udp    111  portmapper    
     100000    3   udp    111  portmapper    
     100000    2   udp    111  portmapper    
     100011    1   udp    875  rquotad    
     100011    2   udp    875  rquotad    
     100011    1   tcp    875  rquotad    
     100011    2   tcp    875  rquotad    
     100005    1   udp  37747  mountd    
     100005    1   tcp   5076  mountd    
     100005    2   udp  31166  mountd    
     100005    2   tcp  39927  mountd    
     100005    3   udp   9292  mountd    
     100005    3   tcp  28300  mountd    
     100003    2   tcp   2049  nfs    
     100003    3   tcp   2049  nfs    
     100003    4   tcp   2049  nfs    
     100227    2   tcp   2049  nfs_acl    
     100227    3   tcp   2049  nfs_acl    
     100003    2   udp   2049  nfs    
     100003    3   udp   2049  nfs    
     100003    4   udp   2049  nfs    
     100227    2   udp   2049  nfs_acl    
     100227    3   udp   2049  nfs_acl    
     100021    1   udp  57181  nlockmgr    
     100021    3   udp  57181  nlockmgr    
     100021    4   udp  57181  nlockmgr    
     100021    1   tcp  46286  nlockmgr    
     100021    3   tcp  46286  nlockmgr    
     100021    4   tcp  46286  nlockmgr

 

3.3 nfs rpc.mountd: svc_tli_create: could not open connection for udp6

啓動NFS報錯如下:    
Starting NFS mountd: rpc.mountd: svc_tli_create: could not open connection for udp6    
rpc.mountd: svc_tli_create: could not open connection for tcp6    
rpc.mountd: svc_tli_create: could not open connection for udp6    
rpc.mountd: svc_tli_create: could not open connection for tcp6    
rpc.mountd: svc_tli_create: could not open connection for udp6    
rpc.mountd: svc_tli_create: could not open connection for tcp6

解決辦法:

修改如下配置文件,然後重啓服務即可。    
[root@localhost ~]# vi /etc/netconfig    
udp tpi_clts v inet udp - -    
tcp tpi_cots_ord v inet tcp - -    
#udp6 tpi_clts v inet6 udp - -    
#tcp6 tpi_cots_ord v inet6 tcp - -    
rawip tpi_raw - inet - - -    
local tpi_cots_ord - loopback - - -    
unix tpi_cots_ord - loopback - - -

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章