安装cinder和nfs

yum install -y openstack-cinder
yum install cifs-utils

在controller节点配置nfs

[root@controller ~]# mkdir -p /data/nfs  #创建一个共享挂载资源的目录
[root@controller ~]# 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服务程序,并将这两个服务一并加入开机启动项中

[root@controller ~]# systemctl resatrt rpcbind
[root@controller ~]# systemctl enable rpcbind
[root@controller ~]# systemctl start nfs-server
[root@controller ~]# systemctl enable nfs-server

使用showmount命令查询NFS服务器的远程共享信息

[root@controller ~]# showmount -e 192.168.100.10
Export list for 192.168.100.10:
/data/nfs *

测试挂载

[root@compute ~]# mount 192.168.100.10:/data/nfs /mnt/
192.168.100.10:/data/nfs nfs4      197G   19G  169G  10% /mnt
#挂载成功
[root@compute ~]# umount /mnt/
[root@compute ~]# 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后端存储

[root@controller ~]# vi /etc/cinder/cinder.conf 
[DEFAULT]
volume_driver = cinder.volume.drivers.nfs.NfsDriver
nfs_shares_config = /etc/cinder/nfs.conf

去创建/etc/cinder/nfs.conf这个文件

[root@controller ~]# vi /etc/cinder/nfs.conf
192.168.100.10:/data/nfs

重启服务nfs后端存储自动挂载

[root@controller ~]# systemctl restart openstack-cinder-api.service
[root@controller ~]# systemctl restart openstack-cinder-volume.service
[root@controller ~]# systemctl restart openstack-cinder-scheduler.service
[root@controller ~]# 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测试

[root@controller ~]# 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                 |
+--------------------------------+--------------------------------------+
[root@controller ~]# openstack volume list
+--------------------------------------+--------------+--------+------+-------------+
| ID                                   | Display Name | Status | Size | Attached to |
+--------------------------------------+--------------+--------+------+-------------+
| d259218e-45ec-4d31-a97c-b7e006cf957e | volume       | error  |    1 |             |
+--------------------------------------+--------------+--------+------+-------------+

#volume状态erros 去查看日志

[root@controller 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 

失败原因没有权限

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

重新创建volume测试

[root@controller ~]# 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                 |
+--------------------------------+--------------------------------------+
[root@controller ~]# cinder list
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
|                  ID                  |   Status  |  Name  | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| 16b0c969-c71f-47e0-b898-1c2098e41338 | available | volume |  1   |      -      |  false   |             |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+

volume状态可用

[root@controller ~]# ls /data/nfs/
volume-16b0c969-c71f-47e0-b898-1c2098e41338
#volume被写入nfs作为后端存储