如何创建OpenStack Cinder卷并将其附加到VM实例

如何在OpenStack中创建Cinder卷并将其附加到实例? OpenStack Cinder服务为虚拟硬盘驱动器提供了持久的块存储管理。通过OpenStack CLI和Horizo​​n Web界面,您可以管理块设备到服务器的创建,连接和分离。本指南介绍了如何在OpenStack环境中运行的服务器上创建,附加和分离Cinder卷。

为了使本指南有意义,您需要配置OpenStack CLI。还有另一篇关于如何在Linux上安装和配置OpenStack Client的文章。有关在Linux系统上安装和配置OpenStack Client的信息,请参考它。

步骤1:检查OpenStack Cinder服务

配置OpenStack客户端后,请确保所有Cinder服务正在运行。煤渣包括:

  • openstack-cinder-volume按需隔离虚拟机存储。提供了许多用于与存储提供程序进行交互的驱动程序。
  • openstack-cinder-api,以响应请求进行处理,并将其放置在消息队列中
  • openstack-cinder-scheduler将任务分配给队列并确定配置卷服务器。

使用以下命令检查这些服务的状态:

for i in volume api scheduler; do
 systemctl status openstack-cinder-$i
done

样本输出所有状态为 跑步

......
● openstack-cinder-volume.service - OpenStack Cinder Volume Server
    Loaded: loaded (/usr/lib/systemd/system/openstack-cinder-volume.service; enabled; vendor preset: disabled)
    Active: active (running) since Sat 2019-09-07 10:13:38 EAT; 14min ago
  Main PID: 6427 (cinder-volume)
     Tasks: 2
    CGroup: /system.slice/openstack-cinder-volume.service
            ├─6427 /usr/bin/python2 /usr/bin/cinder-volume --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf…
            └─6468 /usr/bin/python2 /usr/bin/cinder-volume --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf…

...............
● openstack-cinder-api.service - OpenStack Cinder API Server
    Loaded: loaded (/usr/lib/systemd/system/openstack-cinder-api.service; enabled; vendor preset: disabled)
    Active: active (running) since Sat 2019-09-07 10:13:42 EAT; 14min ago
  Main PID: 6599 (cinder-api)
     Tasks: 9
    CGroup: /system.slice/openstack-cinder-api.service
            ├─6599 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6691 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6692 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6693 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6694 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6695 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6696 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            ├─6697 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…
            └─6699 /usr/bin/python2 /usr/bin/cinder-api --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf --…

......................
● openstack-cinder-scheduler.service - OpenStack Cinder Scheduler Server
    Loaded: loaded (/usr/lib/systemd/system/openstack-cinder-scheduler.service; enabled; vendor preset: disabled)
    Active: active (running) since Sat 2019-09-07 10:13:46 EAT; 14min ago
  Main PID: 6792 (cinder-schedule)
     Tasks: 1
    CGroup: /system.slice/openstack-cinder-scheduler.service
            └─6792 /usr/bin/python2 /usr/bin/cinder-scheduler --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.c…

第2步:创建Cinder卷

您需要配置Cinder存储后端,并确保它可以工作。在设置中使用LVM后端。

$ pvs | grep cinder
  /dev/nvme0n1p1 cinder-volumes lvm2 a--  <476.94g   23.59g

$ vgs | grep cinder
  cinder-volumes   1   4   0 wz--n- <476.94g   23.59g

使用以下命令语法创建Cinder卷:

$ openstack volume create --size  

其中:

  • 卷大小(GB)
  • 要创建的卷的名称。

以下示例创建一个名为 c4geeks-db-backups 大小 30GB

$ openstack volume create --size 30 c4geeks-db-backups

