【openstack N版】——块存储服务cinder

一.块存储服务介绍

1.1块存储服务通常包含以下组件

  • cinder-api:

    接受API请求,并将其路由到"cinder-volume"执行。

  • cinder-volume:

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

  • cinder-scheduler守护进程:

    选择最优存储提供节点来创建卷。其与"nova-scheduler"组件类似。

  • cinder-backup-daemon:

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

注:cinder不是必须需要的服务,看公司需求,因为是通过挂载NFS等一系列文件服务器来做存储,网络是一个很大的瓶颈,但是做了cinder可以扩容磁盘大小,以及云主机的热迁移

二.块存储服务安装(控制节点)

2.1环境准备

 #安装cinder
[root@linux-node1 ~]# yum install openstack-cinder -y

2.2创建库及用户

 #登录数据库
[root@linux-node1 ~]# mysql -uroot -p
#创建cinder库
MariaDB [(none)]> create database cinder;
#给cinder用户授权
MariaDB [(none)]> grant all privileges on cinder.* to 'cinder'@'localhost' identified by 'cinder';
Query OK, rows affected (0.05 sec)
MariaDB [(none)]> grant all privileges on cinder.* to 'cinder'@'%' identified by 'cinder';
Query OK, rows affected (0.00 sec)

2.3创建openstack的cinder用户

 #创建cinder用户,密码cinder
[root@linux-node1 ~]# openstack user create --domain default --password-prompt cinder
#将cinder用户加入到service项目并且赋予admin角色
[root@linux-node1 ~]# openstack role add --project service --user cinder admin

2.4创建cinder和cinderv2实体服务及端点服务

 #创建cinder实体服务
[root@linux-node1 ~]# openstack service create --name cinder \
--description "OpenStack Block Storage" volume
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Block Storage          |
| enabled     | True                             |
| id          | 0dae8b9c2a434c7a82ad1ad56b53d8d0 |
| name        | cinder                           |
| type        | volume                           |
+-------------+----------------------------------+
#创建cinderv2实体服务
[root@linux-node1 ~]# openstack service create --name cinderv2 \
--description "OpenStack Block Storage" volumev2
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Block Storage          |
| enabled     | True                             |
| id          | 30998a4da9c04e2a9e3a3e247311f09b |
| name        | cinderv2                         |
| type        | volumev2                         |
+-------------+----------------------------------+
#创建API端点(cinder)
[root@linux-node1 ~]# openstack endpoint create --region RegionOne \
volume public http://192.168.56.11:8776/v1/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | 67a154e432de4efaa568f1e8c7a0050e           |
| interface    | public                                     |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 0dae8b9c2a434c7a82ad1ad56b53d8d0           |
| service_name | cinder                                     |
| service_type | volume                                     |
| url          | http://192.168.56.11:8776/v1/%(tenant_id)s |
+--------------+--------------------------------------------+
[root@linux-node1 ~]# openstack endpoint create --region RegionOne \
volume internal http://192.168.56.11:8776/v1/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | 0052499eb61e454ab280d9ac689c463e           |
| interface    | internal                                   |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 0dae8b9c2a434c7a82ad1ad56b53d8d0           |
| service_name | cinder                                     |
| service_type | volume                                     |
| url          | http://192.168.56.11:8776/v1/%(tenant_id)s |
+--------------+--------------------------------------------+
[root@linux-node1 ~]# openstack endpoint create --region RegionOne \
volume admin http://192.168.56.11:8776/v1/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | 5765c91142874d2584d6ea7464900732           |
| interface    | admin                                      |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 0dae8b9c2a434c7a82ad1ad56b53d8d0           |
| service_name | cinder                                     |
| service_type | volume                                     |
| url          | http://192.168.56.11:8776/v1/%(tenant_id)s |
+--------------+--------------------------------------------+
#创建API端点(cinderv2)
[root@linux-node1 ~]# openstack endpoint create --region RegionOne \
volumev2 public http://192.168.56.11:8776/v2/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | 35da6dd734e44bee817fd3712f01b126           |
| interface    | public                                     |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 30998a4da9c04e2a9e3a3e247311f09b           |
| service_name | cinderv2                                   |
| service_type | volumev2                                   |
| url          | http://192.168.56.11:8776/v2/%(tenant_id)s |
+--------------+--------------------------------------------+
[root@linux-node1 ~]# openstack endpoint create --region RegionOne \
volumev2 internal http://192.168.56.11:8776/v2/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | 5c046a3dc07c4c26b642e01f2f5b1be0           |
| interface    | internal                                   |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 30998a4da9c04e2a9e3a3e247311f09b           |
| service_name | cinderv2                                   |
| service_type | volumev2                                   |
| url          | http://192.168.56.11:8776/v2/%(tenant_id)s |
+--------------+--------------------------------------------+
[root@linux-node1 ~]# openstack endpoint create --region RegionOne \
volumev2 admin http://192.168.56.11:8776/v2/%\(tenant_id\)s
+--------------+--------------------------------------------+
| Field        | Value                                      |
+--------------+--------------------------------------------+
| enabled      | True                                       |
| id           | 5d86cf81628c42e8847a7bb8373df0a6           |
| interface    | admin                                      |
| region       | RegionOne                                  |
| region_id    | RegionOne                                  |
| service_id   | 30998a4da9c04e2a9e3a3e247311f09b           |
| service_name | cinderv2                                   |
| service_type | volumev2                                   |
| url          | http://192.168.56.11:8776/v2/%(tenant_id)s |
+--------------+--------------------------------------------+

2.5编辑cinder配置文件

 #编辑配置文件
