OpenStack的存储组件—Cinder和Swift—让你在你的私有云里构建块存储和对象的存储系统,Openstack从Folsom开始使用Cinder替换原来的Nova-Volume服务,为Openstack云平台提供块存储服务,Cinder接口提供了一些标准功能,允许创建和附加块设备到虚拟机,如“创建卷”,“删除卷”和“附加卷”。还有更多高级的功能,支持扩展容量的能力,快照和创建虚拟机镜像克隆,主要涉及到的组件如下:

cinder-api:接受API请求,并将其路由到“cinder-volume“执行,即请求cinder要先请求此对外API。

cinder-volume:与块存储服务和例如“cinder-scheduler“的进程进行直接交互。它也可以与这些进程通过一个消息队列进行交互。“cinder-volume“服务响应送到块存储服务的读写请求来维持状态。它也可以和多种存储提供者在驱动架构下进行交互。

cinder-scheduler守护进程:选择最优存储提供节点来创建卷。其与“nova-scheduler“组件类似。

cinder-backup守护进程:“cinder-backup“服务提供任何种类备份卷到一个备份存储提供者。就像“cinder-volume“服务,它与多种存储提供者在驱动架构下进行交互。

消息队列:在块存储的进程之间路由信息。

17.1创建cinder数据库

# mysql -uroot –p

> CREATE DATABASE cinder;

> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%'  IDENTIFIED BY 'cinde

r123';

> flush privileges;

17.2控制端数据访问验证

# mysql -ucinder -h192.168.10.100 -pcinder123

卷快照 openstack openstack创建快照_vim

17.3控制端cinder服务注册

17.3.1创建cinder用户并授权

# source  admin-ocata.sh
# openstack user create --domain default --password-prompt cinder
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | 81672c29064942aea8fb754820ddb76a |
| enabled             | True                             |
| id                  | f12af1d5583e4b179354c3b4d8d0d778 |
| name                | cinder                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
#授权admin权限
#  openstack role add --project service --user cinder admin

17.3.2创建服务

# v2,v3版本创建

# openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2

# v2,v3版本创建

# openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3

17.3.3注册V2版本endpoint

#公共端点:
# openstack endpoint create --region RegionOne volumev2 public http://192.168.10.100:8776/v2/%\(project_id\)s
+--------------+----------------------------------------------+
| Field        | Value                                        |
+--------------+----------------------------------------------+
| enabled      | True                                         |
| id           | cf87da53a7754996972b7ef2baf73933             |
| interface    | public                                       |
| region       | RegionOne                                    |
| region_id    | RegionOne                                    |
| service_id   | 8077b7de84fc4b32a288306459bad10b             |
| service_name | cinderv2                                     |
| service_type | volumev2                                     |
| url          | http://192.168.10.100:8776/v2/%(project_id)s |
+--------------+----------------------------------------------+
#私有端点:
# openstack endpoint create --region RegionOne volumev2 internal http://192.168.10.100:8776/v2/%\(project_id\)s
+--------------+----------------------------------------------+
| Field        | Value                                        |
+--------------+----------------------------------------------+
| enabled      | True                                         |
| id           | 4d8cfb82cd4a4015876df6aafc8bb219             |
| interface    | internal                                     |
| region       | RegionOne                                    |
| region_id    | RegionOne                                    |
| service_id   | 8077b7de84fc4b32a288306459bad10b             |
| service_name | cinderv2                                     |
| service_type | volumev2                                     |
| url          | http://192.168.10.100:8776/v2/%(project_id)s |
+--------------+----------------------------------------------+
#管理端点:
# openstack endpoint create --region RegionOne volumev2 admin http://192.168.10.100:8776/v2/%\(project_id\)s
+--------------+----------------------------------------------+
| Field        | Value                                        |
+--------------+----------------------------------------------+
| enabled      | True                                         |
| id           | 686d554b483a4a52b36c6b6a6c3a2feb             |
| interface    | admin                                        |
| region       | RegionOne                                    |
| region_id    | RegionOne                                    |
| service_id   | 8077b7de84fc4b32a288306459bad10b             |
| service_name | cinderv2                                     |
| service_type | volumev2                                     |
| url          | http://192.168.10.100:8776/v2/%(project_id)s |
+--------------+----------------------------------------------+

17.3.4注册V3版本endpoint

