1. 程式人生 > >配置NFS網絡存儲作為cinder的後端存儲

配置NFS網絡存儲作為cinder的後端存儲

zed 映射 一個 boot mes cbi openstac 客戶端 exe

安裝cinder和nfs
yum install -y openstack-cinder
yum install cifs-utils

在controller節點配置nfs

[[email protected] ~]# mkdir -p /data/nfs  #創建一個共享掛載資源的目錄
[[email protected] ~]# cat /etc/exports
/data/nfs *(rw,sync,root_squash) #NFS服務程序的配置文件為/etc/exports  sync   同時將數據寫入到內存與硬盤中,保證不丟失數據 rw   讀寫 no_root_squash   當NFS客戶端以root管理員訪問時,映射為NFS服務器的root管理員

啟動和啟用NFS服務程序。由於在使用NFS服務進行文件共享之前,需要使用RPC(Remote Procedure Call,遠程過程調用)服務將NFS服務器的IP地址和端口號等信息發送給客戶端。因此,在啟動NFS服務之前,還需要順帶重啟並啟用rpcbind服務程序,並將這兩個服務一並加入開機啟動項中

[[email protected] ~]# systemctl resatrt rpcbind
[[email protected] ~]# systemctl enable rpcbind
[[email protected] ~]# systemctl start nfs-server
[[email protected] ~]# systemctl enable nfs-server

使用showmount命令查詢NFS服務器的遠程共享信息

[[email protected] ~]# showmount -e 192.168.100.10
Export list for 192.168.100.10:
/data/nfs *

測試掛載

[[email protected] ~]# mount 192.168.100.10:/data/nfs /mnt/
192.168.100.10:/data/nfs nfs4      197G   19G  169G  10% /mnt
#掛載成功
[[email protected] ~]# umount /mnt/
[[email protected] ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root ext4      2.9T  1.8G  2.8T   1% /
devtmpfs                devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs                   tmpfs     7.8G     0  7.8G   0% /dev/shm
tmpfs                   tmpfs     7.8G   17M  7.8G   1% /run
tmpfs                   tmpfs     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/md126p2            xfs       495M  129M  367M  27% /boot
tmpfs                   tmpfs     1.6G     0  1.6G   0% /run/user/0

配置nfs作為cinder後端存儲

[[email protected] ~]# vi /etc/cinder/cinder.conf 
[DEFAULT]
volume_driver = cinder.volume.drivers.nfs.NfsDriver
nfs_shares_config = /etc/cinder/nfs.conf

去創建/etc/cinder/nfs.conf這個文件

[[email protected] ~]# vi /etc/cinder/nfs.conf
192.168.100.10:/data/nfs

重啟服務nfs後端存儲自動掛載

[[email protected] ~]# systemctl restart openstack-cinder-api.service
[[email protected] ~]# systemctl restart openstack-cinder-volume.service
[[email protected] ~]# systemctl restart openstack-cinder-scheduler.service
[[email protected] ~]# df -Th
Filesystem               Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  ext4      197G   19G  169G  10% /
devtmpfs                 devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs                    tmpfs     7.8G     0  7.8G   0% /dev/shm
tmpfs                    tmpfs     7.8G  8.7M  7.8G   1% /run
tmpfs                    tmpfs     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1                xfs       494M  126M  368M  26% /boot
/dev/loop0               iso9660   4.1G  4.1G     0 100% /opt/centos
/dev/loop1               iso9660   2.7G  2.7G     0 100% /opt/iaas
tmpfs                    tmpfs     1.6G     0  1.6G   0% /run/user/0
192.168.100.10:/data/nfs nfs4      197G   19G  169G  10% /var/lib/cinder/mnt/cfee723fff086429eb82121076ac5407

創建volume測試

[[email protected] ~]# cinder create --display-name ‘volume‘ 1
+--------------------------------+--------------------------------------+
|            Property            |                Value                 |
+--------------------------------+--------------------------------------+
|          attachments           |                  []                  |
|       availability_zone        |                 nova                 |
|            bootable            |                false                 |
|      consistencygroup_id       |                 None                 |
|           created_at           |      2019-04-24T15:36:11.000000      |
|          description           |                 None                 |
|           encrypted            |                False                 |
|               id               | d259218e-45ec-4d31-a97c-b7e006cf957e |
|            metadata            |                  {}                  |
|        migration_status        |                 None                 |
|          multiattach           |                False                 |
|              name              |                volume                |
|     os-vol-host-attr:host      |                 None                 |
| os-vol-mig-status-attr:migstat |                 None                 |
| os-vol-mig-status-attr:name_id |                 None                 |
|  os-vol-tenant-attr:tenant_id  |   89b7ee9ffd73479b9446a3bf296bacbb   |
|       replication_status       |               disabled               |
|              size              |                  1                   |
|          snapshot_id           |                 None                 |
|          source_volid          |                 None                 |
|             status             |               creating               |
|           updated_at           |                 None                 |
|            user_id             |   3469ea43ec3345d2a29606c4566cd43a   |
|          volume_type           |                 None                 |
+--------------------------------+--------------------------------------+
[[email protected] ~]# openstack volume list
+--------------------------------------+--------------+--------+------+-------------+
| ID                                   | Display Name | Status | Size | Attached to |
+--------------------------------------+--------------+--------+------+-------------+
| d259218e-45ec-4d31-a97c-b7e006cf957e | volume       | error  |    1 |             |
+--------------------------------------+--------------+--------+------+-------------+

#volume狀態erros 去查看日誌

[[email protected] cinder]# tail -f volume.log 
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher   File "/usr/lib/python2.7/site-packages/cinder/utils.py", line 148, in execute
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher     return processutils.execute(*cmd, **kwargs)
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher   File "/usr/lib/python2.7/site-packages/oslo_concurrency/processutils.py", line 389, in execute
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher     cmd=sanitized_cmd)
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher ProcessExecutionError: Unexpected error while running command.
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher Command: truncate -s 1G /var/lib/cinder/mnt/cfee723fff086429eb82121076ac5407/volume-d259218e-45ec-4d31-a97c-b7e006cf957e
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher Exit code: 1
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher Stdout: u‘‘
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher Stderr: ‘truncate: cannot open \xe2\x80\x98/var/lib/cinder/mnt/cfee723fff086429eb82121076ac5407/volume-d259218e-45ec-4d31-a97c-b7e006cf957e\xe2\x80\x99 for writing: Permission denied\n‘
2019-04-24 11:36:13.359 461 ERROR oslo_messaging.rpc.dispatcher 

