一、基本概念

  1.1、概述:OpenStack块存储服务(cinder)为虚拟机添加持久的存储,块存储提供一个基础设施为了管理卷,以及和OpenStack计算服务交互,为实例提供卷。此服务也会激活管理卷的快照和卷类型的功能。

  1.2、基本组件

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

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

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

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

二、控制节点安装服务

  1、创库授权

mysql -u root -pADMIN_PASS

CREATE DATABASE cinder;

GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' IDENTIFIED BY 'ADMIN_PASS';

GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'ADMIN_PASS';

  2、在keysonte上创建系统用户

openstack user create --domain default --password ADMIN_PASS cinder

openstack role add --project service --user cinder admin

  3、在keysonte上创建服务和注册api

openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2      创建cinderv2服务实体

创建块设备存储服务的 API 入口点
  
openstack endpoint create --region RegionOne volumev2 public http://controller:8776/v2/%\(tenant_id\)s
  
openstack endpoint create --region RegionOne volumev2 internal http://controller:8776/v2/%\(tenant_id\)s
  
openstack endpoint create --region RegionOne volumev2 admin http://controller:8776/v2/%\(tenant_id\)s

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

openstack endpoint create --region RegionOne volumev3 public http://controller:8776/v2/%\(tenant_id\)s

openstack endpoint create --region RegionOne volumev3 internal http://controller:8776/v2/%\(tenant_id\)s

openstack endpoint create --region RegionOne volumev3 admin http://controller:8776/v2/%\(tenant_id\)s

  4、安装服务

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install centos-release-openstack-queens.noarch -y
yum install openstack-cinder -y
yum install openstack-utils -y

   5、修改配置文件

cp /etc/cinder/cinder.conf{,.bak}
grep -Ev '^$|#' /etc/cinder/cinder.conf.bak >/etc/cinder/cinder.conf

openstack-config --set /etc/cinder/cinder.conf DEFAULT rpc_backend rabbit
openstack-config --set /etc/cinder/cinder.conf DEFAULT auth_strategy keystone
openstack-config --set /etc/cinder/cinder.conf DEFAULT my_ip 10.0.0.11
openstack-config --set /etc/cinder/cinder.conf database connection  mysql+pymysql://cinder:ADMIN_PASS@controller/cinder
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken auth_uri http://controller:5000
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken auth_url http://controller:35357
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken memcached_servers controller:11211
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken auth_type password
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken project_domain_name default
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken user_domain_name default
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken project_name service
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken username cinder
openstack-config --set /etc/cinder/cinder.conf keystone_authtoken password ADMIN_PASS
openstack-config --set /etc/cinder/cinder.conf oslo_concurrency lock_path /var/lib/cinder/tmp
openstack-config --set /etc/cinder/cinder.conf oslo_messaging_rabbit rabbit_host controller
openstack-config --set /etc/cinder/cinder.conf oslo_messaging_rabbit rabbit_userid openstack
openstack-config --set /etc/cinder/cinder.conf oslo_messaging_rabbit rabbit_password ADMIN_PASS

  6、配置计算节点以使用块设备存储

[cinder]
os_region_name = RegionOne

  7、同步数据库

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

  8、重启服务

    控制节点重启计算API 服务

systemctl restart openstack-nova-api.service

    计算节点重启openstack-nova-compute服务

systemctl restart openstack-nova-compute.service

   9、启动服务

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

   10、验证服务,web页面会多出一个卷管理

cinder service-list

centos 下openstack本地源 centos部署openstack_mysql

 三、存储节点安装服务

  1、LVM拓扑图

centos 下openstack本地源 centos部署openstack_memcached_02

   2、添加两块硬盘,不关机识别

echo '- - -' >/sys/class/scsi_host/host0/scan
fdisk -l

  

centos 下openstack本地源 centos部署openstack_mysql_03

   3、原理图

centos 下openstack本地源 centos部署openstack_配置文件_04

   4、安装支持的工具包

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install centos-release-openstack-queens.noarch -y
yum install lvm2 -y

  systemctl enable lvm2-lvmetad
  systemctl start lvm2-lvmetad

   5、创建物理卷和卷组 

pvcreate /dev/sdb                                     创建LVM 物理卷 
pvcreate /dev/sdc
vgcreate cinder-ssd /dev/sdb                          创建 LVM 卷组
vgcreate cinder-sata /dev/sdc

   6、修改配置文件

vim /etc/lvm/lvm.conf

filter = [ "a/sdb/", "a/sdc/", "r/.*/"]

  7、安装服务

