【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环境准备

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

2.2创建库及用户

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

2.3创建openstack的cinder用户

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

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

 1 #创建cinder实体服务
 2 [root@linux-node1 ~]# openstack service create --name cinder \
 3 --description "OpenStack Block Storage" volume
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Block Storage          |
| enabled     | True                             |
| id          | 0dae8b9c2a434c7a82ad1ad56b53d8d0 |
| name        | cinder                           |
| type        | volume                           |
+-------------+----------------------------------+
4 #创建cinderv2实体服务 5 [root@linux-node1 ~]# openstack service create --name cinderv2 \ 6 --description "OpenStack Block Storage" volumev2
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Block Storage          |
| enabled     | True                             |
| id          | 30998a4da9c04e2a9e3a3e247311f09b |
| name        | cinderv2                         |
| type        | volumev2                         |
+-------------+----------------------------------+
7 #创建API端点(cinder) 8 [root@linux-node1 ~]# openstack endpoint create --region RegionOne \ 9 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 |
+--------------+--------------------------------------------+
10 [root@linux-node1 ~]# openstack endpoint create --region RegionOne \ 11 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 |
+--------------+--------------------------------------------+
12 [root@linux-node1 ~]# openstack endpoint create --region RegionOne \ 13 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 |
+--------------+--------------------------------------------+
14 #创建API端点(cinderv2) 15 [root@linux-node1 ~]# openstack endpoint create --region RegionOne \ 16 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 |
+--------------+--------------------------------------------+

17 [root@linux-node1 ~]# openstack endpoint create --region RegionOne \ 18 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 |
+--------------+--------------------------------------------+
19 [root@linux-node1 ~]# openstack endpoint create --region RegionOne \ 20 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配置文件

 1 #编辑配置文件
 2 [root@linux-node1 ~]# vim /etc/cinder/cinder.conf 
 3 #配置数据库连接
 4 connection = mysql+pymysql://cinder:cinder@192.168.56.11/cinder
 5 #配置连接消息队列
 6 transport_url = rabbit://openstack:openstack@192.168.56.11
 7 #开启keystone认证,打开注释
 8 auth_strategy = keystone
 9 #在keystone_authtoken标签下添加内容
10 [keystone_authtoken]
11 auth_uri = http://192.168.56.11:5000
12 auth_url = http://192.168.56.11:35357
13 memcached_servers = 192.168.56.11:11211
14 auth_type = password
15 project_domain_name = Default
16 user_domain_name = Default
17 project_name = service
18 username = cinder
19 password = cinder
20 #配置锁路径
21 lock_path = /var/lib/cinder/tmp

2.6将数据导入数据库

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

2.7检查数据库

1 [root@linux-node1 ~]# mysql -ucinder -pcinder -h192.168.56.11 -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配置文件

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

2.9启动服务

 1 #重启nova-api服务
 2 [root@linux-node1 ~]# systemctl restart openstack-nova-api.service
 3 #允许开机自启动
 4 [root@linux-node1 ~]# systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
 5 #启动cinder服务及其组件
 6 [root@linux-node1 ~]# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
 7 #允许lvm2服务开机自启
 8 [root@linux-node1 ~]# systemctl enable lvm2-lvmetad.service
 9 #启动lvm2服务
10 [root@linux-node1 ~]# systemctl start lvm2-lvmetad.service

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

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

 3.1准备环境

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

3.2启动服务

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

3.3创建LVM物理卷

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

3.4创建LVM卷组"cinder-volume"

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

3.5修改LVM配置文件

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

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

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

3.6修改cinder配置文件

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

3.7启动服务

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

四.格式化分区、挂载

4.1在web页面添加磁盘

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

4.2磁盘格式化

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

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

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

  — By GoodCook

  — 笔者QQ:253097001

  — 欢迎大家随时来交流

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

原文地址:https://www.cnblogs.com/goodcook/p/6491269.html