其他分享
首页 > 其他分享> > 【OpenStack】菜鸟学OpenStack之部署Train(8)

【OpenStack】菜鸟学OpenStack之部署Train(8)

作者:互联网

菜鸟学OpenStack之部署Train(8)

块存储(Cinder)服务安装配置

块存储(Cinder)服务概览

存储服务是为了数据保存而使用的,在OpenStack项目中被多个服务组件使用,非常重要。从数据保存时间的角度区分,存储可以分为两种:临时存储和持久存储。
临时存储是指数据被虚拟机实例使用,一旦虚拟机实例被关机、重启或删除,该虚拟机实例中的所有数据信息全部丢失。换言之,就是所有的数据都保存在临时存储中。在OpenStack项目中,部署完Nova计算服务组件后,用户可以使用nova boot命令创建虚拟机实例,这时虚拟机实例使用的就是临时存储,所有数据都保存在临时存储上,安全性没有保障。
持久存储包括对象存储、块存储和文件系统存储,它们维护数据持续可用,保证数据安全性,无论虚拟机实例是否终止。
下边从多个角度对存储特性进行描述:

特性临时存储块存储对象存储文件系统存储
用途运行操作系统或暂存数据空间作为持久性存储提供给虚拟机实例使用存储数据,包括虚拟机镜像作为持久性存储提供给虚拟机实例使用
访问方式文件系统块设备,能够进行分区、格式化和被挂载等API调用共享的文件系统服务,能够进行分区、格式化和被挂载等
访问途径虚拟机实例中虚拟机实例中任何地方虚拟机实例中
管理者Nova计算服务组件Cinder块存储服务组件Swift对象存储服务组件Manila共享文件系统存储
数据持久性虚拟机实例被关机删除删除删除
容量大小确定根据管理员对主机类型(flavor)的定义根据需求定义所有有效物理存储容量1.根据需求定义;2.扩大需求;3.用户磁盘配额;4.管理员设置磁盘容量限制
加密方式nova.conf文件中参数配置管理员启用卷加密功能不支持不支持
使用案例小容量磁盘大容量磁盘超大容量磁盘依赖于后端存储容量,当开启thin provisoning功能后,可以提供部分容量(不是全部申请容量)

OpenStack项目中的Cinder块存储服务组件为虚拟机实例提供了块存储设备,同时为管理块存储设备提供了一整套方法,如卷快照(Volume Snapshot)、卷类型(Volume Type)等。块存储类型是由驱动或者后端设备设置的驱动决定的,如NAS、NFS、SAN、ISCSI、Ceph或其他。Cinder块存储服务组件的API和cinder-scheduler服务通常运行在控制节点上,cinder_volume服务可以运行在控制节点、计算节点或者独立的存储节点上。

Cinder块存储服务组件由以下服务进程组成:

块存储又称为卷存储(Volume Storage),为用户提供基于数据块的存储设备访问用户对数据块存储设备的访问和交互是通过将数据块存储设备映射到正在运行的虚拟机实例上进行的,可以对其进行读/写、格式化等。

块存储属于持久存储,当取消块存储设备与虚拟机实例之间的映射或将块存储设备重新映射给其他虚拟机实例时,该块存储设备上的数据都不受影响,数据是完整的。换言之,只要该存储设备是存在的、无损坏的、完整的,那么其上的数据就是完整的、可用的。至于该块存储设备是否映射给其他虚拟机实例识别和使用,与其上已经保存的数据的完整性和可用性无关。块存储由OpenStack项目种的Cinder块存储服务组件提供,根据已经包含的存储驱动,其目前支持多种类型的后端存储。

许多存储驱动支持虚拟机实例直接访问底层存储,无须经过层层转化和性能消耗,这无疑对提升整体的I/O性能很有帮助。同时,Cinder块存储服务组件也支持使用文件作为块设备,如NFS、GlusterFS等。在NFS和GlusterFS文件系统种,可以创建一个独立文件作为块设备映射给虚拟机实例使用。这种方法类似于在QEMU中创建虚拟机实例,这些虚拟机实例是一个个文件,保存在/var/lib/nova/instances目录中。

