直接将cinder服务和块设备都部署在controller节点上
在controller节点添加一块100G的块设备/dev/sdb
配置数据库
(root@localhost) [(none)]> CREATE DATABASE cinder; Query OK, 1 row affected (0.02 sec) (root@localhost) [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder'; Query OK, 0 rows affected (0.10 sec) (root@localhost) [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' IDENTIFIED BY 'cinder'; Query OK, 0 rows affected (0.00 sec) (root@localhost) [(none)]> flush privileges ; Query OK, 0 rows affected (0.04 sec)
配置cinder服务认证
创建cinder用户:
root@controller:~# openstack user create --password-prompt cinder User Password:cinder Repeat User Password:cinder +----------+----------------------------------+ | Field | Value | +----------+----------------------------------+ | email | None | | enabled | True | | id | cbdfbba062b6446dac61ca9b9ce67eb6 | | name | cinder | | username | cinder | +----------+----------------------------------+
将admin角色添加给cinder用户:
root@controller:~# openstack role add --project service --user cinder admin +-------+----------------------------------+ | Field | Value | +-------+----------------------------------+ | id | 63561476dd124bc1b6fe1e4f3cb7f3dc | | name | admin | +-------+----------------------------------+
创建cinder的服务实体:
root@controller:~# openstack service create --name cinder --description "OpenStack Block Storage" volume +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Block Storage | | enabled | True | | id | 91fafad225f1475c9b4596ec663a8d9e | | name | cinder | | type | volume | +-------------+----------------------------------+ root@controller:~# openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2 +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Block Storage | | enabled | True | | id | 53b6766c632b43d0ae442d6e07af5a03 | | name | cinderv2 | | type | volumev2 | +-------------+----------------------------------+
创建cinder服务的API endpoint:
root@controller:~# openstack endpoint create --publicurl http://controller:8776/v2/%\(tenant_id\)s --internalurl http://controller:8776/v2/%\(tenant_id\)s --adminurl http://controller:8776/v2/%\(tenant_id\)s --region RegionOne volume +--------------+-----------------------------------------+ | Field | Value | +--------------+-----------------------------------------+ | adminurl | http://controller:8776/v2/%(tenant_id)s | | id | d9246387b6ec4f0f9a63e60c25b481f4 | | internalurl | http://controller:8776/v2/%(tenant_id)s | | publicurl | http://controller:8776/v2/%(tenant_id)s | | region | RegionOne | | service_id | 91fafad225f1475c9b4596ec663a8d9e | | service_name | cinder | | service_type | volume | +--------------+-----------------------------------------+ root@controller:~# openstack endpoint create --publicurl http://controller:8776/v2/%\(tenant_id\)s --internalurl http://controller:8776/v2/%\(tenant_id\)s --adminurl http://controller:8776/v2/%\(tenant_id\)s --region RegionOne volumev2 +--------------+-----------------------------------------+ | Field | Value | +--------------+-----------------------------------------+ | adminurl | http://controller:8776/v2/%(tenant_id)s | | id | 7f4e8c7a9b794336a61013ce56ceb994 | | internalurl | http://controller:8776/v2/%(tenant_id)s | | publicurl | http://controller:8776/v2/%(tenant_id)s | | region | RegionOne | | service_id | 53b6766c632b43d0ae442d6e07af5a03 | | service_name | cinderv2 | | service_type | volumev2 | +--------------+-----------------------------------------+
安装cinder-server
root@controller:~# apt-get install cinder-api cinder-scheduler python-cinderclient cinder-volume
配置cinder-server
[DEFAULT] rpc_backend = rabbit auth_strategy = keystone my_ip = 10.0.0.200 [database] connection = mysql://cinder:cinder@controller/cinder [oslo_messaging_rabbit] rabbit_host = controller rabbit_userid = openstack rabbit_password = openstack [keystone_authtoken] auth_uri = http://controller:5000 auth_url = http://controller:35357 auth_plugin = password project_domain_id = default user_domain_id = default project_name = service username = cinder password = cinder [oslo_concurrency] lock_path = /var/lock/cinder
初始化数据库:
root@controller:~# su -s /bin/sh -c "cinder-manage db sync" cinder
重启服务:
root@controller:~# service cinder-scheduler restart cinder-scheduler stop/waiting cinder-scheduler start/running, process 5420 root@controller:~# service cinder-api restart cinder-api stop/waiting cinder-api start/running, process 5444
删除Ubuntu自带的SQLit数据库:
root@controller:~# rm -f /var/lib/cinder/cinder.sqlite
块存储配置
创建新分区:将sdb整块盘建立一个分区:
root@controller:~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x622b5756.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x622b5756
Device Boot Start End Blocks Id System
/dev/sdb1 2048 209715199 104856576 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
配置LVM的物理卷:
root@controller:~# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created root@controller:~# pvdisplay --- Physical volume --- PV Name /dev/sdb1 VG Name cinder-volumes 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 bLnc53-Yv3d-samm-nGLL-riM8-TyJc-xQn0i5
创建LVM的卷组cinder-volumes:
root@controller:~# vgcreate cinder-volumes /dev/sdb1 Volume group "cinder-volumes" successfully created root@controller:~# vgdisplay --- Volume group --- VG Name cinder-volumes System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 100.00 GiB PE Size 4.00 MiB Total PE 25599 Alloc PE / Size 0 / 0 Free PE / Size 25599 / 100.00 GiB VG UUID B623Af-5Uru-0S81-23Cr-XOZt-ZCkq-Wh42sf
配置LVM仅仅扫描含有cinder-volume的卷组
编辑/etc/lvm/lvm.conf,在devices部分,添加一个筛选器,仅仅允许/dev/sdb设备并拒绝所有其他设备:
devices {
...
filter = [ "a/sdb/", "r/.*/"]
安装cinder
由于都部署在controller节点上,可以忽略这步
root@controller:~# apt-get install -y cinder-volume python-mysqldb
配置cinder
/etc/cinder/cinder.conf 添加:
[DEFAULT] #启用LVM作为后端存储系统 enabled_backends = lvm #镜像服务运行的节点 glance_host = controller #配置LVM驱动,卷组,iscsi的协议和helper: [lvm] volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver volume_group = cinder-volumes iscsi_protocol = iscsi iscsi_helper = tgtadm
重启服务:
root@controller:~# service tgt restart tgt stop/waiting tgt start/running, process 3785 root@controller:~# service cinder-volume restart cinder-volume stop/waiting cinder-volume start/running, process 3838
检查块存储服务启动的服务组件:
root@controller:~# cinder service-list +------------------+----------------+------+---------+-------+----------------------------+-----------------+ | Binary | Host | Zone | Status | State | Updated_at | Disabled Reason | +------------------+----------------+------+---------+-------+----------------------------+-----------------+ | cinder-scheduler | controller | nova | enabled | up | 2019-08-27T03:43:37.000000 | None | | cinder-volume | controller | nova | enabled | up | 2019-08-27T03:42:48.000000 | None | | cinder-volume | controller@lvm | nova | enabled | up | 2019-08-27T03:43:33.000000 | None | +------------------+----------------+------+---------+-------+----------------------------+-----------------+
卷的管理
创建1GB的一个卷:
root@controller:~# cinder create --name demo-volume1 1
+---------------------------------------+--------------------------------------+
| Property | Value |
+---------------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2019-08-27T03:44:20.000000 |
| description | None |
| encrypted | False |
| id | 2eea737f-6d26-48d9-b396-5c40062dc606 |
| metadata | {} |
| multiattach | False |
| name | demo-volume1 |
| 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 | e2fc7b33877b4d4e844d63b4343e9d14 |
| os-volume-replication:driver_data | None |
| os-volume-replication:extended_status | None |
| replication_status | disabled |
| size | 1 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| user_id | 5726ba166bea4c9b957ed227bfd26692 |
| volume_type | None |
+---------------------------------------+--------------------------------------+
查看可用的卷:
root@controller:~# cinder list +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+ | ID | Status | Name | Size | Volume Type | Bootable | Attached to | +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+ | 2eea737f-6d26-48d9-b396-5c40062dc606 | available | demo-volume1 | 1 | None | false | | +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+ root@controller:~# nova volume-list +--------------------------------------+-----------+--------------+------+-------------+-------------+ | ID | Status | Display Name | Size | Volume Type | Attached to | +--------------------------------------+-----------+--------------+------+-------------+-------------+ | 2eea737f-6d26-48d9-b396-5c40062dc606 | available | | 1 | - | | +--------------------------------------+-----------+--------------+------+-------------+-------------+
将卷添加到实例中:
root@controller:~# nova volume-attach demo1 2eea737f-6d26-48d9-b396-5c40062dc606 +----------+--------------------------------------+ | Property | Value | +----------+--------------------------------------+ | device | /dev/vdb | | id | 2eea737f-6d26-48d9-b396-5c40062dc606 | | serverId | 69eacd59-57dd-49b4-a310-b1cd98edd935 | | volumeId | 2eea737f-6d26-48d9-b396-5c40062dc606 | +----------+--------------------------------------+ root@controller:~# cinder list +--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+ | ID | Status | Name | Size | Volume Type | Bootable | Attached to | +--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+ | 2eea737f-6d26-48d9-b396-5c40062dc606 | in-use | demo-volume1 | 1 | None | false | 69eacd59-57dd-49b4-a310-b1cd98edd935 | +--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+ root@controller:~# nova volume-list +--------------------------------------+--------+--------------+------+-------------+--------------------------------------+ | ID | Status | Display Name | Size | Volume Type | Attached to | +--------------------------------------+--------+--------------+------+-------------+--------------------------------------+ | 2eea737f-6d26-48d9-b396-5c40062dc606 | in-use | | 1 | - | 69eacd59-57dd-49b4-a310-b1cd98edd935 | +--------------------------------------+--------+--------------+------+-------------+--------------------------------------+