yum install openstack-cinder targetcli python-keystone -y

  8、原理图

centos 下openstack本地源 centos部署openstack_mysql_05

   9、修改配置文件

cp /etc/cinder/cinder.conf{,.bak}
grep -Ev '^$|#' /etc/cinder/cinder.conf.bak >/etc/cinder/cinder.conf

[DEFAULT]
rpc_backend = rabbit
auth_strategy = keystone
my_ip = 10.0.0.32
glance_api_servers = http://controller:9292
enabled_backends = ssd,sata

[database]
connection = mysql+pymysql://cinder:ADMIN_PASS@controller/cinder

[keystone_authtoken]

auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = ADMIN_PASS
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp

[oslo_messaging_rabbit]
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = ADMIN_PASS
[ssd]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-ssd
iscsi_protocol = iscsi
iscsi_helper = lioadm
volume_backend_name = ssd
[sata]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-sata
iscsi_protocol = iscsi
iscsi_helper = lioadm
volume_backend_name = sata

   10、启动服务

systemctl enable openstack-cinder-volume target
systemctl start openstack-cinder-volume target

   11、控制节点验证

centos 下openstack本地源 centos部署openstack_配置文件_06

 四、随机创建卷

  1、创建一个lvm的卷

centos 下openstack本地源 centos部署openstack_mysql_07

   2、存储节点上查看

centos 下openstack本地源 centos部署openstack_mysql_08

 五、指定盘创建硬盘

  1、管理员菜单里面创建卷类型

centos 下openstack本地源 centos部署openstack_配置文件_09

 

   2、卷上选择查看扩展规格,选择创建卷类型规格,信息填配置文件里面的volume_backend_name字段信息。

centos 下openstack本地源 centos部署openstack_memcached_10

 

   3、创建对应类型的卷

centos 下openstack本地源 centos部署openstack_mysql_11

   4、后台验证

centos 下openstack本地源 centos部署openstack_memcached_12

 六、官方文档安装方法

 控制节点:

  1、创库授权

mysql -u root -pADMIN_PASS

CREATE DATABASE cinder;
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' IDENTIFIED BY 'ADMIN_PASS';
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'ADMIN_PASS';

  2、创建角色

openstack user create --domain default --password ADMIN_PASS cinder
openstack role add --project service --user cinder admin

  3、创建服务并注册api

openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
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

  4、安装服务

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install centos-release-openstack-queens.noarch -y
yum install openstack-cinder -y
yum install openstack-utils -y

  5、修改配置文件

/etc/cinder/cinder.conf
[database]
# ...
connection = mysql+pymysql://cinder:ADMIN_PASS@controller/cinder

[DEFAULT]
# ...
transport_url = rabbit://openstack:ADMIN_PASS@controller
auth_strategy = keystone

[keystone_authtoken]
# ...
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = ADMIN_PASS

[DEFAULT]
# ...
my_ip = 10.0.0.11

[oslo_concurrency]
# ...
lock_path = /var/lib/cinder/tmp

/etc/nova/nova.conf

[cinder]
os_region_name = RegionOne

  6、启动服务

su -s /bin/sh -c "cinder-manage db sync" cinder             同步数据库
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

 存储节点:

  1、安装服务

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install centos-release-openstack-queens.noarch -y
yum install lvm2 qemu -y

  2、创建物理卷

pvcreate /dev/sdb

  3、创建物理卷组

vgcreate cinder-volumes /dev/sdb

  4、修改配置文件130行

/etc/lvm/lvm.conf

devices {
...
filter = [ "a/sdb/", "r/.*/"]

  5、安装服务

yum install openstack-cinder targetcli python-keystone -y

/etc/cinder/cinder.conf

[database]
# ...
connection = mysql+pymysql://cinder:ADMIN_PASS@controller/cinder

[DEFAULT]
# ...
transport_url = rabbit://openstack:ADMIN_PASS@controller

[DEFAULT]
# ...
auth_strategy = keystone

[keystone_authtoken]
# ...
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = ADMIN_PASS

[DEFAULT]
# ...
my_ip = 10.0.0.31


[lvm]
# ...
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
target_protocol = iscsi
target_helper = lioadm

[DEFAULT]
# ...
enabled_backends = lvm

[DEFAULT]
# ...
glance_api_servers = http://controller:9292

[oslo_concurrency]
# ...
lock_path = /var/lib/cinder/tmp

 

  6、启动服务

systemctl enable openstack-cinder-volume.service tgtd.service
systemctl start openstack-cinder-volume.service tgtd.service