块存储服务(Block Storage Service),项目代号为cinder,作为 OpenStack 的块存储服务,为 Instance 提供虚拟磁盘,其类似AWS的EBS(Elastic Block Storage),它们之间的区别在于存储卷暴露给虚拟机实例的方式。在OpenStack中,通过iSCSI暴露LVM卷组(VG)对卷进行管理,所以使用cinder的存储节点都会有VG。
cinder在控制节点上需要安装openstack-cinder,对应要启动的服务有:cinder-api、cinder-scheduler。修改好配置后,需要启动:openstack-cinder-api.service openstack-cinder-scheduler.service

cinder在存储节点上需要安装openstack-cinder lvm2 device-mapper-persistent-data openstack-cinder targetcli python-keystone
cinder在存储节点上运行的服务是:cinder-volume,当然还需启动其依赖的LVM、target服务。修改好配置后,需要启动:lvm2-lvmetad.service、openstack-cinder-volume.service target.service

 

1、使用数据库访问客户端以 root 用户身份连接到数据库服务器:
# mysql -uroot -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.3.20-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

2、创建 cinder 数据库
MariaDB [(none)]> CREATE DATABASE cinder default character set utf8;

3、授予对 cinder 数据库的适当访问权限
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' \
  IDENTIFIED BY 'CINDER_DBPASS';
  
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' \
  IDENTIFIED BY 'CINDER_DBPASS';
  
4、创建cinder用户
# openstack user create --domain default --password=cinder cinder

5、将admin角色添加到cinder用户
# openstack role add --project service --user cinder admin

6、创建cinderv2和cinderv3服务实体
# openstack service create --name cinderv2 \
  --description "OpenStack Block Storage" volumev2
  
# openstack service create --name cinderv3 \
  --description "OpenStack Block Storage" volumev3
  
7、创建块存储服务API端点
# openstack endpoint create --region RegionOne \
  volumev2 public http://controller:8776/v2/%\(project_id\)s
  
# openstack endpoint create --region RegionOne \
  volumev2 internal http://controller:8776/v2/%\(project_id\)s
  
# openstack endpoint create --region RegionOne \
  volumev2 admin http://controller:8776/v2/%\(project_id\)s
  
# openstack endpoint create --region RegionOne \
  volumev3 public http://controller:8776/v3/%\(project_id\)s
  
# openstack endpoint create --region RegionOne \
  volumev3 internal http://controller:8776/v3/%\(project_id\)s

# openstack endpoint create --region RegionOne \
  volumev3 admin http://controller:8776/v3/%\(project_id\)s
  
8、安装cinder服务
# yum install openstack-cinder -y

9、修改配置文件/etc/cinder/cinder.conf
# cd /etc/cinder/ && mv cinder.conf cinder.conf.source && cat cinder.conf.source |grep -Ev "^#|^$" > cinder.conf && chown cinder:root cinder.conf
# vi /etc/cinder/cinder.conf

在 [database] “配置数据库访问”部分中
[database]
# ...
connection = mysql+pymysql://cinder:CINDER_DBPASS@controller/cinder

在【DEFAULT】部分中,配置RabbitMQ消息队列访问
[DEFAULT]
# ...
transport_url = rabbit://openstack:openstack@controller

在 [DEFAULT] and [keystone_authtoken] 部分中,配置 Identity service 访问权限
[DEFAULT]
# ...
auth_strategy = keystone

[keystone_authtoken]
# ...
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = cinder

在【DEFAULT】部分,配置my_ip选项以使用控制器节点的管理界面IP地址
[DEFAULT]
# ...
my_ip = 192.168.58.100

在【oslo_concurrency】部分中,配置锁路径
[oslo_concurrency]
# ...
lock_path = /var/lib/cinder/tmp

10、同步cinder数据库
# su -s /bin/sh -c "cinder-manage db sync" cinder

11、修改/etc/nova/nova.conf
# vim /etc/nova/nova.conf
在【cinder】部分,启用后端存储
[cinder]
os_region_name = RegionOne
  
12、重新启动nova-api服务
# systemctl restart openstack-nova-api.service

13、启动cinder-api、cinder-scheduler服务并将其设置为开机自启动
# systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
  
14、验证控制节点cinder-scheduler,状态为up即正常
# openstack volume service list
+------------------+---------------+------+---------+-------+----------------------------+
| Binary           | Host          | Zone | Status  | State | Updated At                 |
+------------------+---------------+------+---------+-------+----------------------------+
| cinder-scheduler | controller    | nova | enabled | up    | 2024-02-28T18:17:45.000000 |
| cinder-volume    | compute02@lvm | nova | enabled | up    | 2024-02-28T18:17:47.000000 |
+------------------+---------------+------+---------+-------+----------------------------+