[root@linux-node1 ~]# vim /etc/cinder/cinder.conf
#配置数据库连接
connection = mysql+pymysql://cinder:cinder@192.168.56.11/cinder
#配置连接消息队列
transport_url = rabbit://openstack:openstack@192.168.56.11
#开启keystone认证,打开注释
auth_strategy = keystone
#在keystone_authtoken标签下添加内容
[keystone_authtoken]
auth_uri = http://192.168.56.11:5000
auth_url = http://192.168.56.11:35357
memcached_servers = 192.168.56.11:
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = cinder
password = cinder
#配置锁路径
lock_path = /var/lib/cinder/tmp

2.6将数据导入数据库

 [root@linux-node1 ~]# su -s /bin/sh -c "cinder-manage db sync" cinder

2.7检查数据库

 [root@linux-node1 ~]# mysql -ucinder -pcinder -h192.168.56. -e "use cinder;show tables;"
+----------------------------+
| Tables_in_cinder           |
+----------------------------+
| backups                    |
| cgsnapshots                |
| clusters                   |
| consistencygroups          |
| driver_initiator_data      |
| encryption                 |
| group_snapshots            |
| group_type_projects        |
| group_type_specs           |
| group_types                |
| group_volume_type_mapping  |
| groups                     |
| image_volume_cache_entries |
| messages                   |
| migrate_version            |
| quality_of_service_specs   |
| quota_classes              |
| quota_usages               |
| quotas                     |
| reservations               |
| services                   |
| snapshot_metadata          |
| snapshots                  |
| transfers                  |
| volume_admin_metadata      |
| volume_attachment          |
| volume_glance_metadata     |
| volume_metadata            |
| volume_type_extra_specs    |
| volume_type_projects       |
| volume_types               |
| volumes                    |
| workers                    |
+----------------------------+

2.8编辑nova配置文件

 #编辑nova配置文件
[root@linux-node1 ~]# vim /etc/nova/nova.conf
#在cinder标签下添加内容
[cinder]
os_region_name=RegionOne

2.9启动服务

 #重启nova-api服务
[root@linux-node1 ~]# systemctl restart openstack-nova-api.service
#允许开机自启动
[root@linux-node1 ~]# systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
#启动cinder服务及其组件
[root@linux-node1 ~]# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
#允许lvm2服务开机自启
[root@linux-node1 ~]# systemctl enable lvm2-lvmetad.service
#启动lvm2服务
[root@linux-node1 ~]# systemctl start lvm2-lvmetad.service

三.块存储服务安装(存储节点)

因为环境只有两台服务器,所以将存储节点也装在控制节点上

3.1准备环境

 #安装lvm2
[root@linux-node1 ~]# yum install lvm2 -y
#安装cinder及其组件
[root@linux-node1 ~]# yum install openstack-cinder targetcli python-keystone

3.2启动服务

 #允许lvm2开机自启
[root@linux-node1 ~]# systemctl enable lvm2-lvmetad.service
#启动lvm2
[root@linux-node1 ~]# systemctl start lvm2-lvmetad.service

3.3创建LVM物理卷

 [root@linux-node1 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.

3.4创建LVM卷组"cinder-volume"

 [root@linux-node1 ~]# vgcreate cinder-volumes /dev/sdb
Volume group "cinder-volumes" successfully created

3.5修改LVM配置文件

  只有实例可以访问块存储卷组。但是,底层的操作系统管理着与这些卷相关联的设备。默认情况下,LVM卷扫描工具会扫描``/dev`` 目录,查找包含卷的块存储设备。如果项目在他们的卷上使用了LVM,扫描工具便会在检测到这些卷时尝试缓存它们,这可能会在底层操作系统和项目卷上产生各种问题。所以您必须重新配置LVM,让它扫描仅包含``cinder-volume``卷组的设备。编辑``/etc/lvm/lvm.conf``文件并完成下面的操作:

在 devices 部分,添加一个过滤器,只接受 /dev/sdb 设备,拒绝其他所有设备:

 [root@linux-node1 ~]# vim /etc/lvm/lvm.conf
filter = [ "a/sda/", "a/sdb/", "r/.*/"]

3.6修改cinder配置文件

 [root@linux-node1 ~]# vim /etc/cinder/cinder.conf
#在default标签下添加内容
[default]
#启动LVM后端
enabled_backends = lvm
#在lvm标签下添加内容
[lvm]
#配置LVM后端,包括LVM驱动,cinder-volumes卷组 ,iSCSI 协议和适当的 iSCSI服务
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
iscsi_protocol = iscsi
iscsi_helper = lioadm
glance_api_servers = http://192.168.56.11:9292
iscsi_ip_address = 192.168.56.11

3.7启动服务

 #允许开机自启
[root@linux-node1 ~]# systemctl enable openstack-cinder-volume.service target.service
#启动服务
[root@linux-node1 ~]# systemctl start openstack-cinder-volume.service target.service

四.格式化分区、挂载

4.1在web页面添加磁盘

#新创建一个云主机,然后连接卷

【openstack N版】——块存储服务cinder

4.2磁盘格式化

 #磁盘格式化
[root@web-node1 ~]# mkfs.xfs /dev/vdc
#创建data目录
[root@web-node1 ~]# mkdir /data
#挂载磁盘
[root@web-node1 ~]# mount /dev/vdc /data

注:后端存储,不仅可以用ISCSI,还可以用NFS、GFS等等,后期会更新如何用NFS做后端存储,敬请期待。

【开源是一种精神,分享是一种美德】

— By GoodCook

— 笔者QQ:253097001

— 欢迎大家随时来交流

—原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。

上一篇:Lambda表达式 和 Expression


下一篇:【线段树】Bzoj1230 [Usaco2008 Nov]lites 开关灯