安装和配置(控制节点)

Cinder块存储服务组件要求至少有一个存储节点。

准备

在安装和配置Cinder块存储服务之前,首先要创建数据块、服务证书(service credential)和API endpoint。
(1)创建数据库。
①使用root用户连接数据库

[root@controller openstack]# mysql -uroot -p

②创建Cinder数据库

MariaDB [(none)]> CREATE DATABASE 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';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

(2)加载admin 的环境变量

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

(3)创建Identity服务凭据
①创建Cinder用户

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

②将admin role赋予Cinder用户和service project。

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

③创建cinderv2和cinderv3 service entity

[root@controller openstack]# openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Block Storage          |
| enabled     | True                             |
| id          | 0bdf7164531240248d6bda357cfd4161 |
| name        | cinderv2                         |
| type        | volumev2                         |
+-------------+----------------------------------+
[root@controller openstack]# openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Block Storage          |
| enabled     | True                             |
| id          | 3efda38e9fef41da9744fcf985bb2c1d |
| name        | cinderv3                         |
| type        | volumev3                         |
+-------------+----------------------------------+

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

[root@controller openstack]# openstack endpoint create --region RegionOne volumev2 public http://controller:8776/v2/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | 7bab70d0fbb8459681dcfff273c7e463         |
| interface    | public                                   |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 0bdf7164531240248d6bda357cfd4161         |
| service_name | cinderv2                                 |
| service_type | volumev2                                 |
| url          | http://controller:8776/v2/%(project_id)s |
+--------------+------------------------------------------+
[root@controller openstack]# openstack endpoint create --region RegionOne volumev2 internal http://controller:8776/v2/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | 3f85fc84a3fd4a1daca0777a09d807f3         |
| interface    | internal                                 |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 0bdf7164531240248d6bda357cfd4161         |
| service_name | cinderv2                                 |
| service_type | volumev2                                 |
| url          | http://controller:8776/v2/%(project_id)s |
+--------------+------------------------------------------+
[root@controller openstack]# openstack endpoint create --region RegionOne volumev2 admin http://controller:8776/v2/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | b576c77300bc497d80d09da70bc3dd7a         |
| interface    | admin                                    |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 0bdf7164531240248d6bda357cfd4161         |
| service_name | cinderv2                                 |
| service_type | volumev2                                 |
| url          | http://controller:8776/v2/%(project_id)s |
+--------------+------------------------------------------+
[root@controller openstack]# openstack endpoint create --region RegionOne volumev3 public http://controller:8776/v3/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | 9ca9d872a9614ad298d8a2eeeef288e9         |
| interface    | public                                   |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 3efda38e9fef41da9744fcf985bb2c1d         |
| service_name | cinderv3                                 |
| service_type | volumev3                                 |
| url          | http://controller:8776/v3/%(project_id)s |
+--------------+------------------------------------------+
[root@controller openstack]# openstack endpoint create --region RegionOne volumev3 internal http://controller:8776/v3/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | ca35b10b0dc14e6db4c372a919610207         |
| interface    | internal                                 |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 3efda38e9fef41da9744fcf985bb2c1d         |
| service_name | cinderv3                                 |
| service_type | volumev3                                 |
| url          | http://controller:8776/v3/%(project_id)s |
+--------------+------------------------------------------+
[root@controller openstack]# openstack endpoint create --region RegionOne volumev3 admin http://controller:8776/v3/%\(project_id\)s
+--------------+------------------------------------------+
| Field        | Value                                    |
+--------------+------------------------------------------+
| enabled      | True                                     |
| id           | 1d3f5303aa3f43e991d92cdc935ed89b         |
| interface    | admin                                    |
| region       | RegionOne                                |
| region_id    | RegionOne                                |
| service_id   | 3efda38e9fef41da9744fcf985bb2c1d         |
| service_name | cinderv3                                 |
| service_type | volumev3                                 |
| url          | http://controller:8776/v3/%(project_id)s |
+--------------+------------------------------------------+

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

