“OpenStack:Cinder组件的运维”的版本间的差异
(未显示同一用户的12个中间版本) | |||
第1行: | 第1行: | ||
+ | ==基础准备== | ||
+ | ===检查现有磁盘=== | ||
+ | 控制节点: | ||
+ | |||
+ | [root@compute ~]# fdisk -l | ||
+ | |||
+ | <nowiki>Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos | ||
+ | Disk identifier: 0x00070c58 | ||
+ | |||
+ | Device Boot Start End Blocks Id System | ||
+ | /dev/sda1 2048 195348479 97673216 8e Linux LVM | ||
+ | |||
+ | Disk /dev/mapper/centos-root: 60.0 GB, 59999518720 bytes, 117186560 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 | ||
+ | ... | ||
+ | </nowiki> | ||
+ | |||
+ | ===添加新硬盘=== | ||
+ | 给控制节点: 新增加一块硬盘 | ||
+ | |||
+ | [[文件:openstack8-41.png|700px]] | ||
+ | |||
+ | 关机重启,输入命令: | ||
+ | |||
+ | [root@compute ~]# fdisk -l | ||
+ | |||
+ | <nowiki>Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos | ||
+ | Disk identifier: 0x00070c58 | ||
+ | |||
+ | Device Boot Start End Blocks Id System | ||
+ | /dev/sda1 2048 195348479 97673216 8e Linux LVM | ||
+ | |||
+ | Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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</nowiki> | ||
+ | |||
+ | 多的这一个/dev/sdb就是新添加的硬盘。 | ||
+ | |||
+ | ===硬盘分区=== | ||
+ | 下面这块硬盘进行分区 ,记录分区的名字 | ||
+ | |||
+ | |||
+ | [root@compute ~]# fdisk /dev/sdb | ||
+ | |||
+ | <nowiki>Welcome to fdisk (util-linux 2.23.2). | ||
+ | |||
+ | Changes will remain in memory only, until you decide to write them. | ||
+ | Be careful before using the write command. | ||
+ | |||
+ | Device does not contain a recognized partition table | ||
+ | Building a new DOS disklabel with disk identifier 0x157e7f05. | ||
+ | |||
+ | Command (m for help): n | ||
+ | Partition type: | ||
+ | p primary (0 primary, 0 extended, 4 free) | ||
+ | e extended | ||
+ | Select (default p): p | ||
+ | Partition number (1-4, default 1): 1 | ||
+ | First sector (2048-41943039, default 2048): 2048 | ||
+ | Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G | ||
+ | Partition 1 of type Linux and of size 10 GiB is set | ||
+ | |||
+ | Command (m for help): W | ||
+ | The partition table has been altered! | ||
+ | |||
+ | Calling ioctl() to re-read partition table. | ||
+ | Syncing disks.</nowiki> | ||
+ | |||
+ | 查看新的硬盘分区:/dev/sdb1 | ||
+ | |||
+ | [root@compute ~]# lsblk | ||
+ | |||
+ | <nowiki>NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT | ||
+ | sda 8:0 0 100G 0 disk | ||
+ | └─sda1 8:1 0 93.2G 0 part | ||
+ | ├─centos-root 253:0 0 55.9G 0 lvm / | ||
+ | ├─centos-swap 253:1 0 18.6G 0 lvm [SWAP] | ||
+ | └─centos-home 253:2 0 18.6G 0 lvm /home | ||
+ | sdb 8:16 0 20G 0 disk | ||
+ | └─sdb1 8:17 0 10G 0 part | ||
+ | sr0 11:0 1 1024M 0 rom | ||
+ | sr1 11:1 1 1024M 0 rom</nowiki> | ||
+ | |||
+ | |||
+ | 参考文档:[[Linux 磁盘管理]] | ||
+ | |||
==Cinder的安装== | ==Cinder的安装== | ||
===修改配置文件=== | ===修改配置文件=== | ||
+ | 控制节点&计算节点: | ||
+ | |||
vi /etc/xiandian/openrc.sh | vi /etc/xiandian/openrc.sh | ||
第11行: | 第110行: | ||
##Cinder Block Disk. example:md126p3 | ##Cinder Block Disk. example:md126p3 | ||
− | + | BLOCK_DISK=sdb1(这里填你刚才硬盘分区的名字) | |
</nowiki> | </nowiki> | ||
第21行: | 第120行: | ||
iaas-install-cinder-controller.sh | iaas-install-cinder-controller.sh | ||
− | + | iaas-install-cinder-compute.sh | |
− | + | <nowiki>Created symlink from /etc/systemd/system/sysinit.target.wants/lvm2-lvmetad.service to /usr/lib/systemd/system/lvm2-lvmetad.service. | |
+ | Physical volume "/dev/sdb1" successfully created | ||
+ | Volume group "cinder-volumes" successfully created | ||
+ | Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-cinder-volume.service to /usr/lib/systemd/system/openstack-cinder-volume.service. | ||
+ | Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service. | ||
+ | </nowiki> | ||
== Cinder的CLI命令行使用 == | == Cinder的CLI命令行使用 == | ||
− | + | ||
Cinder作为OpenStack平台的块存储组件,提供了一系列存储操作的CLI命令行用于管理存储卷,可以灵活地对存储卷进行创建、扩容、删除和加密等操作。 | Cinder作为OpenStack平台的块存储组件,提供了一系列存储操作的CLI命令行用于管理存储卷,可以灵活地对存储卷进行创建、扩容、删除和加密等操作。 | ||
+ | |||
==创建cinder存储卷== | ==创建cinder存储卷== | ||
用户可以通过CLI命令创建一个简单的Cinder存储卷,命令如下。 | 用户可以通过CLI命令创建一个简单的Cinder存储卷,命令如下。 | ||
第56行: | 第161行: | ||
[root@controller ~]# cinder list | [root@controller ~]# cinder list | ||
− | <nowiki>+--------------------------------------+-----------+ | + | <nowiki> |
− | | ID | Status | | + | +--------------------------------------+-----------+-------+------+-------------+----------+-------------+ |
− | +--------------------------------------+-----------+ | + | | ID | Status | Name | Size | Volume Type | Bootable | Attached to | |
− | | | + | +--------------------------------------+-----------+-------+------+-------------+----------+-------------+ |
− | + | | 39aa5d70-6185-40b9-bac0-847d6f9fc016 | available | test1 | 1 | - | false | | | |
− | + | +--------------------------------------+-----------+-------+------+-------------+----------+-------------+ | |
− | + | </nowiki> | |
− | |||
− | +--------------------------------------+-----------+ | ||
− | |||
==删除指定的Cinder卷== | ==删除指定的Cinder卷== | ||
第87行: | 第189行: | ||
===创建卷类型=== | ===创建卷类型=== | ||
− | [root@controller ~]# cinder type-create | + | [root@controller ~]# cinder type-create type1 |
− | <nowiki>+--------------------------------------+-------+ | + | <nowiki>+--------------------------------------+-------+-------------+-----------+ |
− | | ID | Name | | + | | ID | Name | Description | Is_Public | |
− | +--------------------------------------+-------+ | + | +--------------------------------------+-------+-------------+-----------+ |
− | | | + | | 0c6ab25c-4c8f-4002-bdc6-5eaf8cfc7343 | type1 | - | True | |
− | +--------------------------------------+-------+</nowiki> | + | +--------------------------------------+-------+-------------+-----------+ |
+ | </nowiki> | ||
[root@controller ~]# cinder type-list | [root@controller ~]# cinder type-list | ||
− | <nowiki>+--------------------------------------+-------+ | + | <nowiki>+--------------------------------------+-------+-------------+-----------+ |
− | | ID | Name | | + | | ID | Name | Description | Is_Public | |
− | +--------------------------------------+-------+ | + | +--------------------------------------+-------+-------------+-----------+ |
− | | | + | | 0c6ab25c-4c8f-4002-bdc6-5eaf8cfc7343 | type1 | - | True | |
− | +--------------------------------------+-------+</nowiki> | + | +--------------------------------------+-------+-------------+-----------+ |
+ | </nowiki> | ||
===创建并查询extra_spec表示的卷类型=== | ===创建并查询extra_spec表示的卷类型=== | ||
第179行: | 第283行: | ||
| volume_type | test1 | | | volume_type | test1 | | ||
+--------------------------------+--------------------------------------+ | +--------------------------------+--------------------------------------+ | ||
− | [root@controller ~]#</nowiki> | + | [root@controller ~]#</nowiki> |
− | |||
− | |||
== 对Cinder后端逻辑卷进行扩容 == | == 对Cinder后端逻辑卷进行扩容 == | ||
第249行: | 第351行: | ||
===对LVM卷进行扩容=== | ===对LVM卷进行扩容=== | ||
====首先我们通过“pvcreate”命令创建pv==== | ====首先我们通过“pvcreate”命令创建pv==== | ||
− | + | 首先,在计算节点上新创建一个分区/dev/sdb2 | |
+ | |||
+ | [root@controller ~]# fdisk /dev/sdb | ||
− | + | <nowiki>Welcome to fdisk (util-linux 2.23.2). | |
+ | |||
+ | Changes will remain in memory only, until you decide to write them. | ||
+ | Be careful before using the write command. | ||
− | |||
− | |||
− | |||
Command (m for help): n | Command (m for help): n | ||
− | First | + | Partition type: |
− | Last | + | p primary (1 primary, 0 extended, 3 free) |
− | Unsupported suffix: '. | + | e extended |
+ | Select (default p): p | ||
+ | Partition number (2-4, default 2): 2 | ||
+ | First sector (20973568-41943039, default 20973568): 20973568 | ||
+ | Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +2G | ||
+ | Unsupported suffix: 'GG'. | ||
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) | Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) | ||
2^N: K (KibiByte), M (MebiByte), G (GibiByte) | 2^N: K (KibiByte), M (MebiByte), G (GibiByte) | ||
− | Last | + | Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +2G |
− | + | Partition 2 of type Linux and of size 2 GiB is set | |
− | |||
Command (m for help): W | Command (m for help): W | ||
第275行: | 第383行: | ||
The kernel still uses the old table. The new table will be used at | The kernel still uses the old table. The new table will be used at | ||
the next reboot or after you run partprobe(8) or kpartx(8) | the next reboot or after you run partprobe(8) or kpartx(8) | ||
− | Syncing disks.</nowiki> | + | Syncing disks. |
+ | </nowiki> | ||
[root@controller ~]# reboot | [root@controller ~]# reboot | ||
第286行: | 第395行: | ||
[root@controller ~]# lsblk | [root@controller ~]# lsblk | ||
− | <nowiki>NAME | + | <nowiki>NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT |
− | + | sda 8:0 0 100G 0 disk | |
− | + | └─sda1 8:1 0 93.2G 0 part | |
− | + | ├─centos-root 253:0 0 55.9G 0 lvm / | |
− | + | ├─centos-swap 253:1 0 18.6G 0 lvm [SWAP] | |
− | + | └─centos-home 253:2 0 18.6G 0 lvm /home | |
− | + | sdb 8:16 0 20G 0 disk | |
− | + | ├─sdb1 8:17 0 10G 0 part | |
− | + | │ ├─cinder--volumes-volume--39aa5d70--6185--40b9--bac0--847d6f9fc016 | |
− | + | 253:3 0 1G 0 lvm | |
− | + | │ └─cinder--volumes-volume--8fbd9360--ff27--47c0--afd1--db129f323206 | |
+ | 253:4 0 1G 0 lvm | ||
+ | └─sdb2 8:18 0 2G 0 part | ||
+ | sr0 11:0 1 1024M 0 rom | ||
+ | sr1 11:1 1 1024M 0 rom | ||
+ | </nowiki> | ||
− | [root@controller ~]# pvcreate /dev/ | + | [root@controller ~]# pvcreate /dev/sdb2 (刚才新创建的分区) |
− | <nowiki> | + | <nowiki> Physical volume "/dev/sdb2" successfully created |
− | + | </nowiki> | |
[root@controller ~]# pvdisplay | [root@controller ~]# pvdisplay | ||
<nowiki>--- Physical volume --- | <nowiki>--- Physical volume --- | ||
− | PV Name /dev/ | + | PV Name /dev/sdb1 |
VG Name cinder-volumes | VG Name cinder-volumes | ||
− | PV Size | + | PV Size 10.00 GiB / not usable 4.00 MiB |
− | Allocatable yes | + | Allocatable yes |
PE Size 4.00 MiB | PE Size 4.00 MiB | ||
− | Total PE | + | Total PE 2559 |
− | Free PE | + | Free PE 2047 |
− | Allocated PE | + | Allocated PE 512 |
− | PV UUID | + | PV UUID vgk3ae-A5ie-DkzP-5fHB-KEYG-pBfk-7Ro3Vy |
− | + | ||
− | "/dev/ | + | --- Physical volume --- |
+ | PV Name /dev/sda1 | ||
+ | VG Name centos | ||
+ | PV Size 93.15 GiB / not usable 4.00 MiB | ||
+ | Allocatable yes | ||
+ | PE Size 4.00 MiB | ||
+ | Total PE 23845 | ||
+ | Free PE 2 | ||
+ | Allocated PE 23843 | ||
+ | PV UUID JwpPRp-jhN9-1CgH-2eOD-QGRE-K0lH-oDxMC4 | ||
+ | |||
+ | "/dev/sdb2" is a new physical volume of "2.00 GiB" | ||
--- NEW Physical volume --- | --- NEW Physical volume --- | ||
− | PV Name /dev/ | + | PV Name /dev/sdb2 |
− | VG Name | + | VG Name |
− | PV Size | + | PV Size 2.00 GiB |
Allocatable NO | Allocatable NO | ||
− | PE Size 0 | + | PE Size 0 |
Total PE 0 | Total PE 0 | ||
Free PE 0 | Free PE 0 | ||
Allocated PE 0 | Allocated PE 0 | ||
− | PV UUID | + | PV UUID yfUsww-CxqM-DXJn-jQEE-H2Ob-lm2u-1A71Yx |
+ | </nowiki> | ||
− | 这样就成功的创建了一个名为/dev/ | + | 这样就成功的创建了一个名为/dev/sdb2的物理分区 |
==== 接着,我们通过“vgextend”命令扩展已有VG的容量==== | ==== 接着,我们通过“vgextend”命令扩展已有VG的容量==== | ||
第359行: | 第485行: | ||
然后进行卷组宽展: | 然后进行卷组宽展: | ||
− | [root@controller ~]# vgextend cinder-volumes /dev/ | + | [root@controller ~]# vgextend cinder-volumes /dev/sdb2 |
− | |||
Volume group "cinder-volumes" successfully extended | Volume group "cinder-volumes" successfully extended | ||
第368行: | 第493行: | ||
<nowiki>--- Volume group --- | <nowiki>--- Volume group --- | ||
VG Name cinder-volumes | VG Name cinder-volumes | ||
− | System ID | + | System ID |
Format lvm2 | Format lvm2 | ||
Metadata Areas 2 | Metadata Areas 2 | ||
− | Metadata Sequence No | + | Metadata Sequence No 4 |
VG Access read/write | VG Access read/write | ||
VG Status resizable | VG Status resizable | ||
MAX LV 0 | MAX LV 0 | ||
− | Cur LV | + | Cur LV 2 |
Open LV 0 | Open LV 0 | ||
Max PV 0 | Max PV 0 | ||
Cur PV 2 | Cur PV 2 | ||
Act PV 2 | Act PV 2 | ||
− | VG Size | + | VG Size 11.99 GiB |
PE Size 4.00 MiB | PE Size 4.00 MiB | ||
− | Total PE | + | Total PE 3070 |
− | Alloc PE / Size | + | Alloc PE / Size 512 / 2.00 GiB |
− | Free PE / Size | + | Free PE / Size 2558 / 9.99 GiB |
− | VG UUID | + | VG UUID M9a5hN-TIAR-Xm3C-mbzp-2QgQ-dUjB-AfJP1e |
+ | </nowiki> | ||
− | ====重启cinder- | + | ====重启cinder-volume服务后再次创建云硬盘==== |
− | [root@controller ~]# cinder create --display-name cinder-volume-demo | + | [root@controller ~]# cinder create --display-name cinder-volume-demo 2 |
<nowiki>+---------------------+--------------------------------------+ | <nowiki>+---------------------+--------------------------------------+ |
2019年5月13日 (一) 04:16的最新版本
目录
基础准备
检查现有磁盘
控制节点:
[root@compute ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos Disk identifier: 0x00070c58 Device Boot Start End Blocks Id System /dev/sda1 2048 195348479 97673216 8e Linux LVM Disk /dev/mapper/centos-root: 60.0 GB, 59999518720 bytes, 117186560 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 ...
添加新硬盘
给控制节点: 新增加一块硬盘
关机重启,输入命令:
[root@compute ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos Disk identifier: 0x00070c58 Device Boot Start End Blocks Id System /dev/sda1 2048 195348479 97673216 8e Linux LVM Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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@compute ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x157e7f05. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): W The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
查看新的硬盘分区:/dev/sdb1
[root@compute ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 100G 0 disk └─sda1 8:1 0 93.2G 0 part ├─centos-root 253:0 0 55.9G 0 lvm / ├─centos-swap 253:1 0 18.6G 0 lvm [SWAP] └─centos-home 253:2 0 18.6G 0 lvm /home sdb 8:16 0 20G 0 disk └─sdb1 8:17 0 10G 0 part sr0 11:0 1 1024M 0 rom sr1 11:1 1 1024M 0 rom
参考文档:Linux 磁盘管理
Cinder的安装
修改配置文件
控制节点&计算节点:
vi /etc/xiandian/openrc.sh
##--------------------Cinder Config--------------------## ##Password for Mysql cinder user. exmaple:000000 CINDER_DBPASS=000000 ##Password for Keystore cinder user. exmaple:000000 CINDER_PASS=000000 ##Cinder Block Disk. example:md126p3 BLOCK_DISK=sdb1(这里填你刚才硬盘分区的名字)
执行脚本文件
控制节点:
cd /usr/local/bin
iaas-install-cinder-controller.sh
iaas-install-cinder-compute.sh
Created symlink from /etc/systemd/system/sysinit.target.wants/lvm2-lvmetad.service to /usr/lib/systemd/system/lvm2-lvmetad.service. Physical volume "/dev/sdb1" successfully created Volume group "cinder-volumes" successfully created Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-cinder-volume.service to /usr/lib/systemd/system/openstack-cinder-volume.service. Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
Cinder的CLI命令行使用
Cinder作为OpenStack平台的块存储组件,提供了一系列存储操作的CLI命令行用于管理存储卷,可以灵活地对存储卷进行创建、扩容、删除和加密等操作。
创建cinder存储卷
用户可以通过CLI命令创建一个简单的Cinder存储卷,命令如下。
[root@controller ~]# cinder create --display-name test1 1
+---------------------+--------------------------------------+ | Property | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | created_at | 2018-12-14T10:14:36.111709 | | display_description | None | | display_name | test1 | | encrypted | False | | id | 9a523cfc-ab43-49f6-84b3-f8ad5867c2e0 | | metadata | {} | | size | 1 | | snapshot_id | None | | source_volid | None | | status | creating | | volume_type | None | +---------------------+--------------------------------------+
[root@controller ~]# cinder list
+--------------------------------------+-----------+-------+------+-------------+----------+-------------+ | ID | Status | Name | Size | Volume Type | Bootable | Attached to | +--------------------------------------+-----------+-------+------+-------------+----------+-------------+ | 39aa5d70-6185-40b9-bac0-847d6f9fc016 | available | test1 | 1 | - | false | | +--------------------------------------+-----------+-------+------+-------------+----------+-------------+
删除指定的Cinder卷
删除Cinder卷的方法比较简单,用户可以通过命令cinder delete <volume> [<volume> ...] 来删除一个或多个Cinder卷。
比如说:删除我们上面新创建的type_test_demo这个cinder卷
[root@controller ~]# cinder delete test1
指定Cinder卷类型
查询type标识的卷类型
可以通过“cinder type-list”命令来查看现有的卷类型
[root@controller ~]# cinder type-list
+----+------+ | ID | Name | +----+------+ +----+------+
创建卷类型
[root@controller ~]# cinder type-create type1
+--------------------------------------+-------+-------------+-----------+ | ID | Name | Description | Is_Public | +--------------------------------------+-------+-------------+-----------+ | 0c6ab25c-4c8f-4002-bdc6-5eaf8cfc7343 | type1 | - | True | +--------------------------------------+-------+-------------+-----------+
[root@controller ~]# cinder type-list
+--------------------------------------+-------+-------------+-----------+ | ID | Name | Description | Is_Public | +--------------------------------------+-------+-------------+-----------+ | 0c6ab25c-4c8f-4002-bdc6-5eaf8cfc7343 | type1 | - | True | +--------------------------------------+-------+-------------+-----------+
创建并查询extra_spec表示的卷类型
除了可以通过cinder创建type类型的卷标识外,OpenStack还允许通过cinder创建extra_spec类型的卷类型,两个功能基本类似,extra_spec利用一组键值对来对cinder卷进行标识。
可以通过命令cinder type-key lvm set volume_backend_name=LVM_iSCSI来创建键为volume_backend_name,值为LVM_iSCSI的extra_spec类型标识。
通过cinder extra-specs-list来查看已创建的extra_spec标识。
[root@controller ~]# cinder extra-specs-list
+--------------------------------------+-------+-------------+ | ID | Name | extra_specs | +--------------------------------------+-------+-------------+ | 6ddb6645-a948-40cc-b614-0457f802f66d | test1 | {} | +--------------------------------------+-------+-------------+
会发现标记红色椭圆的地方是空的,然后我们运行
[root@controller ~]# cinder type-key test1 set volume_backend_name=1
[root@controller ~]# cinder extra-specs-list
+--------------------------------------+-------+--------------------------------+ | ID | Name | extra_specs | +--------------------------------------+-------+--------------------------------+ | 6ddb6645-a948-40cc-b614-0457f802f66d | test1 | {u'volume_backend_name': u'1'} | +--------------------------------------+-------+--------------------------------+
创建云硬盘
[root@controller ~]# cinder create --display-name type_test_demo --volume_type test1 1
+---------------------+--------------------------------------+ | Property | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | created_at | 2018-12-14T10:13:36.937899 | | display_description | None | | display_name | type_test_demo | | encrypted | False | | id | 0a30c060-425d-4c74-8623-1ea42f01f3aa | | metadata | {} | | size | 1 | | snapshot_id | None | | source_volid | None | | status | creating | | volume_type | test1 | +---------------------+--------------------------------------+
创建成功后可以通过命令查看结果,可以看到该卷的volume_type字段已修改为“test1”。查询命令如下
[root@controller ~]# cinder show type_test_demo
+--------------------------------+--------------------------------------+ | Property | Value | +--------------------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | created_at | 2018-12-14T10:13:36.000000 | | display_description | None | | display_name | type_test_demo | | encrypted | False | | id | 0a30c060-425d-4c74-8623-1ea42f01f3aa | | metadata | {} | | os-vol-host-attr:host | None | | os-vol-mig-status-attr:migstat | None | | os-vol-mig-status-attr:name_id | None | | os-vol-tenant-attr:tenant_id | 00d9dcd033d542b68614c88d19fa0544 | | size | 1 | | snapshot_id | None | | source_volid | None | | status | error | | volume_type | test1 | +--------------------------------+--------------------------------------+ [root@controller ~]#
对Cinder后端逻辑卷进行扩容
创建一个1G的云硬盘extend-demo
[root@controller ~]# source admin-openrc.sh
[root@controller ~]# cinder create --display-name cinder-volume-demo 1
+---------------------+--------------------------------------+ | Property | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | created_at | 2018-12-14T09:42:46.382604 | | display_description | None | | display_name | cinder-volume-demo | | encrypted | False | | id | 4bf67c03-2c12-43f8-842b-f971e5c0d97b | | metadata | {} | | size | 1 | | snapshot_id | None | | source_volid | None | | status | creating | | volume_type | None | +---------------------+--------------------------------------+
通过cinder-list命令查看云硬盘信息
[root@controller ~]# cinder list
+--------------------------------------+-----------+--------------------+------+-------------+----------+-------------+ | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to | +--------------------------------------+-----------+--------------------+------+-------------+----------+-------------+ | 4bf67c03-2c12-43f8-842b-f971e5c0d97b | available | cinder-volume-demo | 1 | None | false | | +--------------------------------------+-----------+--------------------+------+-------------+----------+-------------+
用户可以在存储节点运行vgdisplay命令查看逻辑卷空间。
[root@controller ~]# vgdisplay
--- Volume group --- VG Name cinder-volumes System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 9.76 GiB PE Size 4.00 MiB Total PE 2499 Alloc PE / Size 256 / 1.00 GiB Free PE / Size 2243 / 8.76 GiB VG UUID phbML6-I5rB-rn7k-uGaa-ek46-c0u2-VCAgo2
对LVM卷进行扩容
首先我们通过“pvcreate”命令创建pv
首先,在计算节点上新创建一个分区/dev/sdb2
[root@controller ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): 2 First sector (20973568-41943039, default 20973568): 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +2G Unsupported suffix: 'GG'. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +2G Partition 2 of type Linux and of size 2 GiB is set Command (m for help): W The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
[root@controller ~]# reboot
Broadcast message from root@controller (/dev/pts/0) at 4:54 ... The system is going down for reboot NOW!
[root@controller ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 100G 0 disk └─sda1 8:1 0 93.2G 0 part ├─centos-root 253:0 0 55.9G 0 lvm / ├─centos-swap 253:1 0 18.6G 0 lvm [SWAP] └─centos-home 253:2 0 18.6G 0 lvm /home sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 10G 0 part │ ├─cinder--volumes-volume--39aa5d70--6185--40b9--bac0--847d6f9fc016 253:3 0 1G 0 lvm │ └─cinder--volumes-volume--8fbd9360--ff27--47c0--afd1--db129f323206 253:4 0 1G 0 lvm └─sdb2 8:18 0 2G 0 part sr0 11:0 1 1024M 0 rom sr1 11:1 1 1024M 0 rom
[root@controller ~]# pvcreate /dev/sdb2 (刚才新创建的分区)
Physical volume "/dev/sdb2" successfully created
[root@controller ~]# pvdisplay
--- Physical volume --- PV Name /dev/sdb1 VG Name cinder-volumes PV Size 10.00 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 2559 Free PE 2047 Allocated PE 512 PV UUID vgk3ae-A5ie-DkzP-5fHB-KEYG-pBfk-7Ro3Vy --- Physical volume --- PV Name /dev/sda1 VG Name centos PV Size 93.15 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 23845 Free PE 2 Allocated PE 23843 PV UUID JwpPRp-jhN9-1CgH-2eOD-QGRE-K0lH-oDxMC4 "/dev/sdb2" is a new physical volume of "2.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 2.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID yfUsww-CxqM-DXJn-jQEE-H2Ob-lm2u-1A71Yx
这样就成功的创建了一个名为/dev/sdb2的物理分区
接着,我们通过“vgextend”命令扩展已有VG的容量
首先我们先看一下cinder-volumes卷组的大小
[root@controller ~]# vgdisplay
--- Volume group --- VG Name cinder-volumes System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 9.76 GiB PE Size 4.00 MiB Total PE 2499 Alloc PE / Size 256 / 1.00 GiB Free PE / Size 2243 / 8.76 GiB VG UUID phbML6-I5rB-rn7k-uGaa-ek46-c0u2-VCAgo2
然后进行卷组宽展:
[root@controller ~]# vgextend cinder-volumes /dev/sdb2
Volume group "cinder-volumes" successfully extended
查看扩展后的VG容量
[root@controller ~]# vgdisplay
--- Volume group --- VG Name cinder-volumes System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 11.99 GiB PE Size 4.00 MiB Total PE 3070 Alloc PE / Size 512 / 2.00 GiB Free PE / Size 2558 / 9.99 GiB VG UUID M9a5hN-TIAR-Xm3C-mbzp-2QgQ-dUjB-AfJP1e
重启cinder-volume服务后再次创建云硬盘
[root@controller ~]# cinder create --display-name cinder-volume-demo 2
+---------------------+--------------------------------------+ | Property | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | created_at | 2018-12-14T10:09:49.916306 | | display_description | None | | display_name | cinder-volume-demo | | encrypted | False | | id | 5d4127c8-0c9d-4703-ada8-d9e716d87565 | | metadata | {} | | size | 10 | | snapshot_id | None | | source_volid | None | | status | creating | | volume_type | None | +---------------------+--------------------------------------+
[root@controller ~]# cinder list
+--------------------------------------+-----------+--------------------+------+-------------+----------+-------------+ | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to | +--------------------------------------+-----------+--------------------+------+-------------+----------+-------------+ | 3ea86c92-4f15-4aa0-90fa-99b37b107b3a | error | cinder-volume-demo | 100 | None | false | | | 4bf67c03-2c12-43f8-842b-f971e5c0d97b | available | cinder-volume-demo | 1 | None | false | | | 5d4127c8-0c9d-4703-ada8-d9e716d87565 | available | cinder-volume-demo | 10 | None | false | | +--------------------------------------+-----------+--------------------+------+-------------+----------+-------------+
Cinder快照操作
创建Cinder卷快照
用户可以通过如下命令来创建一个简单的Cinder 卷快照。
- cinder snapshot-create --display-name snapshot_test1 test1
+---------------------+--------------------------------------+ | Property | Value | +---------------------+--------------------------------------+ | created_at | 2018-12-14T10:15:52.333696 | | display_description | None | | display_name | snapshot_test1 | | id | 9fd3fae4-5804-42bb-a807-218083dd0c76 | | metadata | {} | | size | 1 | | status | creating | | volume_id | 9a523cfc-ab43-49f6-84b3-f8ad5867c2e0 | +---------------------+--------------------------------------+
查看Cinder卷、快照信息
我们可以通过cinder-list命令查看镜像列表
- cinder list查看cinder卷的列表
- cinder snapshot-list查看snapshot的列表
还可以通过“cinder show <volume>”命令来查看指定云硬盘的详细信息,命令如下。
- cinder show d679d729-85b7-49fa-ab89-f7b87153b62d
将已创建的Cinder卷挂载到虚拟机实例
首先查看有没有云主机实例:
nova list
+----+------+--------+------------+-------------+----------+ | ID | Name | Status | Task State | Power State | Networks | +----+------+--------+------------+-------------+----------+ +----+------+--------+------------+-------------+----------+
如果没有的话,我们可以创建一个最简单的实例:
nova boot --flavor m1.tiny --image cirros test1
+--------------------------------------+-----------------------------------------------+ | Property | Value | +--------------------------------------+-----------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | nova | | OS-EXT-SRV-ATTR:host | - | | OS-EXT-SRV-ATTR:hypervisor_hostname | - | | OS-EXT-SRV-ATTR:instance_name | instance-00000002 | | OS-EXT-STS:power_state | 0 | | OS-EXT-STS:task_state | scheduling | | OS-EXT-STS:vm_state | building | | OS-SRV-USG:launched_at | - | | OS-SRV-USG:terminated_at | - | | accessIPv4 | | | accessIPv6 | | | adminPass | koMo8S7iKqD5 | | config_drive | | | created | 2018-12-14T11:41:38Z | | flavor | m1.tiny (2) | | hostId | | | id | e3c8ef21-673d-43fd-bc7b-75f7bda37021 | | image | cirros (498ef44c-0d77-4c8f-ad1e-508c8ca858b1) | | key_name | - | | metadata | {} | | name | test1 | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | security_groups | default | | status | BUILD | | tenant_id | 00d9dcd033d542b68614c88d19fa0544 | | updated | 2018-12-14T11:41:38Z | | user_id | 83cbfd254b294529853aa51200bd6fe4 | +--------------------------------------+-----------------------------------------------+
然后在nova list查看
+--------------------------------------+--------+--------+------------+-------------+--------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+--------+--------+------------+-------------+--------------------------+ | 4b2cae1f-8eaf-4531-83b0-7c60619e83c7 | test03 | ACTIVE | - | Running | sharednet1=192.168.1.103 | +--------------------------------------+--------+--------+------------+-------------+--------------------------+
接下来就是将我们创建好的cinder卷挂载到我们创建的云主机实例中:
nova volume-attach 4b2cae1f-8eaf-4531-83b0-7c60619e83c7 (云主机实例的id) d679d729-85b7-49fa-ab89-f7b87153b62d(cinder卷的id)
+----------+--------------------------------------+ | Property | Value | +----------+--------------------------------------+ | device | /dev/vdb | | id | 9a523cfc-ab43-49f6-84b3-f8ad5867c2e0 | | serverId | 4b2cae1f-8eaf-4531-83b0-7c60619e83c7 | | volumeId | 9a523cfc-ab43-49f6-84b3-f8ad5867c2e0 | +----------+--------------------------------------+
最后查看挂载情况:
cinder list
+--------------------------------------+-----------+--------------------+------+-------------+----------+--------------------------------------+ | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to | +--------------------------------------+-----------+--------------------+------+-------------+----------+--------------------------------------+ | 0a30c060-425d-4c74-8623-1ea42f01f3aa | error | type_test_demo | 1 | test1 | false | | | 3ea86c92-4f15-4aa0-90fa-99b37b107b3a | error | cinder-volume-demo | 100 | None | false | | | 4bf67c03-2c12-43f8-842b-f971e5c0d97b | available | cinder-volume-demo | 1 | None | false | | | 9a523cfc-ab43-49f6-84b3-f8ad5867c2e0 | in-use | test1 | 1 | None | false | 4b2cae1f-8eaf-4531-83b0-7c60619e83c7 | | feaa8688-cefd-4f2e-987c-2a59cd951885 | available | cinder-volume-demo | 1 | None | false | | +--------------------------------------+-----------+--------------------+------+-------------+----------+--------------------------------------+