cinder 以挂接的方式加入到现有的 openstack 环境中。
    cinder 块存储服务需要至少一个额外的存储节点,该节点为实例提供卷。
    本实验搭建一个专门的存储节点及使用其之上的一块空白磁盘(/dev/sdb),以卷的形式,向实例提供数据盘。

    安装好存储节点的 centos 系统,并配置好 IP 和主机名,编辑 hosts 文件加入主机解析等。
    存储节点的管理网络的 ip 地址为 192.168.10.44,主机名是 b1。

    安装和配置控制器节点
    创建数据库
    mysql -u root -p

    创建 cinder 数据库
    MariaDB [(none)]> CREATE DATABASE cinder;

    授予对 cinder 数据库的适当访问权限
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder. TO ‘cinder’@’localhost’ IDENTIFIED BY ‘CINDER_DBPASS’;
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.
    TO ‘cinder’@’%’ IDENTIFIED BY ‘CINDER_DBPASS’;
    MariaDB [(none)]> exit;

    创建服务凭证
    . admin-openrc
    创建 cinder 用户
    openstack user create —domain default —password CINDER_PASS cinder

    向 cinder 用户添加 admin 角色
    openstack role add —project service —user cinder admin

    创建 cinderv2 和 cinderv3 服务实体
    openstack service create —name cinderv2 —description “OpenStack Block Storage” volumev2
    openstack service create —name cinderv3 —description “OpenStack Block Storage” volumev3

    创建块存储服务 API 端点
    openstack endpoint create —region RegionOne volumev2 public http://ct:8776/v2/%(project_id)ss)
    openstack endpoint create —region RegionOne volumev2 internal http://ct:8776/v2/%(project_id)ss)
    openstack endpoint create —region RegionOne volumev2 admin http://ct:8776/v2/%(project_id)ss)
    openstack endpoint create —region RegionOne volumev3 public http://ct:8776/v3/%(project_id)ss)
    openstack endpoint create —region RegionOne volumev3 internal http://ct:8776/v3/%(project_id)ss)
    openstack endpoint create —region RegionOne volumev3 admin http://ct:8776/v3/%(project_id)ss)

    安装软件包
    yum install openstack-cinder
    cp /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak
    grep -Ev ‘#|^$’ /etc/cinder/cinder.conf.bak>/etc/cinder/cinder.conf
    vim /etc/cinder/cinder.conf
    [database]
    connection = mysql+pymysql://cinder:CINDER_DBPASS@ct/cinder

    [DEFAULT]
    transport_url = rabbit://openstack:RABBIT_PASS@ct
    auth_strategy = keystone
    my_ip = 192.168.10.41

    [keystone_authtoken]
    www_authenticate_uri = http://ct:5000
    auth_url = http://ct:5000
    memcached_servers = ct:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = cinder
    password = CINDER_PASS

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

    填充块存储数据库
    su -s /bin/sh -c “cinder-manage db sync” cinder

    配置计算以使用块存储
    vim /etc/nova/nova.conf
    [oslo_concurrency]
    os_region_name = RegionOne

    重新启动 Compute API 服务
    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

    安装和配置存储节点
    存储节点的管理网络的 ip 地址为 192.168.10.44

    安装 LVM 软件包
    yum install lvm2 device-mapper-persistent-data

    启动 LVM 元数据服务,并将其配置为在系统引导时启动
    systemctl enable lvm2-lvmetad.service
    systemctl start lvm2-lvmetad.service

    创建 LVM 物理卷 / dev/sdb
    pvcreate /dev/sdb

    创建 LVM 卷组 cinder-volumes
    vgcreate cinder-volumes /dev/sdb

    将 LVM 重新配置为仅扫描包含 cinder-volumes 卷组的设备
    vim /etc/lvm/lvm.conf
    在 devices 部分中,添加一个接受 / dev/sdb 设备并拒绝所有其他设备的过滤器:
    devices {
    filter = [ “a/sdb/“, “r/.*/“]
    a 用于接受,r 用于拒绝。

    安装软件包
    yum install centos-release-openstack-train -y
    yum upgrade -y
    yum install python-openstackclient -y
    yum install openstack-selinux -y
    yum install openstack-cinder targetcli python-keystone -y

    修改配置文件
    cp /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak
    grep -Ev ‘#|^$’ /etc/cinder/cinder.conf.bak>/etc/cinder/cinder.conf
    vim /etc/cinder/cinder.conf
    [database]
    connection = mysql+pymysql://cinder:CINDER_DBPASS@ct/cinder

    [DEFAULT]
    transport_url = rabbit://openstack:RABBIT_PASS@ct
    auth_strategy = keystone
    my_ip = 192.168.10.44
    enabled_backends = lvm
    glance_api_servers = http://ct:9292

    [keystone_authtoken]
    www_authenticate_uri = http://ct:5000
    auth_url = http://ct:5000
    memcached_servers = ct:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = cinder
    password = CINDER_PASS

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

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

    启动块存储卷服务及其相关,并将其配置为在系统启动时启动:
    systemctl enable openstack-cinder-volume.service target.service
    systemctl start openstack-cinder-volume.service target.service

    验证 cinder 块存储服务
    . admin-openrc
    openstack volume service list

    使用块存储服务向实例提供数据盘
    创建卷(volume)
    . ygj-openrc
    创建一个 10 GB 的卷:
    openstack volume create —size 10 volume1
    很短的时间后,卷状态应该从 creating 到 available
    openstack volume list

    将卷附加到实例
    openstack server add volume INSTANCE_NAME VOLUME_NAME
    将 volume1 卷附加到 centos7-instance1 实例:
    openstack server add volume centos7-instance1 volume1
    openstack volume list

    使用 SSH 访问实例,并使用以下 fdisk 命令验证该卷是否作为 / dev/vdb 块存储设备:
    sudo fdisk -l
    分区并格式化新添加的 / dev/vdb
    fdisk /dev/vdb
    mk2fs.ext4 /dev/vdb1
    https://blog.51cto.com/11694088/2464232