(1)安装软件包

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

(2)编辑文件/etc/cinder/cinder.conf,完成以下操作
①在[database]部分,配置数据库访问

[database]
# ...
connection = mysql+pymysql://cinder:CINDER_DBPASS@controller/cinder

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

[DEFAULT]
# ...
transport_url = rabbit://openstack:RABBIT_PASS@controller

③在[DEFAULT]和keystone_authtoken],配置Keystone身份认证服务组件访问

[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_PASS

④在[DEFAULT]部分,配置my_ip参数为控制节点的管理/数据网络IP地址

[DEFAULT]
# ...
my_ip = 10.0.0.11

⑤在[oslo_concurrency]部分,配置锁路径

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

⑥打开日志记录功能,方便问题跟踪和解决

[DEFAULT]
...
verbose = true

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

[root@controller openstack]# su -s /bin/sh -c "cinder-manage db sync" cinder

(4)编辑文件/etc/nova/nova.conf,配置Nova计算服务使用Cinder块存储服务。

完成安装

(1)重启Nova计算服务的API服务

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

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

[root@controller openstack]# systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
Created symlink /etc/systemd/system/multi-user.target.wants/openstack-cinder-api.service → /usr/lib/systemd/system/openstack-cinder-api.service.
Created symlink /etc/systemd/system/multi-user.target.wants/openstack-cinder-scheduler.service → /usr/lib/systemd/system/openstack-cinder-scheduler.service.
[root@controller openstack]# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service

(3)验证控制节点的安装,state为up,即为状态正常

[root@controller openstack]# openstack volume service list
+------------------+------------+------+---------+-------+----------------------------+
| Binary           | Host       | Zone | Status  | State | Updated At                 |
+------------------+------------+------+---------+-------+----------------------------+
| cinder-scheduler | controller | nova | enabled | up    | 2021-01-04T07:47:23.000000 |
+------------------+------------+------+---------+-------+----------------------------+

安装和配置(存储节点)

为简单起见,这里将计算节点和存储节点合二为一,放在同一主机上,使用本地硬件设备(/dev/sdb)作为存储,通过iSCSI传输协议,使用LVM驱动将逻辑卷分配给虚拟机实例。

准备

在安装和配置Cinder块存储服务之前,需要首先确定使用的存储设备。
(1)安装软件包
①安装LVM软件包

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

(2)创建lvm物理卷。前提是compute节点有一块未使用磁盘,也可以直接使用单盘。这里使用的是VMware虚拟机,因此,需要添加一块硬盘,这里设置为20G,然后重启计算节点,可以通过fdisk -l命令看到这块新添加的硬盘

[root@computer02 ~]# fdisk -l
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors #这里的硬盘为/dev/sdb
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x46c340dd

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 83886079 81786880  39G 8e Linux LVM


Disk /dev/mapper/cl-root: 35 GiB, 37631295488 bytes, 73498624 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/cl-swap: 4 GiB, 4240441344 bytes, 8282112 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

这里基于/dev/sdb创建物理卷

[root@computer02 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.

(3)创建LVM卷组cinder-volumes

[root@computer02 ~]# vgcreate cinder-volumes /dev/sdb
  Volume group "cinder-volumes" successfully created

(4)Cinder块存储卷一般只能被虚拟机实例访问使用,但是存储节点操作系统可以管理包括磁盘在内的本地硬件设备,操作系统中的LVM卷扫描工具可以扫描/dev目录下的所有设备,包括虚拟机实例访问使用的块存储卷。如果块存储卷被虚拟机实例用作LVM,则当卷扫描工具尝试对块存储进行扫描时,会产生一系列问题。为了避免这些问题,需要对块存储卷进行配置。编辑文件/etc/lvm/lvm.conf,完成以下操作。

devices部分,添加一个过滤器,只接受/dev/sdb设备,拒绝其他所有设备:

devices {
...
filter = [ "a/sdb/", "r/.*/"]

每个过滤器组中的元素都以a开头,即为 accept,或以r开头,即为reject,并且包括一个设备名称的正则表达式规则。过滤器组必须以r/.*/结束,过滤所有保留设备。您可以使用命令vgs -vvvv来测试过滤器。
注意:
如果存储节点在操作系统磁盘上使用了 LVM,还必需添加相关的设备到过滤器中。例如,如果 /dev/sda 设备包含操作系统:

filter = [ "a/sda/", "a/sdb/", "r/.*/"]

类似地,如果计算节点在操作系统磁盘上使用了 LVM,也必需修改这些节点上 /etc/lvm/lvm.conf 文件中的过滤器,将操作系统磁盘包含到过滤器中。例如,如果/dev/sda设备包含操作系统:

filter = [ "a/sda/", "r/.*/"]

因此,这里添加的过滤器为[ “a/sda/”, “a/sdb/”, “r/.*/”]。

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

(1)安装软件包

yum install openstack-cinder targetcli python3-keystone -y

(2)编辑文件/etc/cinder/cinder.conf,完成以下操作
①备份cinder.conf文件

[root@computer02 ~]# cp /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak
[root@computer02 ~]# egrep -v "^$|^#" /etc/cinder/cinder.conf.bak >/etc/cinder/cinder.conf

②在[database]部分,配置数据库连接

[database]
# ...
connection = mysql+pymysql://cinder:CINDER_DBPASS@controller/cinder

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

[DEFAULT]
# ...
transport_url = rabbit://openstack:RABBIT_PASS@controller

④在[DEFAULT]和[keystone_authtoken]部分,配置Keystone身份认证服务组件

[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_PASS

⑤在[DEFAULT]部分,配置my_ip参数为控制节点的管理/数据网络IP地址

[DEFAULT]
# ...
my_ip = MANAGEMENT_INTERFACE_IP_ADDRESS

⑥在[lvm]部分中,使用LVM驱动程序,cinder-volumes卷组,iSCSI协议和相应的iSCSI服务配置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

完成安装

启动块存储卷的相关服务并设置为开启启动

systemctl enable openstack-cinder-volume.service target.service
systemctl restart openstack-cinder-volume.service target.service
systemctl status openstack-cinder-volume.service target.service

验证Cinder服务

在控制节点上执行如下操作:
(1)导入admin管理凭证

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

(2)列出Cinder块存储服务组件,查看是否启动成功

[root@controller openstack]# openstack volume service list
+------------------+----------------+------+---------+-------+----------------------------+
| Binary           | Host           | Zone | Status  | State | Updated At                 |
+------------------+----------------+------+---------+-------+----------------------------+
| cinder-scheduler | controller     | nova | enabled | up    | 2021-01-04T13:46:01.000000 |
| cinder-volume    | computer02@lvm | nova | enabled | down  | 2021-01-05T14:19:57.000000 |
| cinder-volume    | computer01@lvm | nova | enabled | down  | 2021-01-05T14:19:55.000000 |
+------------------+----------------+------+---------+-------+----------------------------+

显然,这里已经在节点compute01、compute02上安装完成cinder存储服务。
至此,已经安装完成Cinder块存储服务,下一步,将安装对象存储(Swift)服务。

参考资料

  1. 《OpenStack从零开始学》
  2. https://blog.csdn.net/caiyqn/article/details/106934436
  3. https://docs.openstack.org/cinder/train/install/index-rdo.html

标签:存储,openstack,service,菜鸟,controller,Train,cinder,OpenStack,id
来源: https://blog.csdn.net/ARPOSPF/article/details/112216032