Cinder是OpenStack环境中的块存储服务,主要为运行在OpenStack之上的虚拟机提供块存储服务。这种块存储类似于我们日常生活中使用的硬盘、U盘、SD卡等块设备。对于Cinder来说,它主要由三个组件组成:cinder-api、cinder-scheduler和cinder-volume。其中,cinder-api和cinder-scheduler通常部署在控制节点,而cinder-volume则通常部署在存储节点。Cinder-volume的主要作用是通过接收OpenStack控制节点上cinder-scheduler发送过来的请求,进行卷管理。而cinder-api的主要作用是接收请求,并将请求放到对应的消息队列中。cinder-scheduler则负责调度后面的cinder-volume来完成卷的管理。
Swift是OpenStack云存储服务的重要组件,提供了高可用、分布式、持久性、大文件的对象存储服务。它利用便宜的X86硬件存储设备,提供安全、高可靠的存储服务。Swift的架构非常对称,每个节点的功能和作用相同,不会因为单点故障带来系统的不稳定性。此外,每个节点地位相同,没有一个角色是单点的,对元数据及对象文件的存储处理方式也一样。这种架构使得Swift具有很高的可靠性。
Cinder主要是为虚拟机提供块级的持久化卷,通过Cinder可以实现卷的创建、挂载、快照等功能。简而言之,Cinder是在虚拟机层面提供的存储解决方案。而Swift则是OpenStack提供的一种分布式、持续虚拟对象存储服务,它自身维持空间并对外提供对象存储服务。与Cinder相比,Swift更接近于传统的文件系统(如ext3/4),但相比之下逻辑更简单,具有更高的读写效率。因此,Swift与Cinder是两个不同的层次概念。Cinder是在虚拟机层面提供基础硬盘,而Swift则是在这个硬盘上实现的一种“文件系统”。
cinder运维命令
创建云硬盘
[root@localhost ~(keystone_admin)]# cinder create --name cinder 20
+--------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2024-03-22T08:21:32.000000 |
| description | None |
| encrypted | False |
| group_id | None |
| id | fc109dee-9cc7-4e1a-9316-6279f48436f5 |
| metadata | {} |
| migration_status | None |
| multiattach | False |
| name | cinder |
| os-vol-host-attr:host | None |
| os-vol-mig-status-attr:migstat | None |
| os-vol-mig-status-attr:name_id | None |
| os-vol-tenant-attr:tenant_id | 009a94428fb84a0db16aa4a1adab9a35 |
| provider_id | None |
| replication_status | None |
| service_uuid | None |
| shared_targets | True |
| size | 20 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| updated_at | None |
| user_id | 8dbf97f777ee4846878acb44e55f6cdf |
| volume_type | iscsi |
+--------------------------------+--------------------------------------+
[root@localhost ~(keystone_admin)]#
查看创建的云硬盘信息
[root@localhost ~(keystone_admin)]# cinder list
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| fc109dee-9cc7-4e1a-9316-6279f48436f5 | available | cinder | 20 | iscsi | false | |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
[root@localhost ~(keystone_admin)]#
创建云硬盘类型
[root@localhost ~(keystone_admin)]# cinder type-create lvm
+--------------------------------------+------+-------------+-----------+
| ID | Name | Description | Is_Public |
+--------------------------------------+------+-------------+-----------+
| 0c643c13-6f0a-43bb-bee2-519ab6a4f181 | lvm | - | True |
+--------------------------------------+------+-------------+-----------+
[root@localhost ~(keystone_admin)]#
查看卷类型列表
[root@localhost ~(keystone_admin)]# cinder type-list
+--------------------------------------+-------------+---------------------+-----------+
| ID | Name | Description | Is_Public |
+--------------------------------------+-------------+---------------------+-----------+
| 0c643c13-6f0a-43bb-bee2-519ab6a4f181 | lvm | - | True |
| 1f7148df-1d56-4b2e-bfb1-ee08df29b4bf | __DEFAULT__ | Default Volume Type | True |
| a1cca1ec-48ee-4530-9856-80c80e3e5114 | iscsi | - | True |
+--------------------------------------+-------------+---------------------+-----------+
[root@localhost ~(keystone_admin)]#
创建一个带有标识的云硬盘
[root@localhost ~(keystone_admin)]# cinder create --name testmy --volume-type lvm 20
+--------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2024-03-22T08:25:29.000000 |
| description | None |
| encrypted | False |
| group_id | None |
| id | 18df385b-da2c-41cf-b934-f627595d28f1 |
| metadata | {} |
| migration_status | None |
| multiattach | False |
| name | testmy |
| os-vol-host-attr:host | None |
| os-vol-mig-status-attr:migstat | None |
| os-vol-mig-status-attr:name_id | None |
| os-vol-tenant-attr:tenant_id | 009a94428fb84a0db16aa4a1adab9a35 |
| provider_id | None |
| replication_status | None |
| service_uuid | None |
| shared_targets | True |
| size | 20 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| updated_at | None |
| user_id | 8dbf97f777ee4846878acb44e55f6cdf |
| volume_type | lvm |
+--------------------------------+--------------------------------------+
[root@localhost ~(keystone_admin)]# cinder list
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| 18df385b-da2c-41cf-b934-f627595d28f1 | available | testmy | 20 | lvm | false | |
| fc109dee-9cc7-4e1a-9316-6279f48436f5 | available | cinder | 20 | iscsi | false | |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
[root@localhost ~(keystone_admin)]#
删除云硬盘
[root@localhost ~(keystone_admin)]# cinder delete cinder
Request to delete volume cinder has been accepted.
[root@localhost ~(keystone_admin)]# cinder list
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| 18df385b-da2c-41cf-b934-f627595d28f1 | available | testmy | 20 | lvm | false | |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
[root@localhost ~(keystone_admin)]#
用openstack 执行查看云硬盘列表
[root@localhost ~(keystone_admin)]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 18df385b-da2c-41cf-b934-f627595d28f1 | testmy | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------+
[root@localhost ~(keystone_admin)]#
用openstack 执行创建云硬盘
[root@localhost ~(keystone_admin)]# openstack volume create my123 --size 20
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2024-03-22T08:30:46.000000 |
| description | None |
| encrypted | False |
| id | f312732e-db3c-4bbe-902d-0bdb4ffae12b |
| migration_status | None |
| multiattach | False |
| name | my123 |
| properties | |
| replication_status | None |
| size | 20 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | iscsi |
| updated_at | None |
| user_id | 8dbf97f777ee4846878acb44e55f6cdf |
+---------------------+--------------------------------------+
[root@localhost ~(keystone_admin)]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| f312732e-db3c-4bbe-902d-0bdb4ffae12b | my123 | available | 20 | |
| 18df385b-da2c-41cf-b934-f627595d28f1 | testmy | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------+
[root@localhost ~(keystone_admin)]#
删除云硬盘
[root@localhost ~(keystone_admin)]# openstack volume delete my123
[root@localhost ~(keystone_admin)]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 18df385b-da2c-41cf-b934-f627595d28f1 | testmy | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------+
[root@localhost ~(keystone_admin)]#
swift运维命令
创建容器
[root@localhost ~(keystone_admin)]# swift post test
[root@localhost ~(keystone_admin)]# swift list
test
[root@localhost ~(keystone_admin)]#
上传文件至容器中
[root@localhost ~(keystone_admin)]# mkdir file
[root@localhost ~(keystone_admin)]# ls
anaconda-ks.cfg CentOS7.2.qcow2 Desktop Documents Downloads file keystonerc_admin keystonerc_demo Music original-ks.cfg packstack-answers-20240318-231803.txt Pictures Public Templates Videos
[root@localhost ~(keystone_admin)]
1.创建两个文件
[root@localhost file(keystone_admin)]# ls
[root@localhost file(keystone_admin)]# touch abc.txt
[root@localhost file(keystone_admin)]# ls
abc.txt
[root@localhost file(keystone_admin)]# touch 123.txt
[root@localhost file(keystone_admin)]# ls
123.txt abc.txt
[root@localhost file(keystone_admin)]# cd
2.将文件上传到容器中
[root@localhost ~(keystone_admin)]# swift upload test file/
file/123.txt
file/abc.txt
从容器中下载文件
1.删除本地文件
[root@localhost ~(keystone_admin)]# cd file/
[root@localhost file(keystone_admin)]# ls
123.txt abc.txt
[root@localhost file(keystone_admin)]# rm -rf 123.txt abc.txt
[root@localhost file(keystone_admin)]# ls
[root@localhost file(keystone_admin)]#
2.从容器下载文件
错误示范
[root@localhost file(keystone_admin)]# swift download test file/123.txt abc.txt
Object 'test/abc.txt' not foundfile/123.txt [auth 0.451s, headers 0.827s, total 0.827s, 0.000 MB/s]
//由于我已经在该file目录下,找不到file文件所以新建了新的file目录
[root@localhost file(keystone_admin)]# swift download test file/123.txt ab^C
[root@localhost file(keystone_admin)]#
[root@localhost file(keystone_admin)]#
[root@localhost file(keystone_admin)]# ls
file
[root@localhost file(keystone_admin)]# cd file/
[root@localhost file(keystone_admin)]# ls
123.txt
回到根下就没问题
[root@localhost file(keystone_admin)]#cd
[root@localhost ~(keystone_admin)]# swift download test file/abc.txt
file/abc.txt [auth 0.380s, headers 0.708s, total 0.709s, 0.000 MB/s]
[root@localhost ~(keystone_admin)]# cd file/
[root@localhost file(keystone_admin)]# ls
abc.txt file
查询容器的详细信息
[root@localhost ~(keystone_admin)]# swift list test
file/123.txt
file/abc.txt
[root@localhost ~(keystone_admin)]#
查询容器状态
[root@localhost ~(keystone_admin)]# swift stat
Account: AUTH_009a94428fb84a0db16aa4a1adab9a35
Containers: 1
Objects: 2
Bytes: 0
Containers in policy "policy-0": 1
Objects in policy "policy-0": 2
Bytes in policy "policy-0": 0
X-Account-Project-Domain-Id: default
X-Openstack-Request-Id: tx9ec33c67654f4baf8ee53-0065fd4741
X-Timestamp: 1711096408.84856
X-Trans-Id: tx9ec33c67654f4baf8ee53-0065fd4741
Content-Type: application/json; charset=utf-8
Accept-Ranges: bytes
[root@localhost ~(keystone_admin)]#
从容器中删除文件
[root@localhost ~(keystone_admin)]# swift delete test file/123.txt
file/123.txt
[root@localhost ~(keystone_admin)]# swift delete test file/abc.txt
file/abc.txt
[root@localhost ~(keystone_admin)]# swift list test
[root@localhost ~(keystone_admin)]#
删除创建的容器
[root@localhost ~(keystone_admin)]# swift delete test
test
[root@localhost ~(keystone_admin)]# swift list
[root@localhost ~(keystone_admin)]#
openstack 命令执行创建容器、删除容器
[root@localhost ~(keystone_admin)]# openstack container create my
+---------------------------------------+-----------+------------------------------------+
| account | container | x-trans-id |
+---------------------------------------+-----------+------------------------------------+
| AUTH_009a94428fb84a0db16aa4a1adab9a35 | my | tx21cb60c481944b8b996af-0065fd4912 |
+---------------------------------------+-----------+------------------------------------+
[root@localhost ~(keystone_admin)]# swift list
my
[root@localhost ~(keystone_admin)]#
[root@localhost ~(keystone_admin)]# openstack container delete my //删除
[root@localhost ~(keystone_admin)]# openstack container list
[root@localhost ~(keystone_admin)]#
以上就是基础命令啦!