OpenStack(T版)——块存储(Cinder)服务介绍与安装

OpenStack 块存储(Cinder)是一个用于提供持久性存储的组件,它允许用户创建和管理虚拟机实例所需的块级存储卷。

想象一下,你有一个计算机硬盘,用于存储文件和数据。OpenStack 块存储就像是为虚拟机提供了一个硬盘,供它们存储数据。

使用块存储,你可以创建一个虚拟机需要的存储卷,然后将其附加到虚拟机实例上。这个存储卷就像是一个空白的硬盘,虚拟机可以在上面存储文件、操作系统和其他数据。 块存储的好处是它具有持久性,意味着存储卷中的数据不会随着虚拟机的关闭而丢失。当虚拟机重新启动时,它可以重新连接到之前附加的存储卷,并继续访问其中的数据。 另外,OpenStack 块存储还支持一些高级功能,例如创建快照(Snapshot)来备份存储卷的数据或创建卷的副本(Volume Replication)以提供冗余和容错能力。

OpenStack 块存储是一个为虚拟机提供持久性存储的组件,类似于为虚拟机提供了一个硬盘。它允许用户创建、管理和附加存储卷,以供虚拟机存储数据和操作系统。

安装和配置(controller)

官方文档

准备

在安装和配置Cinder块存储服务组件之前,首先创建数据库、服务证书和APIendpoint。

(1)创建数据库

①在操作系统终端连接数据库

[root@controller ~]# mysql -uroot -p000000

②创建cinder数据库

MariaDB [(none)]> CREATE DATABASE cinder;

③Cinder数据库的访问权限设置

MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%'  IDENTIFIED BY '000000';

④退出数据库

(2)加载admin user的环境变量

[root@controller ~]# source admin-openrc.sh 

(3)创建Identity服务凭据

①创建cinder用户

[root@controller ~]# openstack user create --domain default --password-prompt cinder
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | cdd102aa997d4bf3bba8d6902caebd7d |
| name                | cinder                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

②admin role 赋予 Cinder 用户和 service project

[root@controller ~]#  openstack role add --project service --user cinder admin

③创建Cinder 和 Cinder v2 service entity

[root@controller ~]# openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Block Storage          |
| enabled     | True                             |
| id          | 95bfea28c48f4780b33f6dfd0c9c2284 |
| name        | cinderv2                         |
| type        | volumev2                         |
+-------------+----------------------------------+
[root@controller ~]# openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Block Storage          |
| enabled     | True                             |
| id          | d554116b699a41a19834a19e75fb4bfc |
| name        | cinderv3                         |
| type        | volumev3                         |
+-------------+----------------------------------+

(4)创建Cinder 块存储服务组件的API endpoint

[root@controller ~]# openstack endpoint create --region RegionOne  volumev2 public http://controller:8776/v2/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | a2db581e11224f47a43641959ba23989         |
| interface    | public                                   |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 95bfea28c48f4780b33f6dfd0c9c2284         |
| service_name | cinderv2                                 |
| service_type | volumev2                                 |
| url          | http://controller:8776/v2/%(project_id)s |
+--------------+------------------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne volumev2 internal   http://controller:8776/v2/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | 2f93a7d5aaca4310a1abcd1b6925a920         |
| interface    | internal                                 |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 95bfea28c48f4780b33f6dfd0c9c2284         |
| service_name | cinderv2                                 |
| service_type | volumev2                                 |
| url          | http://controller:8776/v2/%(project_id)s |
+--------------+------------------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne  volumev2 admin http://controller:8776/v2/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | 86d6d9a9afda4e8eba86883f7208cb89         |
| interface    | admin                                    |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 95bfea28c48f4780b33f6dfd0c9c2284         |
| service_name | cinderv2                                 |
| service_type | volumev2                                 |
| url          | http://controller:8776/v2/%(project_id)s |
+--------------+------------------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne  volumev3 public http://controller:8776/v3/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | 905fe2ac7f8842a8955a813d5ef1c28b         |
| interface    | public                                   |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | d554116b699a41a19834a19e75fb4bfc         |
| service_name | cinderv3                                 |
| service_type | volumev3                                 |
| url          | http://controller:8776/v3/%(project_id)s |
+--------------+------------------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne  volumev3 internal http://controller:8776/v3/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | f2342b5ab4ce401598068630b1b56eb8         |
| interface    | internal                                 |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | d554116b699a41a19834a19e75fb4bfc         |
| service_name | cinderv3                                 |
| service_type | volumev3                                 |
| url          | http://controller:8776/v3/%(project_id)s |
+--------------+------------------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne  volumev3 admin http://controller:8776/v3/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | 24734a6eec464c029f0d7da0d74a1045         |
| interface    | admin                                    |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | d554116b699a41a19834a19e75fb4bfc         |
| service_name | cinderv3                                 |
| service_type | volumev3                                 |
| url          | http://controller:8776/v3/%(project_id)s |
+--------------+------------------------------------------+