#公共端点:
# openstack endpoint create --region RegionOne volumev3 public http://192.168.10.100:8776/v3/%\(project_id\)s
+--------------+----------------------------------------------+
| Field        | Value                                        |
+--------------+----------------------------------------------+
| enabled      | True                                         |
| id           | 729e23316e964ff6bc6315f4d95e590a             |
| interface    | public                                       |
| region       | RegionOne                                    |
| region_id    | RegionOne                                    |
| service_id   | 4234b69629ac4e6bbabcd72c8bb0ab81             |
| service_name | cinderv3                                     |
| service_type | volumev3                                     |
| url          | http://192.168.10.100:8776/v3/%(project_id)s |
+--------------+----------------------------------------------+
#私有端点:
# openstack endpoint create --region RegionOne volumev3 internal http://192.168.10.100:8776/v3/%\(project_id\)s
+--------------+----------------------------------------------+
| Field        | Value                                        |
+--------------+----------------------------------------------+
| enabled      | True                                         |
| id           | 0541cfdf2d99477fb4105aac045f0399             |
| interface    | internal                                     |
| region       | RegionOne                                    |
| region_id    | RegionOne                                    |
| service_id   | 4234b69629ac4e6bbabcd72c8bb0ab81             |
| service_name | cinderv3                                     |
| service_type | volumev3                                     |
| url          | http://192.168.10.100:8776/v3/%(project_id)s |
+--------------+----------------------------------------------+
#管理端点:
# openstack endpoint create --region RegionOne volumev3 admin http://192.168.10.100:8776/v3/%\(project_id\)s
+--------------+----------------------------------------------+
| Field        | Value                                        |
+--------------+----------------------------------------------+
| enabled      | True                                         |
| id           | 3b45ed17bb724479a49df89e49a0e2ae             |
| interface    | admin                                        |
| region       | RegionOne                                    |
| region_id    | RegionOne                                    |
| service_id   | 4234b69629ac4e6bbabcd72c8bb0ab81             |
| service_name | cinderv3                                     |
| service_type | volumev3                                     |
| url          | http://192.168.10.100:8776/v3/%(project_id)s |
+--------------+----------------------------------------------+
17.4配置haproxy负载
# vim /etc/haproxy/haproxy.cfg
listen cinder
    bind 192.168.10.100:8776
    mode tcp
    log global
    balance source
    server cinder-server 192.168.10.201:8776 check inter 5000 rise 3 fall 3
# systemctl reload haproxy.service

17.5安装并配置cinder组件

17.5.1控制端安装cinder

#  yum install openstack-cinder –y

17.5.2编辑配置文件cinder.conf

# vim /etc/cinder/cinder.conf
1:[DEFAULT]
263:my_ip = 192.168.10.201
376:auth_strategy = keystone
3243:transport_url = rabbit://openstack:123456@192.168.10.205
3518:[database]
3546:connection = mysql+pymysql://cinder:cinder123@192.168.10.100/cinder
3767:[keystone_authtoken]
3768:auth_uri = http://192.168.10.100:5000
3769:auth_url = http://192.168.10.100:35357
3770:memcached_servers = 192.168.10.100:11211
3771:auth_type = password
3772:project_domain_name = default
3773:user_domain_name = default
3774:project_name = service
3775:username = cinder
3776:password = cinder
3996:[oslo_concurrency]
4012:lock_path = /var/lib/cinder/tmp

17.5.3同步并验证数据库

# su -s /bin/sh -c "cinder-manage db sync" cinder

17.5.4验证数据库同步成功

# mysql -ucinder -h192.168.10.100 -pcinder123

卷快照 openstack openstack创建快照_vim_02

17.5.5控制端重启nova-api服务

#  systemctl restart openstack-nova-api.service

17.5.6启动块存储服务cinder

# systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service

# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service

 

17.5.7验证cinder日志

# tail -f /var/log/cinder/*.log

卷快照 openstack openstack创建快照_mysql_03

17.6配置计算节点使用cinder存储

17.6.1编辑配置文件nova.conf

# vim /etc/nova/nova.conf

3982 [cinder]

4031 os_region_name=RegionOne

17.6.2重启nova服务

# systemctl restart libvirtd.service openstack-nova-compute.service

17.6.3验证cinder控制端

# openstack volume service list

卷快照 openstack openstack创建快照_bc_04

17.7配置存储节点

17.7.1添加磁盘

在负载服务器(或其他指定服务器)新添加一块50G的磁盘然后点确定:

卷快照 openstack openstack创建快照_vim_05

17.7.2安装LVM包

#  yum install lvm2 –y

