Article directory
- OpenStack (T version) - block storage (Cinder) service introduction and installation
- Install and configure (controller)
- Installation and configuration (compute)
- verify
- Basic use of Cinder service
OpenStack (T version) - block storage (Cinder) service introduction and installation
OpenStack Block Storage (Cinder) is a component used to provide persistent storage, which allows users to create and manage block-level storage volumes required by virtual machine instances.
Imagine you have a computer hard drive where you store files and data. OpenStack block storage is like providing a hard disk for virtual machines to store data on.
Using block storage, you create a storage volume that a virtual machine requires and then attach it to the virtual machine instance. This storage volume is like a blank hard disk on which the virtual machine can store files, operating system, and other data. The benefit of block storage is that it is durable, meaning the data in the storage volume is not lost when the virtual machine is shut down. When the virtual machine restarts, it can reconnect to the previously attached storage volume and continue to access the data within it. In addition, OpenStack block storage also supports some advanced functions, such as creating snapshots to back up storage volume data or creating volume replicas to provide redundancy and fault tolerance.
OpenStack block storage is a component that provides persistent storage for virtual machines, similar to providing a hard disk for virtual machines. It allows users to create, manage and attach storage volumes for virtual machines to store data and operating systems.
Install and configure (controller)
Prepare
Before installing and configuring the Cinder block storage service components, first create the database, service certificate and APIendpoint.
(1)Create database
① Connect to the database in the operating system terminal
[root@controller ~]# mysql -uroot -p000000
②Create cinder
database
MariaDB [(none)]> CREATE DATABASE cinder;
③Cinder database access permission settings
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY '000000';
④Exit the database
(2) Load the environment variables of admin user
[root@controller ~]# source admin-openrc.sh
(3)Create Identity service credentials
①Create cinder user
[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 grants Cinder users and service projects
[root@controller ~]# openstack role add --project service --user cinder admin
③Create Cinder and 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) Create the API endpoint of the Cinder block storage service component
[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 |
+--------------+------------------------------------------+
Install and configure Cinder block storage service components
(1)Install software package
[root@controller ~]# yum install -y openstack-cinder
(2) Edit the /etc/cinder/cinder.conf file and complete the following operations
①In [database]
section, configure database access
[root@controller ~]# vim /etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:000000@controller/cinder
②In [DEFAULT]
the section, configure RabbitMQ
message queue access
[DEFAULT]
transport_url = rabbit://openstack:000000@controller
③In the [DEFAULT]
and [keystone_authtoken]
section, configure identity service access
[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
⑤ In [DEFAULT]
the section, configure the option my_ip
to use the controller node's management interface IP address
[DEFAULT]
my_ip = 192.168.200.10
⑥In [oslo_concurrency]
section, configure the lock path
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
(3) Synchronize the Cinder block storage service information to the Cinder database
[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)Configure nova file
[root@controller ~]# vim /etc/nova/nova.conf
[cinder]
os_region_name = RegionOne
finish installation
①Restart the nova service
[root@controller ~]# systemctl restart openstack-nova-api.service
②Start the Cinder block storage service component and set it to start automatically
[root@controller ~]# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service && systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
Installation and configuration (compute)
Prepare
Before installing the Cinder block storage service component, you need to first determine the block storage device to be used.
[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)Install software package
[root@compute ~]# yum install -y lvm2 device-mapper-persistent-data
(2) Start the LVM metadata service and set it to start automatically at boot
[root@compute ~]# systemctl start lvm2-lvmetad.service && systemctl enable lvm2-lvmetad.service
(3) Create LVM physical volume /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)Configure LVM file
[root@compute ~]# vim /etc/lvm/lvm.conf
devices {
filter = [ "a/sdb/", "r/.*/"]
# 根据这个配置,只有 "/dev/sdb" 会被作为可用设备,并被 LVM 管理器使用
# 其他设备将被排除在外
Install and configure Cinder block storage service components
(1)Install software package
[root@compute ~]# yum install -y openstack-cinder targetcli python-keystone
(2)Configuration file
Edit /etc/cinder/cinder.conf
the file and complete the following actions
①In [database]
section, configure database access
[root@compute ~]# vim /etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:000000@controller/cinder
②In [DEFAULT]
the section, configure RabbitMQ
message queue access
[DEFAULT]
transport_url = rabbit://openstack:000000@controller
③In the [DEFAULT]
and [keystone_authtoken]
section, configure identity service access
[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
④In [DEFAULT]
section, configure my_ip
options
my_ip = 192.168.200.20
⑤Add in [lvm]
section
[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
target_protocol = iscsi
target_helper = lioadm
⑥In [DEFAULT]
section, enable LVM backend
[DEFAULT]
enabled_backends = lvm
⑦In [DEFAULT]
the section, configure the location of the image service API
[DEFAULT]
glance_api_servers = http://controller:9292
⑧In [oslo_concurrency]
the section, configure the lock path
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
finish installation
Start the block storage volume service and set it to start automatically at boot
[root@compute ~]# systemctl start openstack-cinder-volume.service target.service && systemctl enable openstack-cinder-volume.service target.service
# 自行查看log文件 如果有error就是有错误
verify
List the Cinder block storage service components to see if the process starts successfully
[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 |
+------------------+-------------+------+---------+-------+----------------------------+
Basic use of Cinder service
Create block storage
Create a block storage through the command, the size is 2G, and the name is 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 |
+---------------------+--------------------------------------+
View block storage
[root@controller ~]# openstack volume list
+--------------------------------------+--------+----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+----------+------+-------------+
| 51b8b246-14b0-4b1e-866f-d4fb17c1f4c6 | volume | reserved | 2 | |
+--------------------------------------+--------+----------+------+-------------+
Mount cloud disk
必须事先创建好云主机才能挂载云硬盘
Use the command to add the volume block storage just created to the cloud host csq
[root@controller ~]# openstack server add volume csq volume
Use commands to view block storage list information
[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 |
+--------------------------------------+--------+--------+------+------------------------------+
还有相关扩展卷的操作可以参考这篇博客:
Basic use of glance, nova, cinder and swift services