cinder块存储服务的安装部署
更新:HHH   时间:2023-1-7


简介

Cinder块存储是虚拟基础架构中必不可少的组件,是存储虚拟机镜像文件及虚拟机使用的数据的基础。Cinder提供对块存储的管理支持,通过使用iSCSI, 光纤通道或者NFS协议,以及若干私有协议提供后端连接,展现给计算层(Nova)。

Cinder接口提供了一些标准功能,允许创建和附加块设备到虚拟机,如"创建卷","删除卷"和"附加卷"。还有更多高级的功能,支持扩展容量的能力,快照和创建虚拟机镜像克隆。

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)s
openstack endpoint create --region RegionOne volumev2 internal http://ct:8776/v2/%(project_id)s
openstack endpoint create --region RegionOne volumev2 admin http://ct:8776/v2/%(project_id)s
openstack endpoint create --region RegionOne volumev3 public http://ct:8776/v3/%(project_id)s
openstack endpoint create --region RegionOne volumev3 internal http://ct:8776/v3/%(project_id)s
openstack endpoint create --region RegionOne volumev3 admin http://ct:8776/v3/%(project_id)s

安装软件包
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

返回云计算教程...