17.7.3启动LVM并设置为开机启动

#  systemctl enable lvm2-lvmetad.service

#  systemctl start lvm2-lvmetad.service

17.7.4动态识别新磁盘

# ll /sys/class/scsi_host/host

host0/ host1/ host2/

# echo "- - -" > /sys/class/scsi_host/host0/scan

# echo "- - -" > /sys/class/scsi_host/host1/scan

# echo "- - -" > /sys/class/scsi_host/host2/scan

17.7.5验证磁盘

#fdisk -l

卷快照 openstack openstack创建快照_mysql_06

17.7.6创建物理卷和卷组

#  pvcreate /dev/sdb

  Physical volume "/dev/sdb" successfully created.

#  vgcreate cinder-volumes /dev/sdb

  Volume group "cinder-volumes" successfully created

17.8存储安装并配置组件

在负载服务器安装配置

17.8.1安装组件

#  yum install openstack-cinder targetcli python-keystone –y

17.8.2编辑配置文件cinder.conf

# vim /etc/cinder/cinder.conf

1:[DEFAULT]

283:my_ip = 192.168.10.205

288:glance_api_servers = http://192.168.10.100:9292

400:auth_strategy = keystone

404:enabled_backends = lvm

1210:transport_url = rabbit://openstack:123456@192.168.10.205

3730:[database]

3749:connection = mysql+pymysql://cinder:cinder123@192.168.10.100/cinder

3973:[keystone_authtoken]

3974:auth_uri = http://192.168.10.100:5000

3975:auth_url = http://192.168.10.100:35357

3976:memcached_servers = 192.168.10.100:11211

3977:auth_type = password

3978:project_domain_name = default

3979:user_domain_name = default

3980:project_name = service

3981:username = cinder

3982:password = cinder

4249:[oslo_concurrency]

4263:lock_path = /var/lib/cinder/tmp

4904:[lvm]

4905:volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver

4906:volume_group = cinder-volumes

4907:iscsi_protocol = iscsi

4908:iscsi_helper = lioadm

4909:volume_backend_name=Openstack-lvm

 

17.8.3启动服务并设置为开机启动

#  systemctl enable openstack-cinder-volume.service target.service

#  systemctl start openstack-cinder-volume.service target.service

17.8.4验证日志

卷快照 openstack openstack创建快照_卷快照 openstack_07

17.8.5控制端验证cinder注册

# openstack volume service list

卷快照 openstack openstack创建快照_mysql_08

17.9验证卷使用

17.9.1创建卷

使用admin或者demo用户登录到管理界面,点击卷—创建卷:

卷快照 openstack openstack创建快照_mysql_09

17.9.2填写卷信息

卷快照 openstack openstack创建快照_vim_10

17.9.3查看卷状态

卷快照 openstack openstack创建快照_卷快照 openstack_11

17.9.4关联到虚拟机

卷快照 openstack openstack创建快照_卷快照 openstack_12

17.9.5关联到目标虚拟机

卷快照 openstack openstack创建快照_vim_13

17.9.6连接后的卷状态

卷快照 openstack openstack创建快照_mysql_14

17.9.7虚拟机验证磁盘

卷快照 openstack openstack创建快照_vim_15

 

 

17.9.8格式化磁盘

# mkfs.ext4 /dev/vdb

卷快照 openstack openstack创建快照_mysql_16

17.9.9挂载磁盘并复制数据

卷快照 openstack openstack创建快照_bc_17

17.9.10磁盘挂载至其他虚拟机

新创建一个虚拟机,用于将上一步关联的卷分离后挂载到新的虚拟机上进行测试。

17.9.10.1卸载卷

在之前的虚拟机将卷卸载。

 

卷快照 openstack openstack创建快照_bc_18

 

 

17.9.10.2磁盘分离

点击项目-卷-管理连接:

卷快照 openstack openstack创建快照_mysql_19

 

 

 

17.9.10.3分离卷

卷快照 openstack openstack创建快照_vim_20

17.9.10.4确认分离

卷快照 openstack openstack创建快照_vim_21

17.9.10.5挂载至新实例

在管理连接界面,将卷关联至test-vm2:

卷快照 openstack openstack创建快照_bc_22

 

 

17.9.10.6关联成功

卷快照 openstack openstack创建快照_mysql_23

17.9.10.7新实例验证磁盘

验证可以挂载关联的磁盘并可以查看之前的数据

卷快照 openstack openstack创建快照_mysql_24