本地卷的使用

达芬奇密码2018-07-12 09:38
本地卷,指的是云主机数据卷和云主机在同一物理节点,有助于提升云主机的IO性能。
服务部署

使用本地卷需要将计算节点和存储后端节点部署在同一物理节点上,即nova-compute和cinder-volume服务在同一物理节点上混合部署。
lvm的配置

本地卷后端存储使用lvm逻辑卷。首先要在在使用本地卷的计算节点上创建逻辑卷组。

  • 物理节点上需要安装lvm管理工具
    dpkg -l|grep lvm
    ii  lvm2                                         2.02.95-8                                amd64        Linux Logical Volume Manager
    
  • 在本地磁盘创建分区,并指定分区类型为lvm。

    Disk /dev/vdd: 107.4 GB, 107374182400 bytes
    13 heads, 44 sectors/track, 366634 cylinders, total 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 identifier: 0x4573d851
    
     Device Boot      Start         End      Blocks   Id  System
    /dev/vdd1            2048   209715199   104856576   8e  Linux LVM
    
  • 创建物理卷
    创建物理卷:pvcreate /dev/vdd1
    查看已经创建的物理卷:pvdisplay
    查询结果:
    --- Physical volume ---
    PV Name               /dev/vdd1
    VG Name               vg_lvm_local
    PV Size               100.00 GiB / not usable 3.00 MiB
    Allocatable           yes
    PE Size               4.00 MiB
    Total PE              25599
    Free PE               25599
    Allocated PE          0
    PV UUID               bJLUTz-MEGI-vm9q-mMdy-DyIw-RKYE-OArYyk
    
  • 在创建的物理卷上创建逻辑卷组
    创建逻辑卷组:vgcreate vg_lvm_local /dev/vdc1 /dev/vdd1 /dev/vde1
    查看已经创建的逻辑卷组:vgdisplay
    查询结果:
    --- Volume group ---
    VG Name               vg_lvm_local
    System ID
    Format                lvm2
    Metadata Areas        3
    Metadata Sequence No  37
    VG Access             read/write
    VG Status             resizable
    MAX LV                0
    Cur LV                6
    Open LV               2
    Max PV                0
    Cur PV                3
    Act PV                3
    VG Size               299.99 GiB
    PE Size               4.00 MiB
    Total PE              76797
    Alloc PE / Size       8960 / 35.00 GiB
    Free  PE / Size       67837 / 264.99 GiB
    VG UUID               rGcoIF-2kIt-IbcX-p83P-HJP6-Y3Rz-plDZmP
    
存储后端的配置

  • 创建本地卷的volume-type

cinder type-create lvm
+--------------------------------------+----------+
|                  ID                  |   Name   |
+--------------------------------------+----------+
| 613e57a8-79ae-4b61-81be-a1b69b5b41d8 |   lvm    |
+--------------------------------------+----------+
  • 为本地卷的volume-type指定存储后端名称

cinder type-key 613e57a8-79ae-4b61-81be-a1b69b5b41d8 set volume_backend_name=LVMLocal
  • 配置cinder-volume节点

#指定启用的存储后端
enabled_backends=lvm 

[lvm]
#指定本地卷存储后端使用的volume驱动
volume_driver=cinder.volume.drivers.lvmlocal.LVMLocalDriver
#指定存储后端名称
volume_backend_name=LVMLocal
#指定数据存储所在的逻辑卷组
volume_group=vg_lvm_local
原有配置的修改

cinder volume使用单存储后端时,volume的Host字段格式为主机名。cinder volume使用多存储后端时,volume的Host字段格式为主机名@volume_type。因此,集群中配置cinder volume使用多存储后端之后要把原有的volume做一次迁移,否则原有volume将不可用。迁移方式为:

cinder host-volumes-migrate source dest
source 源主机,格式为主机名
dest 目的主机,格式为主机名@volume_type

注意,在迁移之前要保证目的端的cinder-volume服务为enable状态。

本地卷的创建

  • 创建本地卷的接口与原有接口保持一致,指定volume-type为lvm

cinder create 5 --volume-type lvm
+---------------------+--------------------------------------+
|       Property      |                Value                 |
+---------------------+--------------------------------------+
|     attachments     |                  []                  |
|  availability_zone  |                 nova                 |
|       bootable      |                false                 |
|      created_at     |      2016-08-11T03:28:14.345929      |
| display_description |                 None                 |
|     display_name    |                 None                 |
|          id         | 8fc529ea-4e4f-453d-b6ff-e67ed73b2800 |
|       metadata      |                  {}                  |
|         size        |                  5                   |
|     snapshot_id     |                 None                 |
|     source_volid    |                 None                 |
|        status       |               creating               |
|     volume_type     |                 lvm                  |
+---------------------+--------------------------------------+
  • 管理员/service/qa可以在创建卷时指定卷所在的host

请求示例:
curl -i http://10.166.224.4:8776/v1/2ad031a49c994db99b3b32bcda6bf345/volumes -X POST -H "X-Auth-Project-Id: admin" -H "User-Agent: python-cinderclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: 4b66133f61ad47a88b6278ca9470f631" -d '{"volume": {"status": "creating", "availability_zone": null, "source_volid": null, "display_description": null, "snapshot_id": null, "user_id": null, "size": 1, "display_name": null, "imageRef": null, "attach_status": "detached", "volume_type": "lvm", "project_id": null, "metadata": {}, "forced_host":"devstack-hzyuewenyuan"}}'
响应示例:
{"volume": {"status": "creating", "display_name": null, "attachments": [], "availability_zone": "nova", "bootable": "false", "created_at": "2016-08-11T03:34:04.238546", "display_description": null, "volume_type": "lvm", "snapshot_id": null, "source_volid": null, "metadata": {}, "id": "3314794e-467f-47c8-9d63-4c5356d3e115", "size": 1}}

本文来自网易实践者社区,经作者岳文远授权发布。