---
title: 安装Cinder
description: "Cinder块存储为虚拟机实例提供持久化存储。它的存在简化了块存储设备的创建和管理。请在控制节点和存储节点安装Cinder。在控制节点和存储节点安装Cinder的操作有所不同，操作过程中请仔细分辨。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcpfs/ecosystemEnable/OpenStack/kunpengopenstackwallaby_04_019.html
sourcePath: /source/zh/kunpengcpfs/ecosystemEnable/OpenStack/kunpengopenstackwallaby_04_019.html
indexId: f9907fa53cf220ec2bd3a47e680eabe5e5e30fad3b723bac25433a00af15bacc84
---
# 安装Cinder

Cinder块存储为虚拟机实例提供持久化存储。它的存在简化了块存储设备的创建和管理。请在控制节点和存储节点安装Cinder。在控制节点和存储节点安装Cinder的操作有所不同，操作过程中请仔细分辨。

#### 在控制节点安装和配置Cinder

1. 创建数据库。

  a. 以root用户登录数据库。

```
mysql -u root -p
```


  b. 在数据库中，创建Cinder数据库并授权。
    1 2 3 CREATE DATABASE cinder; GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' IDENTIFIED BY 'CINDER_DBPASS'; GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'CINDER_DBPASS';

    替换CINDER_DBPASS为Cinder数据库设置密码。密码请勿包含字符“#@$”，支持特殊字符“&=- _ . + ! * ()”。

  c. 退出数据库。

```
exit
```


2. 创建Cinder服务凭证。

```
source
~
/.admin-openrc
openstack user create --domain default --password-prompt cinder
openstack role add --project service --user cinder admin
openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
```


  密码请勿包含字符“#@$”，支持特殊字符“&=- _ . + ! * ()”

3. 创建块存储服务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
```


4. 安装软件包。

```
yum install openstack-cinder-api openstack-cinder-scheduler
```


5. 编辑Cinder相关配置。

  a. 打开配置文件。

```
vi /etc/cinder/cinder.conf
```


  b. 按“i”进入编辑模式，添加如下内容。

```
[DEFAULT]
transport_url = rabbit://openstack:
RABBIT_PASSWORD
@controller
auth_strategy = keystone
my_ip = 192.168.14.2
[database]
connection = mysql+pymysql://cinder:
CINDER_DBPASS
@controller/cinder
[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 =
CINDER_PASSWORD
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
```


    [database]字段用于配置数据库参数。 [DEFAULT]字段用于配置RabbitMQ消息队列入口，配置my_ip。 [DEFAULT] [keystone_authtoken]字段用于配置身份认证服务入口。 [oslo_concurrency]字段用于配置lock path。 192.168.14.2 为控制节点的管理IP地址。 CINDER_DBPASS为Cinder数据库的密码。 RABBIT_PASSWORD为RabbitMQ中OpenStack账户的密码。 CINDER_PASSWORD为Cinder用户的密码。


  c. 按“Esc”键退出编辑模式，输入:wq!，按“Enter”键保存并退出文件。


#### 在存储节点安装和配置Cinder

1. 安装LVM包。

```
yum install lvm2 device-mapper-persistent-data scsi-target-utils rpcbind nfs-utils openstack-cinder-volume openstack-cinder-backup
```


2. 准备存储设备。以下仅为示例。
  1 2 3 4 5 6 7 pvcreate /dev/sdb vgcreate cinder-volumes /dev/sdb vi /etc/lvm/lvm.conf devices { ... filter = [ "a/sdb/", "r/.*/"]

  在devices字段中添加过滤，以接受“/dev/sda”设备并拒绝其他设备。 filter过滤器阵列中的每个项目开头为“a”或者“r”，用于接受或拒绝某个设备，如果操作系统本身也使用了LVM卷，则还必须将关联的系统盘设备添加到过滤器。例如，如果“/dev/sda”设备包含操作系统，则需要将“sda”添加到过滤器。

3. 修改配置文件“/etc/cinder/cinder.conf”。

  a. 打开配置文件“/etc/cinder/cinder.conf”。

```
vi /etc/cinder/cinder.conf
```


  b. 按“i”进入编辑模式，添加如下内容。

```
[DEFAULT]
transport_url = rabbit://openstack:
RABBIT_PASSWORD
@controller
auth_strategy = keystone
my_ip =
192.168.14.4
enabled_backends = lvm
[database]
connection = mysql+pymysql://cinder:
CINDER_DBPASS
@controller/cinder
[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 =
CINDER_PASSWORD
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
iscsi_protocol = iscsi
iscsi_helper = tgtadm
```


    192.168.14.4为当前节点的管理IP地址。 RABBIT_PASSWORD为OpenStack用户的RabbitMQ密码。 将CINDER_DBPASS替换为Cinder数据库密码，将CINDER_PASSWORD替换为Cinder用户密码。


  c. 按“Esc”键退出编辑模式，输入:wq!，按“Enter”键保存并退出文件。
4. 当Cinder使用tgtadm的方式挂载卷的时候，需要在“/etc/tgt/tgtd.conf”文件最后添加如下内容，保证tgtd可以发现cinder-volume的iSCSI Target。

```
include /var/lib/cinder/volumes/*
```


5. 启动存储服务，并将其配置为在系统引导时启动。

```
systemctl enable rpcbind.service nfs-server.service tgtd.service iscsid.service openstack-cinder-volume.service openstack-cinder-backup.service
systemctl start rpcbind.service nfs-server.service tgtd.service iscsid.service openstack-cinder-volume.service openstack-cinder-backup.service
```


#### 在控制节点启动Cinder服务

1. 同步数据库。

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


2. 配置Nova。

  a. 打开配置文件。

```
vi /etc/nova/nova.conf
```


  b. 按“i”进入编辑模式，添加如下内容。

```
[cinder]
os_region_name = RegionOne
```


  c. 按“Esc”键退出编辑模式，输入:wq!，按“Enter”键保存并退出文件。
3. 重启计算API服务。

```
systemctl restart openstack-nova-api.service
```


4. 启动Cinder服务。

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