“OpenStack:Cinder组件的运维”的版本间的差异

来自CloudWiki
跳转至: 导航搜索
指定Cinder卷类型
第343行: 第343行:
 
===对LVM卷进行扩容===
 
===对LVM卷进行扩容===
 
====首先我们通过“pvcreate”命令创建pv====
 
====首先我们通过“pvcreate”命令创建pv====
首先,在计算节点上新创建一个分区/dev/sda6
+
首先,在计算节点上新创建一个分区/dev/sdb2
  
[root@controller ~]# fdisk /dev/sda
+
[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.
  
<nowiki>WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
 
        switch off the mode (command 'c') and change display units to
 
        sectors (command 'u').
 
  
 
Command (m for help): n
 
Command (m for help): n
First cylinder (10461-13055, default 10461): 10461
+
Partition type:
Last cylinder, +cylinders or +size{K,M,G} (10461-13055, default 13055): +10g^H^H
+
  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 cylinder, +cylinders or +size{K,M,G} (10461-13055, default 13055): 10G'
+
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +2G
Value out of range.
+
Partition 2 of type Linux and of size 2 GiB is set
Last cylinder, +cylinders or +size{K,M,G} (10461-13055, default 13055): +10G
 
  
 
Command (m for help): W
 
Command (m for help): W
第369行: 第375行:
 
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
第380行: 第387行:
 
[root@controller ~]# lsblk
 
[root@controller ~]# lsblk
  
  <nowiki>NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
+
  <nowiki>NAME                                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0    11:0    1 1024M 0 rom 
+
sda                                            8:0    0  100G  0 disk
sda      8:0    0  100G 0 disk
+
└─sda1                                        8:1   0 93.2G 0 part
├─sda1   8:1    0 48.8G 0 part /
+
  ├─centos-root                              253:0    0 55.9G 0 lvm /
├─sda2   8:2    0 19.5G 0 part /srv/node
+
   ├─centos-swap                              253:1    0 18.6G 0 lvm  [SWAP]
├─sda3   8:3    0 9.8G 0 part  
+
   └─centos-home                              253:2    0 18.6G 0 lvm  /home
│ └─cinder--volumes-volume--4bf67c03--2c12--43f8--842b--f971e5c0d97b (dm-0)
+
sdb                                            8:16   0  20G  0 disk
      253:0   0    1G  0 lvm
+
├─sdb1                                        8:17  0   10G 0 part
├─sda4  8:4    0    1K 0 part
+
│ ├─cinder--volumes-volume--39aa5d70--6185--40b9--bac0--847d6f9fc016
├─sda5  8:5    0    2G  0 part [SWAP]
+
                                            253:3   0    1G  0 lvm
└─sda6  8:6   0   10G 0 part</nowiki>  
+
│ └─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/sda6
+
[root@controller ~]#  pvcreate /dev/sdb2 (刚才新创建的分区)
  
   <nowiki>dev_is_mpath: failed to get device for 8:6
+
   <nowiki> Physical volume "/dev/sdb2" successfully created
  Physical volume "/dev/sda6" successfully created</nowiki>
+
</nowiki>
  
 
[root@controller ~]# pvdisplay
 
[root@controller ~]# pvdisplay
  
 
   <nowiki>--- Physical volume ---
 
   <nowiki>--- Physical volume ---
   PV Name              /dev/sda3
+
   PV Name              /dev/sdb1
 
   VG Name              cinder-volumes
 
   VG Name              cinder-volumes
   PV Size              9.77 GiB / not usable 4.00 MiB
+
   PV Size              10.00 GiB / not usable 4.00 MiB
   Allocatable          yes  
+
  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
 
   PE Size              4.00 MiB
   Total PE              2499
+
   Total PE              23845
   Free PE              2243
+
   Free PE              2
   Allocated PE          256
+
   Allocated PE          23843
   PV UUID              5yJoVV-H5ll-aWDh-7p7t-CcKp-Mjn2-zcjZre
+
   PV UUID              JwpPRp-jhN9-1CgH-2eOD-QGRE-K0lH-oDxMC4
 
+
 
   "/dev/sda6" is a new physical volume of "10.00 GiB"
+
   "/dev/sdb2" is a new physical volume of "2.00 GiB"
 
   --- NEW Physical volume ---
 
   --- NEW Physical volume ---
   PV Name              /dev/sda6
+
   PV Name              /dev/sdb2
   VG Name              
+
   VG Name
   PV Size              10.00 GiB
+
   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              LwE4wf-fFd3-T441-Fihp-2le1-f50J-Nba2y2</nowiki>
+
   PV UUID              yfUsww-CxqM-DXJn-jQEE-H2Ob-lm2u-1A71Yx
 +
</nowiki>
 
    
 
    
这样就成功的创建了一个名为/dev/sda6的物理分区
+
这样就成功的创建了一个名为/dev/sdb2的物理分区
  
 
==== 接着,我们通过“vgextend”命令扩展已有VG的容量====
 
==== 接着,我们通过“vgextend”命令扩展已有VG的容量====
第453行: 第477行:
 
然后进行卷组宽展:
 
然后进行卷组宽展:
 
    
 
    
[root@controller ~]# vgextend cinder-volumes /dev/sda6
+
[root@controller ~]# vgextend cinder-volumes /dev/sdb2
 
 
 
   Volume group "cinder-volumes" successfully extended
 
   Volume group "cinder-volumes" successfully extended
  
第462行: 第485行:
 
   <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  3
+
   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                1
+
   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              19.76 GiB
+
   VG Size              11.99 GiB
 
   PE Size              4.00 MiB
 
   PE Size              4.00 MiB
   Total PE              5059
+
   Total PE              3070
   Alloc PE / Size      256 / 1.00 GiB
+
   Alloc PE / Size      512 / 2.00 GiB
   Free  PE / Size      4803 / 18.76 GiB
+
   Free  PE / Size      2558 / 9.99 GiB
   VG UUID              phbML6-I5rB-rn7k-uGaa-ek46-c0u2-VCAgo2</nowiki>
+
   VG UUID              M9a5hN-TIAR-Xm3C-mbzp-2QgQ-dUjB-AfJP1e
 +
</nowiki>
  
====重启cinder-volume服务后再次创建该云硬盘====
+
====重启cinder-volume服务后再次创建云硬盘====
 
    
 
    
[root@controller ~]# cinder create --display-name cinder-volume-demo 10
+
[root@controller ~]# cinder create --display-name cinder-volume-demo 2
  
 
  <nowiki>+---------------------+--------------------------------------+
 
  <nowiki>+---------------------+--------------------------------------+

2019年4月26日 (五) 07:26的版本

基础准备

检查现有磁盘

[root@controller ~]# 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
...

添加新硬盘

给计算节点 新增加一块硬盘

Openstack8-41.png

关机重启,输入命令:

[root@controller ~]# 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@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.

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@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
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

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 卷快照。

  1. 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命令查看镜像列表

  1. cinder list查看cinder卷的列表
  1. cinder snapshot-list查看snapshot的列表

还可以通过“cinder show <volume>”命令来查看指定云硬盘的详细信息,命令如下。

  1. 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   |                                      |
+--------------------------------------+-----------+--------------------+------+-------------+----------+--------------------------------------+