+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attachments         | []                                   |
| availability_zone   | nova                                 |
| bootable            | false                                |
| consistencygroup_id | None                                 |
| created_at          | 2019-09-07T07:37:14.000000           |
| description         | None                                 |
| encrypted           | False                                |
| id                  | 4a4f5cf1-9122-4147-83c1-5aa622f7ba57 |
| migration_status    | None                                 |
| multiattach         | False                                |
| name                | c4geeks-db-backups                   |
| properties          |                                      |
| replication_status  | None                                 |
| size                | 30                                   |
| snapshot_id         | None                                 |
| source_volid        | None                                 |
| status              | creating                             |
| type                | None                                 |
| updated_at          | None                                 |
| user_id             | 336acbb7421f47f8be4891eabf0c9cc8     |
+---------------------+--------------------------------------+

检查卷创建状态。

$ openstack volume list
+--------------------------------------+---------------------+----------------+------+--------------------------------------+
| ID                                   | Name                | Status         | Size | Attached to                          |
+--------------------------------------+---------------------+----------------+------+--------------------------------------+
| 4a4f5cf1-9122-4147-83c1-5aa622f7ba57 | c4geeks-db-backups  | available      |   30 |                                      |
+--------------------------------------+---------------------+----------------+------+--------------------------------------+

可以看到尺寸 30GB 成功创建并可以使用。让我们连接到在OpenStack上运行的服务器。

但首先,获取虚拟机的名称/ ID

$ openstack server list
+--------------------------------------+-------------------+--------+-----------------------------------+----------+-----------+
| ID                                   | Name              | Status | Networks                          | Image    | Flavor    |
+--------------------------------------+-------------------+--------+-----------------------------------+----------+-----------+
| 08df4929-4d9e-4881-9f01-6d89e9862385 | c4geeks-db-server | ACTIVE | private=10.10.1.196               | CentOS-7 | m1.large  |
+--------------------------------------+-------------------+--------+-----------------------------------+----------+-----------+

将创建的卷连接到服务器。

openstack server add volume c4geeks-db-server c4geeks-db-backups 

检查Cinder卷的附件。

$ openstack volume list
+--------------------------------------+---------------------+----------------+------+--------------------------------------------+
| ID                                   | Name                | Status         | Size | Attached to                                |
+--------------------------------------+---------------------+----------------+------+--------------------------------------------+
| 4a4f5cf1-9122-4147-83c1-5aa622f7ba57 | c4geeks-db-backups  | in-use         |   30 | Attached to c4geeks-db-server on /dev/vdc  |
+--------------------------------------+---------------------+----------------+------+--------------------------------------------+

步骤3:在虚拟机上消耗Cinder量

登录到服务器,查看是否看到原始块设备。

$ lsblk /dev/vdc
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdc  253:32   0  30G  0 disk 

创建并安装分区。

sudo parted -s -a optimal -- /dev/vdc mklabel gpt
sudo parted -s -a optimal -- /dev/vdc mkpart primary 0% 100%
sudo parted -s -- /dev/vdc align-check optimal 1
sudo mkfs.xfs /dev/vdc1
sudo mkdir /data
echo "/dev/vdc1 /data xfs defaults 0 0" | sudo tee -a /etc/fstab
sudo mount -a

显示当前的安装图。

$ df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda1      xfs        40G  2.6G   38G   7% /
devtmpfs       devtmpfs  3.8G     0  3.8G   0% /dev
tmpfs          tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs          tmpfs     3.9G   17M  3.9G   1% /run
tmpfs          tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs          tmpfs     783M     0  783M   0% /run/user/1000
/dev/vdc1      xfs        30G   33M   30G   1% /data

开始使用日常操作中添加的块存储。

从服务器分离Cinder虚拟磁盘

要分离并卸下磁盘,请在服务器上将其卸载并运行。

openstack server remove volume c4geeks-db-server c4geeks-db-backups
openstack volume delete c4geeks-db-backups

查看博客上提供的其他OpenStack教程。

学习OpenStack Cloud Platform 2019的完美书

如何调整OpenStack实例/虚拟机的大小

使用Packstack在CentOS 7上进行OpenStack部署

如何在Linux上安装和配置OpenStack Client

使用DevStack在Ubuntu 18.04上进行OpenStack部署

如何将Glance云映像添加到OpenStack

使用CLI将SSH密钥对添加到OpenStack

如何使用CLI向OpenStack添加口味

Sidebar