天天看點

[優化篇]OpenStack的Cinder後端存儲技術——NFS

題記

OpenStack的Cinder可以為虛拟機提供背景塊存儲資源,來擴充虛拟機的存儲資源,而且Cinder的後端存儲可以支援非常多的存儲技術,包括NFS、GlusterFS、Ceph、以及不同存儲廠商的硬體驅動,預設幫助文檔上支援的是LVM,本文主要介紹基于NFS的背景存儲。

環境

Ubuntu 14.04 LTS、OpenStack for icehouse 

使用VM Ware搭建的三個節點的GRE網絡架構的虛拟機,另外添加了一個存儲節點。

操作步驟

我是将原來的LVM方式修改為NFS。

存儲節點

1、在存儲節點安裝rpcbind和nfs-kernel-server軟體包 

2、建立一個路徑,共享出去例如/data/nfs

3、修改權限,建議使用cinder使用者群組

root@cinder:~# ll /data/
total 
drwxr-xr-x   root   root    Jul  : ./
drwxr-xr-x  root   root    Jul  : ../
drwxr-xr-x   cinder cinder  Jul  : nfs/
           

4、添加/etc/exportfs配置,共享出去

[email protected]:~# cat /etc/exports 
# /etc/exports: the access control list for filesystems which may be exported
#       to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/data/nfs *(rw,sync,no_root_squash)
           

5、重新開機rpcbind和nfs-kernel-server服務 

6、建立/etc/cinder/nfs_shares檔案,并修改其組和權限

-rw-r-----   root   cinder     Jul  : nfs_shares
           

7、修改/etc/cinder/cinder.conf配置檔案,添加如下内容[DEFAULT]

#添加nfs驅動
volume_driver=cinder.volume.drivers.nfs.NfsDriver
#建立nfs共享存儲檔案,可以自定義,就是步驟6建立的
nfs_shares_config=/etc/cinder/nfs_shares
#指定挂載點
nfs_mount_point_base=$state_path/mnt
           

8、重新開機cinder-volume服務 

9、檢視mount挂載資訊 

我們可以看到重新開機完cinder-volume服務之後,可以看到系統會自動mount上相關路徑

:/data/nfs on /var/lib/cinder/mnt/a01856b116a3558d2981626e type nfs4 (rw,relatime,vers=,rsize=,wsize=,namlen=,hard,proto=tcp,port=,timeo=,retrans=,sec=sys,clientaddr=,local_lock=none,addr=)
           

控制節點 

更新/etc/cinder/cinder.conf的nfs驅動

計算節點 

1、nova.conf更新cinder相關配置

最後,建議在所有計算和控制節點安裝rpcbind、nfs-common、nfs-kernel-server軟體包,我在實施過程中遇到了一個問題,我可以建立好的我雲硬碟,但是就是挂接不到我的虛拟機上。 

最後檢視計算節點/var/log/nova/nova-compute.log有以下錯誤

-- ::  TRACE oslo.messaging.rpc.dispatcher Stderr: u'mount: wrong fs type, bad option, bad superblock on 192.168.3.185:/data/nfs,\n       missing codepage or helper program, or other error\n       (for several filesystems (e.g. nfs, cifs) you might\n       need a /sbin/mount.<type> helper program)\n       In some cases useful info is found in syslog - try\n       dmesg | tail  or so\n\n'
-- ::  TRACE oslo.messaging.rpc.dispatcher
-- ::  ERROR oslo.messaging._drivers.common [-] Returning exception Unexpected error while running command.
Command: sudo nova-rootwrap /etc/nova/rootwrap.conf mount -t nfs :/data/nfs /var/lib/nova/mnt/a01856b116a3558d2981626e
Exit code: 
Stdout: u''
Stderr: u'mount: wrong fs type, bad option, bad superblock on 192.168.3.185:/data/nfs,\n       missing codepage or helper program, or other error\n       (for several filesystems (e.g. nfs, cifs) you might\n       need a /sbin/mount.<type> helper program)\n       In some cases useful info is found in syslog - try\n       dmesg | tail  or so\n\n' to caller
@                                                                                                                                                                                                         @                   
           

最後在計算節點安裝上述nfs安裝包,問題解決。

驗證

1、我們使用horizon建立一個1GB的雲硬碟,我們可以看到cinder的挂載點

root@cinder:~# ll /var/lib/cinder/mnt/74877087a01856b116a3558d2981626e/
total 
drwxr-xr-x  cinder cinder        Jul  : ./
drwxr-xr-x  cinder cinder        Jul  : ../
-rw-rw-rw-      ntp     Jul  : volume-d46c486d-fe--b5-ca9353
           

2、其實該檔案存儲在共享檔案夾中/data/nfs

root@cinder:~# ll /data/nfs
total 
drwxr-xr-x  cinder cinder        Jul  : ./
drwxr-xr-x  root   root          Jul  : ../
-rw-rw-rw-      ntp     Jul  : volume-d46c486d-fe--b5-ca9353
           

3、檢視cinder清單

[優化篇]OpenStack的Cinder後端存儲技術——NFS
[email protected]:~# cinder list
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
|                  ID                  | Status | Display Name | Size | Volume Type | Bootable |             Attached to              |
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
| d46c486d-71fe-4863-95b5-864621ca9353 | in-use |      a       |  1   |     None    |  false   | 614a2641-1e8d-4442-9704-6ab62e3f39d5 |
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+