openstack cinder、swift运维命令

简介: Cinder是OpenStack的块存储服务,提供虚拟机块设备功能,包括卷的创建、挂载等。它由cinder-api、cinder-scheduler和cinder-volume三个组件构成,前者处理请求,中间者负责调度,后者执行卷管理。Swift是OpenStack的分布式对象存储服务,高可用、持久性,适用于大文件存储。Swift架构对称,无单点故障,提供类似文件系统的简单逻辑和高效读写。Cinder关注虚拟机层面的块存储,而Swift则提供对象存储服务。命令示例展示了如何使用cinder和openstack命令操作云硬盘和Swift容器。

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)]#

以上就是基础命令啦!

目录
相关文章
|
4月前
|
存储 Swift 对象存储
OpenStack的对象存储(Swift)
【8月更文挑战第24天】
181 1
|
2月前
|
运维 监控 网络协议
|
20天前
|
缓存 运维 监控
【运维必备知识】Linux系统平均负载与top、uptime命令详解
系统平均负载是衡量Linux服务器性能的关键指标之一。通过使用 `top`和 `uptime`命令,可以实时监控系统的负载情况,帮助运维人员及时发现并解决潜在问题。理解这些工具的输出和意义是确保系统稳定运行的基础。希望本文对Linux系统平均负载及相关命令的详细解析能帮助您更好地进行系统运维和性能优化。
43 3
|
3月前
|
存储 消息中间件 算法
深入解析OpenStack Cinder:块存储服务详解
本文介绍了OpenStack及其块存储服务Cinder。OpenStack是一个开源云计算管理平台,提供基础设施即服务(IaaS),核心服务包括计算、网络、存储等。Cinder主要用于为虚拟机提供持久性块存储,具备多种功能,如卷操作、备份、快照及与实例的交互等。此外,还详细介绍了Cinder的工作流程、命令行操作及不同存储插件的使用。
480 8
|
4月前
|
图形学 开发者 存储
超越基础教程:深度拆解Unity地形编辑器的每一个隐藏角落,让你的游戏世界既浩瀚无垠又细节满满——从新手到高手的全面技巧升级秘籍
【8月更文挑战第31天】Unity地形编辑器是游戏开发中的重要工具,可快速创建复杂多变的游戏环境。本文通过比较不同地形编辑技术,详细介绍如何利用其功能构建广阔且精细的游戏世界,并提供具体示例代码,展示从基础地形绘制到植被与纹理添加的全过程。通过学习这些技巧,开发者能显著提升游戏画面质量和玩家体验。
165 3
|
4月前
|
存储 固态存储 网络性能优化
OpenStack的块存储(Cinder)
【8月更文挑战第24天】
127 2
|
4月前
|
SQL 运维 监控
DM日常运维高频命令总结
DM日常运维高频命令总结
104 3
|
4月前
|
运维 Oracle 前端开发
Oracle 11g RAC集群日常运维命令总结
Oracle 11g RAC集群日常运维命令总结
99 2
|
4月前
|
SQL 运维 调度
DM8日常运维命令总结(二)
DM8日常运维命令总结(二)
101 2
|
4月前
|
SQL 运维 Oracle
入门级Oracle 11g日常运维命令总结
入门级Oracle 11g日常运维命令总结
130 1