安装和配置Cinder块存储服务组件

(1)安装软件包

[root@controller ~]# yum install -y openstack-cinder

(2)编辑/etc/cinder/cinder.conf 文件,完成下面的操作

①在[database]部分中,配置数据库访问

[root@controller ~]# vim /etc/cinder/cinder.conf 
[database]
connection = mysql+pymysql://cinder:000000@controller/cinder

②在[DEFAULT]部分中,配置RabbitMQ 消息队列访问

[DEFAULT]
transport_url = rabbit://openstack:000000@controller

③在[DEFAULT][keystone_authtoken]部分中,配置身份服务访问

[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 = 000000

⑤在[DEFAULT]部分中,配置选项my_ip以使用控制器节点的管理接口 IP 地址

[DEFAULT]
my_ip = 192.168.200.10

⑥在[oslo_concurrency]部分中,配置锁定路径

[oslo_concurrency]
lock_path = /var/lib/cinder/tmp

(3)将Cinder块存储服务信息同步到Cinder数据库中

[root@controller ~]# su -s /bin/sh -c "cinder-manage db sync" cinder  # 返回信息不要管
Deprecated: Option "logdir" from group "DEFAULT" is deprecated. Use option "log-dir" from group "DEFAULT".

(4)配置nova文件

[root@controller ~]# vim /etc/nova/nova.conf 
[cinder]
os_region_name = RegionOne

完成安装

①重启nova服务

[root@controller ~]# systemctl restart openstack-nova-api.service

②启动Cinder块存储服务组件并设置开机自启

[root@controller ~]# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service  &&  systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service

安装和配置(compute)

准备

在安装Cinder块存储服务组件之前,需要首先确定使用的块存储设备。

[root@compute ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 41.1G  0 lvm  /home
sdb               8:16   0   20G  0 disk            # 这个就是我们添加的硬盘
sr0              11:0    1  4.4G  0 rom  

(1)安装软件包

[root@compute ~]# yum install -y  lvm2 device-mapper-persistent-data

(2)启动LVM元数据服务并设置开机自启

[root@compute ~]# systemctl start lvm2-lvmetad.service  &&  systemctl enable lvm2-lvmetad.service

(3)创建LVM物理卷/dev/sdb

[root@compute ~]# pvcreate /dev/sdb 
  Physical volume "/dev/sdb" successfully created.
[root@compute ~]# vgcreate cinder-volumes /dev/sdb
  Volume group "cinder-volumes" successfully created

(4)配置LVM文件

[root@compute ~]# vim /etc/lvm/lvm.conf
devices {
          filter = [ "a/sdb/", "r/.*/"]
# 根据这个配置,只有 "/dev/sdb" 会被作为可用设备,并被 LVM 管理器使用
# 其他设备将被排除在外

安装和配置Cinder块存储服务组件

(1)安装软件包

[root@compute ~]# yum install -y  openstack-cinder targetcli python-keystone

(2)配置文件

编辑/etc/cinder/cinder.conf文件并完成以下操作

①在[database]部分中,配置数据库访问

[root@compute ~]# vim /etc/cinder/cinder.conf

[database]
connection = mysql+pymysql://cinder:000000@controller/cinder

②在[DEFAULT]部分中,配置RabbitMQ 消息队列访问

[DEFAULT]
transport_url = rabbit://openstack:000000@controller

③在[DEFAULT][keystone_authtoken]部分中,配置身份服务访问

[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 = 000000

④在[DEFAULT]部分中,配置my_ip选项

my_ip = 192.168.200.20

⑤在[lvm]节中添加

[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
target_protocol = iscsi
target_helper = lioadm

⑥在[DEFAULT]部分中,启用 LVM 后端

[DEFAULT]
enabled_backends = lvm

⑦在[DEFAULT]部分中,配置图像服务 API 的位置

[DEFAULT]
glance_api_servers = http://controller:9292

⑧在[oslo_concurrency]部分中,配置锁定路径

[oslo_concurrency]
lock_path = /var/lib/cinder/tmp

完成安装

启动块存储卷服务并设置开机自启

[root@compute ~]# systemctl start openstack-cinder-volume.service target.service   &&  systemctl enable openstack-cinder-volume.service target.service
# 自行查看log文件 如果有error就是有错误

验证

列出Cinder 块存储服务组件,看进程是否成功启动

[root@controller ~]# source admin-openrc.sh 
[root@controller ~]# openstack volume service list
+------------------+-------------+------+---------+-------+----------------------------+
| Binary           | Host        | Zone | Status  | State | Updated At                 |
+------------------+-------------+------+---------+-------+----------------------------+
| cinder-scheduler | controller  | nova | enabled | up    | 2023-06-29T08:27:06.000000 |
| cinder-volume    | compute@lvm | nova | enabled | up    | 2023-06-29T08:27:09.000000 |
+------------------+-------------+------+---------+-------+----------------------------+

Cinder服务的基本使用

创建块存储

通过命令创建块存储,大小为2G,名称为 volume

[root@controller ~]# openstack volume create --size 2 volume
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attachments         | []                                   |
| availability_zone   | nova                                 |
| bootable            | false                                |
| consistencygroup_id | None                                 |
| created_at          | 2023-06-29T09:58:16.000000           |
| description         | None                                 |
| encrypted           | False                                |
| id                  | 51b8b246-14b0-4b1e-866f-d4fb17c1f4c6 |
| migration_status    | None                                 |
| multiattach         | False                                |
| name                | volume                               |
| properties          |                                      |
| replication_status  | None                                 |
| size                | 2                                    |
| snapshot_id         | None                                 |
| source_volid        | None                                 |
| status              | creating                             |
| type                | __DEFAULT__                          |
| updated_at          | None                                 |
| user_id             | fef5f8c16d3d4b9d849bc1488bf50a21     |
+---------------------+--------------------------------------+

查看块存储

[root@controller ~]# openstack volume list
+--------------------------------------+--------+----------+------+-------------+
| ID                                   | Name   | Status   | Size | Attached to |
+--------------------------------------+--------+----------+------+-------------+
| 51b8b246-14b0-4b1e-866f-d4fb17c1f4c6 | volume | reserved |    2 |             |
+--------------------------------------+--------+----------+------+-------------+

挂载云硬盘

必须事先创建好云主机才能挂载云硬盘
使用命令将刚刚创建的 volume 块存储添加至云主机 csq上

[root@controller ~]# openstack server add volume csq volume

使用命令查看块存储列表信息

[root@controller ~]# openstack volume list
+--------------------------------------+--------+--------+------+------------------------------+
| ID                                   | Name   | Status | Size | Attached to                  |
+--------------------------------------+--------+--------+------+------------------------------+
| 51b8b246-14b0-4b1e-866f-d4fb17c1f4c6 | volume | in-use |    2 | Attached to csq on /dev/vdb  |
+--------------------------------------+--------+--------+------+------------------------------+

image-20230629180208125

还有相关扩展卷的操作可以参考这篇博客:glance,nova,cinder,swift服务基本使用

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