一、存储服务概念
OpenStack块存储服务(Cinder)将持久性存储添加到一个虚拟机。块存储提供了管理卷的基础设施,并与OpenStack计算交互,为实例提供卷。该服务还支持卷快照和卷类型的管理。
块存储服务由以下组件组成:
cinder-api
接收API请求,并将其路由到cinders -volume以进行操作。
cinder-volume
直接与块存储服务和进程(如cinders -scheduler)交互。它还可以通过消息队列与这些进程进行交互。cinders -volume服务响应发送到块存储服务的读写请求,以维护状态。它可以通过驱动程序体系结构与各种存储提供者交互。
cinder-scheduler daemon
选择要在其上创建卷的最佳存储提供程序节点。与nova-scheduler类似的组件。
cinder-backup daemon
Cinder-backup服务向备份存储提供程序提供任何类型的备份卷。与cinders -volume服务一样,它可以通过驱动程序体系结构与各种存储提供者交互。
Messaging queue
在块存储进程之间路由信息。
本节描述如何在Controller节点上安装和配置代码为cinder的块存储服务。此服务至少需要一个额外的存储节点,该节点为实例提供卷。
二、Controller—基础配置
在安装和配置块存储服务之前,必须创建数据库、服务凭据和API端点。
1.创建数据库,为cinder数据库授权
# mysql -uroot -p123456
MariaDB [(none)]> create database cinder;
MariaDB [(none)]> grant all privileges on cinder.* to 'cinder'@'localhost' identified by '123456';
MariaDB [(none)]> grant all privileges on cinder.* to 'cinder'@'%' identified by '123456';
2.创建服务凭据
1)生成管理凭证,以获得访问只有管理CLI命令:
# . admin-openrc
2)创建cinder用户:
# openstack user create --domain default --password-prompt cinder
3)添加admin角色到cinder用户中: (无返回值)
# openstack role add --project service --user cinder admin
4)创建cinder2和cinderv3服务实体:
注:块存储服务需要两个服务实体。
# openstack service create --name cinderv2 \
--description "OpenStack Block Storage" volumev2
# openstack service create --name cinderv3 \
--description "OpenStack Block Storage" volumev3
4)创建块存储服务API端点:
注:块存储服务需要每个服务实体的端点。
# openstack endpoint create --region RegionOne \
volumev2 public http://controller:8776/v2/%\(project_id\)s
# openstack endpoint create --region RegionOne \
volumev2 internal http://controller:8776/v2/%\(project_id\)s
# openstack endpoint create --region RegionOne \
volumev2 admin http://controller:8776/v2/%\(project_id\)s
# openstack endpoint create --region RegionOne \
volumev3 public http://controller:8776/v3/%\(project_id\)s
# openstack endpoint create --region RegionOne \
volumev3 internal http://controller:8776/v3/%\(project_id\)s
# openstack endpoint create --region RegionOne \
volumev3 admin http://controller:8776/v3/%\(project_id\)s
三、Controller—安装配置组件
1.安装包
# yum install -y openstack-cinder
2.编辑 /etc/cinder/cinder.conf文件
# vi /etc/cinder/cinder.conf
1)在[database]选项,配置数据库访问:
[database]
connection = mysql+pymysql://cinder:123456@controller/cinder
2)在[DEFAULT]部分,配置RabbitMQ消息队列访问:
[DEFAULT]
transport_url = rabbit://openstack:123456@controller
3)在[DEFAULT]和[keystone_authtoken]选项,配置身份服务访问:
[DEFAULT]
auth_strategy = keystone
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_id = default
user_domain_id = default
project_name = service
username = cinder
password = 123456
4)在[DEFAULT]选项,配置my_ip选项,使用Controller节点的管理接口IP地址:
[DEFAULT]
my_ip = 192.168.100.10
5)在[oslo_concurrency]选项,配置lock路径:
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
6)同步块存储数据(忽略此输出中的任何弃用消息。)
# su -s /bin//sh -c "cinder-manage db sync" cinder
7)配置计算服务以使用块存储
编辑 /etc/nova/nova.conf 文件
# vi /etc/nova/nova.conf
[cinder]
os_regioon_name = RegionOne
3.启动服务
# systemctl restart openstack-nova-api.service
# systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
将存储节点安装在Compute节点
本节描述如何为块存储服务安装和配置存储节点。为了简单起见,此配置引用一个存储节点,其中包含一个空的本地块存储设备。这些指令使用/dev/sdb,但是可以为特定的节点替换不同的值。
该服务使用LVM驱动程序在该设备上提供逻辑卷,并通过iSCSI传输将它们提供给实例。您可以按照这些说明进行一些小的修改,以使用额外的存储节点水平扩展您的环境。
四、Compute—基础配置
在存储节点上安装和配置块存储服务之前,必须准备好存储设备。
1.安装配套的实用程序包:
1)安装LVM包:
# yum install -y lvm2
2)启动LVM元数据服务,并将其配置为在系统启动时启动:
注:一些发行版默认安装LVM。
# systemctl enable lvm2-lvmetad.service
# systemctl start lvm2-lvmetad.service
2.创建LVM物理卷/dev/sdb:
# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
3.创建LVM卷组cinder-volmes:
注:块存储服务在此卷组中创建逻辑卷。
# vgcreate cinder-volumes /dev/sdb
Volume group "cinder-volumes" successfully created
4.只有实例可以访问块存储卷。然而,底层操作系统管理与卷相关联的设备。默认情况下,LVM卷扫描工具扫描/dev目录中包含卷的块存储设备。如果项目在其卷上使用LVM,那么扫描工具将检测这些卷并试图缓存它们,这会导致底层操作系统和项目卷出现各种问题。必须重新配置LVM,以便只扫描包含cinder-volume卷组的设备。
编辑 /etc/lvm/lvm.conf文件
在devices选项,添加一个接受/dev/sdb设备并拒绝所有其他设备的过滤器:
注:filter数组中的每个项都以for accept或r for reject开头,并包含一个用于设备名称的正则表达式。数组必须以r/结束。*/拒绝任何剩余设备。您可以使用vgs -vvvv命令来测试过滤器。
devices {
...
filter = [ "a/sdb/", "r/.*/"]
五、Compute—安装配置组件
1.安装包
# yum install -y openstack-cinder targetcli python-keystone
2.编辑/etc/cinder/cinder.conf 文件
# vi /etc/cinder/cinder.conf
1)在[database]选项,配置数据库访问
[database]
connection = mysql+pymysql://cinder:123456@controller/cinder
2)在[DEFAULT]选项,配置RabbitMQ消息队列访问:
[DEFAULT]
transport_url = rabbit://openstack:123456@controller
3)在[DEFAULT]和[keystone_authtoken]选项,配置身份服务访问:
[DEFAULT]
auth_strategy = keystone
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_id = default
user_domain_id = default
project_name = service
username = cinder
password = 123456
4)在[DEFAULT]部分,配置my_ip选项:
my_ip = 192.168.100.20
5)在[DEFAULT]选项,配置映像服务API的位置:
glance_api_servers = http://controller:9292
6)在[lvm]选项,使用lvm驱动程序、Cinder卷组、iSCSI协议和iSCSI服务配置lvm后端。如果[lvm]部分不存在,则添加它:
[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
iscsi_protocol = iscsi
iscsi_helper = lioadm
7)在[DEFAULT]部分,启用LVM后端:
[DEFAULT]
enabled_backends = lvm
8)在[oslo_concurrency]节中,配置lock路径
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
3.开启服务
启动块存储卷服务,包括它的依赖项,并配置它们在系统启动时启动:
# systemctl enable openstack-cinder-volume.service target.service
# systemctl restart openstack-cinder-volume.service target.service
六、校验操作
1.生成临时环境变量
# . admin-openrc
2.列出服务组件以验证每个流程的成功启动:
# openstack volume service list
3.创建一个1G的卷,并查看其状态
# cinder create --display-name myVolume 1
# cinder list