1、创建数据库
使用数据库访问客户端,以 root 用户身份连接到数据库服务器。
mysql -u root -p
依次执行以下命令创建数据库并设置访问权限,完成之后退出数据库访问客户端。这
里 cinder 用户的密码设为 cinder123
MariaDB [(none)]> CREATE DATABASE cinder;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder123';
MariaDB [(none)]> exit;
2、创建cinder服务凭据
创建用户:cinder
openstack user create --domain default --password-prompt 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 端点:
#V2的
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
#下面是V3的
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
yum -y install openstack-cinder
2、编辑文件并完成以下操作:/etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:cinder123@controller/cinder
[DEFAULT]
transport_url = rabbit://openstack:openstack123@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 = cinder123
[DEFAULT]
my_ip = 10.0.0.11
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
填充块存储数据库:
su -s /bin/sh -c "cinder-manage db sync" cinder
3、在控制节点配置计算服务使用块存储服务
[cinder]
os_region_name = RegionOne
1、重新启动计算 API 服务:
systemctl restart openstack-nova-api.service
2、启动块存储服务,并将其配置为在系统引导时启动:
systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
将计算节点作为存储节点
1、在存储节点主机上增加一块硬盘sdb
2、安装支持工具包
yum -y install lvm2 device-mapper-persistent-data
systemctl enable lvm2-lvmetad.service
systemctl start lvm2-lvmetad.service
3、创建 LVM 物理卷/dev/sdb
[root@compute1 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
4、基于该物理卷创建 LVM 卷组 cinder-volumes
[root@compute1 ~]# vgcreate cinder-volumes /dev/sdb
Volume group "cinder-volumes" successfully created
5、编辑/etc/lvm/lvm.conf 文件
1、首先安装软件包。
yum -y install openstack-cinder targetcli python-keystone
2、编辑/etc/cinder/cinder.conf 文件并完成相应设置
[database]
connection = mysql+pymysql://cinder:cinder123@controller/cinder
[DEFAULT]
transport_url = rabbit://openstack:openstack123@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 = cinder123
[DEFAULT]
# ...
my_ip = 10.0.0.31 #计算节点的IP,以实际为准
[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
3、在存储节点(计算节点)
systemctl enable openstack-cinder-volume.service target.service
systemctl start openstack-cinder-volume.service target.service
. admin-openrc
2、执行以下命令列出 Cinder 块存储服务组件。
[root@controller ~]# openstack volume service list
+------------------+--------------+------+---------+-------+----------------------------+
| Binary | Host | Zone | Status | State | Updated At |
+------------------+--------------+------+---------+-------+----------------------------+
| cinder-scheduler | controller | nova | enabled | up | 2022-06-05T11:38:01.000000 |
| cinder-volume | compute1@lvm | nova | enabled | up | 2022-06-05T11:38:02.000000 |
+------------------+--------------+------+---------+-------+----------------------------+
3、创建卷进行要测试
[root@controller ~]# openstack volume create --size 5 --availability-zone nova testVol
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2022-06-05T11:39:44.000000 |
| description | None |
| encrypted | False |
| id | 7a91e682-7970-47f0-aeaf-a73eb98686b8 |
| migration_status | None |
| multiattach | False |
| name | testVol |
| properties | |
| replication_status | None |
| size | 5 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | __DEFAULT__ |
| updated_at | None |
| user_id | 5adedd33881042a3b87857d30066cf2a |
+---------------------+--------------------------------------+
创建完毕,测试
[root@controller ~]# openstack volume list
+--------------------------------------+---------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+---------+-----------+------+-------------+
| 7a91e682-7970-47f0-aeaf-a73eb98686b8 | testVol | available | 5 | |
+--------------------------------------+---------+-----------+------+-------------+