失敗原因沒有權限

[[email protected] ~]# ls /data/nfs/ -ld
drwxr-xr-x. 2 root root 4096 Apr 24 10:19 /data/nfs/
[[email protected] ~]# chmod o+w /data/nfs/
[[email protected] ~]# ls /data/nfs/ -ld   
drwxr-xrwx. 2 root root 4096 Apr 24 10:19 /data/nfs/

重新創建volume測試

[[email protected] ~]# cinder create --display-name ‘volume‘ 1
+--------------------------------+--------------------------------------+
|            Property            |                Value                 |
+--------------------------------+--------------------------------------+
|          attachments           |                  []                  |
|       availability_zone        |                 nova                 |
|            bootable            |                false                 |
|      consistencygroup_id       |                 None                 |
|           created_at           |      2019-04-24T15:41:56.000000      |
|          description           |                 None                 |
|           encrypted            |                False                 |
|               id               | 16b0c969-c71f-47e0-b898-1c2098e41338 |
|            metadata            |                  {}                  |
|        migration_status        |                 None                 |
|          multiattach           |                False                 |
|              name              |                volume                |
|     os-vol-host-attr:host      |                 None                 |
| os-vol-mig-status-attr:migstat |                 None                 |
| os-vol-mig-status-attr:name_id |                 None                 |
|  os-vol-tenant-attr:tenant_id  |   89b7ee9ffd73479b9446a3bf296bacbb   |
|       replication_status       |               disabled               |
|              size              |                  1                   |
|          snapshot_id           |                 None                 |
|          source_volid          |                 None                 |
|             status             |               creating               |
|           updated_at           |                 None                 |
|            user_id             |   3469ea43ec3345d2a29606c4566cd43a   |
|          volume_type           |                 None                 |
+--------------------------------+--------------------------------------+
[[email protected] ~]# cinder list
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
|                  ID                  |   Status  |  Name  | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| 16b0c969-c71f-47e0-b898-1c2098e41338 | available | volume |  1   |      -      |  false   |             |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+

volume狀態可用

[[email protected] ~]# ls /data/nfs/
volume-16b0c969-c71f-47e0-b898-1c2098e41338
#volume被寫入nfs作為後端存儲

配置NFS網絡存儲作為cinder的後端存儲