OpenStack组件的基本使用

news2025/1/21 15:36:55

OpenStack组件的基本使用

  • Keystone
    • 命令行的方式
      • 项目
      • 用户
      • 角色
    • 图形化界面方式
      • 项目
      • 用户
      • 角色
  • Glance
    • 命令行操作
      • 镜像上传下载
      • 管理镜像
      • 开放镜像权限
      • 转换镜像格式
    • 图形化界面
  • Nova和Neutron
    • 命令行的方式
      • 实例类型
      • 密钥对
      • 安全组
      • 创建网络
      • 创建云主机
      • 启动关闭云主机
    • 图形化界面
      • 创建实例类型
      • 创建网络
      • 创建密钥对
      • 添加安全组规则
      • 创建云主机
  • Cinder
    • 命令行操作
      • 创建块存储
      • 挂载块存储
      • 扩展块存储
      • 删除块存储
  • Swift
    • 命令行操作
      • 创建容器
      • 创建对象
      • 下载对象
      • 删除对象
      • 删除容器
      • 分片存储案例

Keystone

用户(user)可以同时属于一个或多个项目,角色(role)定义了用户可以执行的操作类型。

openstack项目中的各个服务组件可以执行的操作可以在/etc/xxxxx/policy.json 文件中进行定义。例如,Nova计算服务组件可执行操作列表在 /etc/nova/policy.json文件中定义。keystone服务则在/etc/keystone/policy.json中定义

在进行删除用户操作时,首先将用户和项目的映射删除。

命令行的方式

项目

(1)展示列表中所有的项目

[root@controller ~]# openstack project list
+----------------------------------+-----------+
| ID                               | Name      |
+----------------------------------+-----------+
| 0769b940829c4078a4aa573e83d6520c | admin     |
| 60882db373c2495eb7498a06b9443360 | service   |
| 98b082ffdddb4361ab983ea3cfcd6094 | demo      |
| a14ec47b15344fbd8247e933d973efcc | myproject |
+----------------------------------+-----------+

(2)创建项目

[root@controller ~]# openstack project create  --description 'default project' csq1
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | default project                  |
| domain_id   | default                          |
| enabled     | True                             |
| id          | 378813957fca4a25a74d856bab219e48 |
| is_domain   | False                            |
| name        | csq1                             |
| options     | {}                               |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+

(3)更新项目

①禁用租户

禁用刚刚创建的csq1项目

[root@controller ~]# openstack project set 378813957fca4a25a74d856bab219e48 --disable

②启用被禁用的项目

[root@controller ~]# openstack project set 378813957fca4a25a74d856bab219e48 --enable

③更改项目名称

[root@controller ~]# openstack project set 378813957fca4a25a74d856bab219e48 --name zhw1
[root@controller ~]# openstack project list |grep zhw1 |cut -d '|' -f 3
 zhw1   

④确认已修改信息

[root@controller ~]# openstack project show 378813957fca4a25a74d856bab219e48
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | default project                  |
| domain_id   | default                          |
| enabled     | True                             |
| id          | 378813957fca4a25a74d856bab219e48 |
| is_domain   | False                            |
| name        | zhw1                             |
| options     | {}                               |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+

(4)删除项目

[root@controller ~]# openstack project delete zhw1

用户

(5)展示列表中的所有用户

[root@controller ~]# openstack user list
+----------------------------------+-------------------+
| ID                               | Name              |
+----------------------------------+-------------------+
| fef5f8c16d3d4b9d849bc1488bf50a21 | admin             |
| 5bf6341f28174502abc213ce093d4376 | myuser            |
| 28863c4ea60b43a6aa07b4388bf5417b | glance            |
| dd0b68b6602a4c2d808d9e876574d12a | placement         |
| 003a122553b44827968d8b0f07c91434 | nova              |
| 65a61b0b295b428f934b809e73a36cd0 | neutron           |
| 604f6fa1e4714c348f7d90f134065757 | cinder            |
| d29d82ce57524c9c88c61a60da3d6cae | swift             |
| acd845361d32470f888ec98a33bcd176 | heat              |
| ddacc6ca064a462690f84a439bfcc06a | heat_domain_admin |
| 941d4f91bf144a358c46bd338eb53ef7 | demo              |
| 2d6b2600158e430e8fdaaaab332e6203 | manila            |
| 7d982c41976147c6a0b0d8339c408acd | barbican          |
| 6372f45b6f074a2490de88dcf3d5f5e0 | cloudkitty        |
+----------------------------------+-------------------+

(6)创建用户

在创建用户时,必须指定用户名称。可选项包括租户ID和密码,建议在创建用户时指定可选信息,否则用户无法通过dashboard登录

[root@controller ~]# openstack user create --domain default --password-prompt csq1
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | c4157e5599114d05a0f8460deafd39e1 |
| name                | csq1                             |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
# 当然你也可以选择 --password <密码>  这种方式

(7)更新用户

①禁用用户

[root@controller ~]# openstack user set c4157e5599114d05a0f8460deafd39e1 --disable

②启用被禁用的用户

[root@controller ~]# openstack user set c4157e5599114d05a0f8460deafd39e1 --enable

③更新用户名称

[root@controller ~]# openstack user set c4157e5599114d05a0f8460deafd39e1 --name zhw1
[root@controller ~]# openstack user list |grep zhw |cut -d "|" -f 3
 zhw1          

(8)删除用户

[root@controller ~]# openstack user delete zhw1

角色

(9)展示列表中的所有角色

[root@controller ~]# openstack role list
+----------------------------------+------------------+
| ID                               | Name             |
+----------------------------------+------------------+
| 11904104fea14c029d7db85a25ccc8c0 | heat_stack_user  |
| 1550dde96f9944eab4d872376a2becae | heat_stack_owner |
| 4255cb58a4eb459e843c408bbd92dee8 | myrole           |
| 70c96642c6d74c4ab8847f6b2bd7cb1b | creator          |
| 7d1e5d969f7e427ca70ffc4decb0b393 | admin            |
| 8487e7321922440793dc4c262f575081 | member           |
| b41d4562a3bf43138cbf1d575cfda382 | reader           |
+----------------------------------+------------------+

(10)创建角色

[root@controller ~]# openstack role create csq1
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | None                             |
| domain_id   | None                             |
| id          | 1f83b2300bec43029ec9b1270e2da164 |
| name        | csq1                             |
| options     | {}                               |
+-------------+----------------------------------+

(11)分配角色

①列出所有项目和用户并挑选所需赋予角色的用户

[root@controller ~]# openstack project list 
+----------------------------------+-----------+
| ID                               | Name      |
+----------------------------------+-----------+
| 0769b940829c4078a4aa573e83d6520c | admin     |
| 60882db373c2495eb7498a06b9443360 | service   |
| 98b082ffdddb4361ab983ea3cfcd6094 | demo      |
| a14ec47b15344fbd8247e933d973efcc | myproject |
+----------------------------------+-----------+
[root@controller ~]# openstack user list
+----------------------------------+-------------------+
| ID                               | Name              |
+----------------------------------+-------------------+
| fef5f8c16d3d4b9d849bc1488bf50a21 | admin             |
| 5bf6341f28174502abc213ce093d4376 | myuser            |
| 28863c4ea60b43a6aa07b4388bf5417b | glance            |
| dd0b68b6602a4c2d808d9e876574d12a | placement         |
| 003a122553b44827968d8b0f07c91434 | nova              |
| 65a61b0b295b428f934b809e73a36cd0 | neutron           |
| 604f6fa1e4714c348f7d90f134065757 | cinder            |
| d29d82ce57524c9c88c61a60da3d6cae | swift             |
| acd845361d32470f888ec98a33bcd176 | heat              |
| ddacc6ca064a462690f84a439bfcc06a | heat_domain_admin |
| 941d4f91bf144a358c46bd338eb53ef7 | demo              |
| 2d6b2600158e430e8fdaaaab332e6203 | manila            |
| 7d982c41976147c6a0b0d8339c408acd | barbican          |
| 6372f45b6f074a2490de88dcf3d5f5e0 | cloudkitty        |
+----------------------------------+-------------------+

②列出所有角色并挑选所需使用的角色

[root@controller ~]# openstack role list
+----------------------------------+------------------+
| ID                               | Name             |
+----------------------------------+------------------+
| 11904104fea14c029d7db85a25ccc8c0 | heat_stack_user  |
| 1550dde96f9944eab4d872376a2becae | heat_stack_owner |
| 1f83b2300bec43029ec9b1270e2da164 | csq1             |
| 4255cb58a4eb459e843c408bbd92dee8 | myrole           |
| 70c96642c6d74c4ab8847f6b2bd7cb1b | creator          |
| 7d1e5d969f7e427ca70ffc4decb0b393 | admin            |
| 8487e7321922440793dc4c262f575081 | member           |
| b41d4562a3bf43138cbf1d575cfda382 | reader           |
+----------------------------------+------------------+

③将角色赋予用户和项目

[root@controller ~]# openstack role add --user admin --project admin csq1

(12)移除赋予角色的用户和项目

[root@controller ~]# openstack role remove --user admin --project admin csq1

(13)删除角色

[root@controller ~]# openstack role delete csq1

图形化界面方式

项目

首先登录OpenStack Web界面

(1)创建项目

image-20230703110122512

image-20230703122626186

image-20230703122721177

image-20230703122851544

(2)管理成员

当你想要修改项目成员或者项目组以及项目名称等等信息,可以在里面设置

image-20230703122940642

(3)删除项目

image-20230703123256006

用户

(1)创建用户

image-20230703124229916

image-20230703124357728

image-20230703124923307

(2)更改用户信息

点编辑即可 更改用户信息

image-20230703125010380

如果想修改密码可点旁边的倒三角

角色

角色是拥有权限的集合,定义用户可以执行的一系列操作

(1)创建角色

image-20230703104222877

image-20230703104319038

image-20230703104406356

(2)编辑角色

image-20230703104503802

image-20230703104538294

image-20230703104602297

(3)删除角色

image-20230703104745894

Glance

命令行操作

在镜像管理之前你需要先准备一个镜像文件

镜像上传下载

上传镜像

上传镜像镜像名字为 cirros

[root@controller ~]# openstack image create --disk-format qcow2 --container-format bare --file image/cirros-0.3.4-x86_64-disk.img cirros
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2023-07-03T05:05:18Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/23ba495a-ee86-4570-a7bb-4c1eac9c742b/file                                                                                                                                       |
| id               | 23ba495a-ee86-4570-a7bb-4c1eac9c742b                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | cirros                                                                                                                                                                                     |
| owner            | 0769b940829c4078a4aa573e83d6520c                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='1b03ca1bc3fafe448b90583c12f367949f8b0e665685979d95b004e48574b953316799e23240f4f739d1b5eb4c4ca24d38fdc6f4f9d8247a2bc64db25d6bbdb2', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 13287936                                                                                                                                                                                   |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2023-07-03T05:05:19Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | shared                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

–disk-format:镜像格式

–container-format:镜像在其他项目中可见性

–file:选择本地镜像文件

镜像下载

–file 指定下载到哪个目录什么文件名

[root@controller ~]# openstack image save --file /opt/my-image.qcow2 cirros
[root@controller ~]# ls /opt/
my-image.qcow2

管理镜像

(1)查看镜像

[root@controller ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 23ba495a-ee86-4570-a7bb-4c1eac9c742b | cirros | active |
+--------------------------------------+--------+--------+

(2)查看镜像详细信息

[root@controller ~]# openstack image show 23ba495a-ee86-4570-a7bb-4c1eac9c742b
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2023-07-03T05:05:18Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/23ba495a-ee86-4570-a7bb-4c1eac9c742b/file                                                                                                                                       |
| id               | 23ba495a-ee86-4570-a7bb-4c1eac9c742b                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | cirros                                                                                                                                                                                     |
| owner            | 0769b940829c4078a4aa573e83d6520c                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='1b03ca1bc3fafe448b90583c12f367949f8b0e665685979d95b004e48574b953316799e23240f4f739d1b5eb4c4ca24d38fdc6f4f9d8247a2bc64db25d6bbdb2', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 13287936                                                                                                                                                                                   |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2023-07-03T05:05:19Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | shared                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

(3)修改镜像

参数说明:

–min-disk:镜像启动最小硬盘大小

–name:镜像名称

–disk-format:镜像格式。

–min-ram:镜像启动最小内存大小

–container-format:镜像在项目中可见性

[root@controller ~]# openstack image set --min-disk 10 --min-ram 1024  cirros

(4)删除镜像

[root@controller ~]# openstack image delete cirros
[root@controller ~]# openstack image list

开放镜像权限

[root@controller ~]# openstack project create --domain default csqA
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description |                                  |
| domain_id   | default                          |
| enabled     | True                             |
| id          | 34585d2439934ebd8b1b9c2e6110667e |
| is_domain   | False                            |
| name        | csqA                             |
| options     | {}                               |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+
[root@controller ~]# openstack project create --domain default csqB
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description |                                  |
| domain_id   | default                          |
| enabled     | True                             |
| id          | faa83f0d3d0c42a19773c05fe2043adf |
| is_domain   | False                            |
| name        | csqB                             |
| options     | {}                               |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+
[root@controller ~]# openstack user create --domain default --password 000000 csq-userA
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | de01f40d307d41fe9a828a9694fb6c79 |
| name                | csq-userA                        |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
[root@controller ~]# openstack user create --domain default --password 000000 csq-userB
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 4c5478b9d7d84dd3879d410acc833f57 |
| name                | csq-userB                        |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
[root@controller ~]# openstack role add --project csqA --user csq-userA user
[root@controller ~]# openstack role add --project csqB --user csq-userB user
[root@controller ~]# openstack image create --disk-format qcow2 --container-format bare --file image/cirros-0.3.4-x86_64-disk.img cirros1
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2023-07-03T13:24:22Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/b272c8ef-14b8-4d64-9449-84b2f5313cdd/file                                                                                                                                       |
| id               | b272c8ef-14b8-4d64-9449-84b2f5313cdd                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | cirros1                                                                                                                                                                                    |
| owner            | 0769b940829c4078a4aa573e83d6520c                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='1b03ca1bc3fafe448b90583c12f367949f8b0e665685979d95b004e48574b953316799e23240f4f739d1b5eb4c4ca24d38fdc6f4f9d8247a2bc64db25d6bbdb2', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 13287936                                                                                                                                                                                   |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2023-07-03T13:24:23Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | shared                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

[root@controller ~]# glance member-create  b272c8ef-14b8-4d64-9449-84b2f5313cdd 34585d2439934ebd8b1b9c2e6110667e
+--------------------------------------+----------------------------------+---------+
| Image ID                             | Member ID                        | Status  |
+--------------------------------------+----------------------------------+---------+
| b272c8ef-14b8-4d64-9449-84b2f5313cdd | 34585d2439934ebd8b1b9c2e6110667e | pending |
+--------------------------------------+----------------------------------+---------+

[root@controller ~]# glance member-update  b272c8ef-14b8-4d64-9449-84b2f5313cdd 34585d2439934ebd8b1b9c2e6110667e accepted
+--------------------------------------+----------------------------------+----------+
| Image ID                             | Member ID                        | Status   |
+--------------------------------------+----------------------------------+----------+
| b272c8ef-14b8-4d64-9449-84b2f5313cdd | 34585d2439934ebd8b1b9c2e6110667e | accepted |
+--------------------------------------+----------------------------------+----------+
# 测试 切换到 csqB用户后查看镜像
[root@controller ~]# export OS_PROJECT_NAME=csqB
[root@controller ~]# export OS_USERNAME=csq-userB
[root@controller ~]# export OS_PASSWORD=000000
[root@controller ~]# glance image list
+----+------+
| ID | Name |
+----+------+
+----+------+
# 测试切换到 csqA用户后查看信息
[root@controller ~]# export OS_PROJECT_NAME=csqA
[root@controller ~]# export OS_USERNAME=csq-userA
[root@controller ~]# export OS_PASSWORD=000000
[root@controller ~]# glance image-list
+--------------------------------------+---------+
| ID                                   | Name    |
+--------------------------------------+---------+
| b272c8ef-14b8-4d64-9449-84b2f5313cdd | cirros1 |
+--------------------------------------+---------+

转换镜像格式

# 首先准备一个镜像
[root@controller ~]# ls
 bionic-server-cloudimg-amd64.vmdk 
# 查看镜像文件信息
[root@controller ~]# qemu-img info  bionic-server-cloudimg-amd64.vmdk 
image: bionic-server-cloudimg-amd64.vmdk
file format: vmdk
virtual size: 10G (10737418240 bytes)
disk size: 370M
cluster_size: 65536
Format specific information:
    cid: 2119925927
    parent cid: 4294967295
    create type: streamOptimized
    extents:
        [0]:
            compressed: true
            virtual size: 10737418240
            filename: bionic-server-cloudimg-amd64.vmdk
            cluster size: 65536
            format:          

执行以下命令将镜像从vmdk转化为qcow2

[root@controller ~]# qemu-img convert -f vmdk -O qcow2 -c -p bionic-server-cloudimg-amd64.vmdk bionic-server-cloudimg-amd64.qcow2
  • -f 指定输入磁盘的镜像格式
  • -O 指定输出格式
  • -c 目标只能被压缩成QCOW2格式
  • -p 显示转换进度

等镜像格式转化呢完成后查看你信息

[root@controller ~]# qemu-img info bionic-server-cloudimg-amd64.qcow2 
image: bionic-server-cloudimg-amd64.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 387M
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

创建镜像

[root@controller ~]# openstack image create --disk-format qcow2 --container-format bare \
> --min-disk 10 \
> --min-ram 1024 \
> --file bionic-server-cloudimg-amd64.qcow2 \
> Ubuntu-image
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | 8d2427ce42ef65aaf912475c37026cd5                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2023-07-03T14:35:47Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/58fe3551-b653-4d6c-aa27-db514470b96c/file                                                                                                                                       |
| id               | 58fe3551-b653-4d6c-aa27-db514470b96c                                                                                                                                                       |
| min_disk         | 10                                                                                                                                                                                         |
| min_ram          | 1024                                                                                                                                                                                       |
| name             | Ubuntu-image                                                                                                                                                                               |
| owner            | 05a47fe36758427785540085776c6e36                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='49f0f07ff1f4f14257d8080c91f7ca8de1eff359c9be472c3974eefae9d0141bdac48bbf6228c753d96bd1e283b7c9bcef7f5fb4d8d82f987f7147b92d27a4d8', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 405667840                                                                                                                                                                                  |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2023-07-03T14:35:52Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | shared                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@controller ~]# openstack image list
+--------------------------------------+--------------+--------+
| ID                                   | Name         | Status |
+--------------------------------------+--------------+--------+
| 58fe3551-b653-4d6c-aa27-db514470b96c | Ubuntu-image | active |
| 0ee90422-2c4a-4da1-a162-2e315cddbcd1 | cirros       | active |
+--------------------------------------+--------------+--------+

图形化界面

创建镜像

image-20230703215345655

image-20230703215530963

image-20230703215659824

image-20230703215810030

Nova和Neutron

命令行的方式

实例类型

(1)创建flavor类型

[root@controller ~]# openstack flavor create  --disk 20 --ram 3096 --vcpus 3 --id 777 flavor2
+----------------------------+---------+
| Field                      | Value   |
+----------------------------+---------+
| OS-FLV-DISABLED:disabled   | False   |
| OS-FLV-EXT-DATA:ephemeral  | 0       |
| disk                       | 20      |
| id                         | 777     |
| name                       | flavor2 |
| os-flavor-access:is_public | True    |
| properties                 |         |
| ram                        | 3096    |
| rxtx_factor                | 1.0     |
| swap                       |         |
| vcpus                      | 3       |
+----------------------------+---------+

(2)查看flavor类型

[root@controller ~]# openstack flavor list
+-----+---------+------+------+-----------+-------+-----------+
| ID  | Name    |  RAM | Disk | Ephemeral | VCPUs | Is Public |
+-----+---------+------+------+-----------+-------+-----------+
| 0   | m1.nano |   64 |    1 |         0 |     1 | True      |
| 777 | flavor2 | 3096 |   20 |         0 |     3 | True      |
+-----+---------+------+------+-----------+-------+-----------+

(3)查看flavor具体信息

[root@controller ~]# openstack flavor show flavor2
+----------------------------+---------+
| Field                      | Value   |
+----------------------------+---------+
| OS-FLV-DISABLED:disabled   | False   |
| OS-FLV-EXT-DATA:ephemeral  | 0       |
| access_project_ids         | None    |
| disk                       | 20      |
| id                         | 777     |
| name                       | flavor2 |
| os-flavor-access:is_public | True    |
| properties                 |         |
| ram                        | 3096    |
| rxtx_factor                | 1.0     |
| swap                       |         |
| vcpus                      | 3       |
+----------------------------+---------+

(4)删除flavor类型

[root@controller ~]# openstack flavor delete <flavor name>

密钥对

创建密钥对mykey2

[root@controller ~]# ssh-keygen -q -N ""
[root@controller ~]# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey2
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| fingerprint | 4e:89:e8:78:70:1e:82:4a:b8:65:87:1e:21:6a:83:25 |
| name        | mykey2                                          |
| user_id     | fef5f8c16d3d4b9d849bc1488bf50a21                |
+-------------+-------------------------------------------------+

安全组

(1)查看安全组

[root@controller ~]# openstack security group list

(2)创建安全组

[root@controller ~]# openstack security group create myanquanzu
+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field           | Value                                                                                                                                                   |
+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| created_at      | 2023-07-03T15:29:20Z                                                                                                                                    |
| description     | myanquanzu                                                                                                                                              |
| id              | 5b76d5ae-c8b2-4f44-8da2-0dc2a1626b25                                                                                                                    |
| location        | cloud='', project.domain_id=, project.domain_name='Default', project.id='0769b940829c4078a4aa573e83d6520c', project.name='admin', region_name='', zone= |
| name            | myanquanzu                                                                                                                                              |
| project_id      | 0769b940829c4078a4aa573e83d6520c                                                                                                                        |
| revision_number | 1                                                                                                                                                       |
| rules           | created_at='2023-07-03T15:29:20Z', direction='egress', ethertype='IPv4', id='c498e8d8-8fda-4739-86da-aad0e03889d9', updated_at='2023-07-03T15:29:20Z'   |
|                 | created_at='2023-07-03T15:29:20Z', direction='egress', ethertype='IPv6', id='cf3f3224-71c7-4831-b5bf-cc56e466e3b2', updated_at='2023-07-03T15:29:20Z'   |
| tags            | []                                                                                                                                                      |
| updated_at      | 2023-07-03T15:29:20Z                                                                                                                                    |
+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+

(3)删除安全组

[root@controller ~]# openstack security group delete myanquanzu

(4)添加安全规则

在myanquanzu安全组中添加一条策略,从入口方向放行所有ICMP规则,命令如下

[root@controller ~]# openstack security group rule create --protocol icmp --ingress myanquanzu
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field             | Value                                                                                                                                                   |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| created_at        | 2023-07-03T15:31:10Z                                                                                                                                    |
| description       |                                                                                                                                                         |
| direction         | ingress                                                                                                                                                 |
| ether_type        | IPv4                                                                                                                                                    |
| id                | de5748eb-770b-4fe5-86f9-24b34271ac76                                                                                                                    |
| location          | cloud='', project.domain_id=, project.domain_name='Default', project.id='0769b940829c4078a4aa573e83d6520c', project.name='admin', region_name='', zone= |
| name              | None                                                                                                                                                    |
| port_range_max    | None                                                                                                                                                    |
| port_range_min    | None                                                                                                                                                    |
| project_id        | 0769b940829c4078a4aa573e83d6520c                                                                                                                        |
| protocol          | icmp                                                                                                                                                    |
| remote_group_id   | None                                                                                                                                                    |
| remote_ip_prefix  | 0.0.0.0/0                                                                                                                                               |
| revision_number   | 0                                                                                                                                                       |
| security_group_id | 849923e9-2eed-42b5-8eee-fa0f1b855026                                                                                                                    |
| tags              | []                                                                                                                                                      |
| updated_at        | 2023-07-03T15:31:10Z                                                                                                                                    |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+

在myanquanzu安全组中添加一条策略,从入口方向放行所有TCP规则,命令如下

[root@controller ~]# openstack security group rule create --protocol tcp --ingress  myanquanzu
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field             | Value                                                                                                                                                   |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| created_at        | 2023-07-03T15:32:14Z                                                                                                                                    |
| description       |                                                                                                                                                         |
| direction         | ingress                                                                                                                                                 |
| ether_type        | IPv4                                                                                                                                                    |
| id                | 9dfedfbd-3328-4340-abc0-04f3b64367ec                                                                                                                    |
| location          | cloud='', project.domain_id=, project.domain_name='Default', project.id='0769b940829c4078a4aa573e83d6520c', project.name='admin', region_name='', zone= |
| name              | None                                                                                                                                                    |
| port_range_max    | None                                                                                                                                                    |
| port_range_min    | None                                                                                                                                                    |
| project_id        | 0769b940829c4078a4aa573e83d6520c                                                                                                                        |
| protocol          | tcp                                                                                                                                                     |
| remote_group_id   | None                                                                                                                                                    |
| remote_ip_prefix  | 0.0.0.0/0                                                                                                                                               |
| revision_number   | 0                                                                                                                                                       |
| security_group_id | 849923e9-2eed-42b5-8eee-fa0f1b855026                                                                                                                    |
| tags              | []                                                                                                                                                      |
| updated_at        | 2023-07-03T15:32:14Z                                                                                                                                    |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+

在myanquanzu安全组中添加一条策略,从入口方向放行所有UDP规则,命令如下

[root@controller ~]# openstack security group rule create --protocol udp --ingress  myanquanzu
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field             | Value                                                                                                                                                   |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| created_at        | 2023-07-03T15:33:09Z                                                                                                                                    |
| description       |                                                                                                                                                         |
| direction         | ingress                                                                                                                                                 |
| ether_type        | IPv4                                                                                                                                                    |
| id                | 928c3bca-ea8c-4d50-9919-432f03b90a92                                                                                                                    |
| location          | cloud='', project.domain_id=, project.domain_name='Default', project.id='0769b940829c4078a4aa573e83d6520c', project.name='admin', region_name='', zone= |
| name              | None                                                                                                                                                    |
| port_range_max    | None                                                                                                                                                    |
| port_range_min    | None                                                                                                                                                    |
| project_id        | 0769b940829c4078a4aa573e83d6520c                                                                                                                        |
| protocol          | udp                                                                                                                                                     |
| remote_group_id   | None                                                                                                                                                    |
| remote_ip_prefix  | 0.0.0.0/0                                                                                                                                               |
| revision_number   | 0                                                                                                                                                       |
| security_group_id | 849923e9-2eed-42b5-8eee-fa0f1b855026                                                                                                                    |
| tags              | []                                                                                                                                                      |
| updated_at        | 2023-07-03T15:33:09Z                                                                                                                                    |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+

查看myanquanzu安全组中所有的规则列表信息,命令如下

[root@controller ~]# openstack security group rule list myanquanzu
+--------------------------------------+-------------+-----------+-----------+------------+-----------------------+
| ID                                   | IP Protocol | Ethertype | IP Range  | Port Range | Remote Security Group |
+--------------------------------------+-------------+-----------+-----------+------------+-----------------------+
| 1435f001-94fa-4d29-ad0f-626cff27feef | None        | IPv6      | ::/0      |            | None                  |
| 928c3bca-ea8c-4d50-9919-432f03b90a92 | udp         | IPv4      | 0.0.0.0/0 |            | None                  |
| 9b34ccb6-ab3e-4dbf-bc8a-da901066755f | None        | IPv4      | 0.0.0.0/0 |            | None                  |
| 9dfedfbd-3328-4340-abc0-04f3b64367ec | tcp         | IPv4      | 0.0.0.0/0 |            | None                  |
| de5748eb-770b-4fe5-86f9-24b34271ac76 | icmp        | IPv4      | 0.0.0.0/0 |            | None                  |
+--------------------------------------+-------------+-----------+-----------+------------+-----------------------+

创建网络

创建网络

[root@controller ~]# openstack network create  --share --external   --provider-physical-network provider  --provider-network-type flat net-flat
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field                     | Value                                                                                                                                                   |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| admin_state_up            | UP                                                                                                                                                      |
| availability_zone_hints   |                                                                                                                                                         |
| availability_zones        |                                                                                                                                                         |
| created_at                | 2023-07-03T15:39:27Z                                                                                                                                    |
| description               |                                                                                                                                                         |
| dns_domain                | None                                                                                                                                                    |
| id                        | cfd04a6d-47c0-4144-b3a1-537179d037c8                                                                                                                    |
| ipv4_address_scope        | None                                                                                                                                                    |
| ipv6_address_scope        | None                                                                                                                                                    |
| is_default                | None                                                                                                                                                    |
| is_vlan_transparent       | None                                                                                                                                                    |
| location                  | cloud='', project.domain_id=, project.domain_name='Default', project.id='0769b940829c4078a4aa573e83d6520c', project.name='admin', region_name='', zone= |
| mtu                       | 1500                                                                                                                                                    |
| name                      | net-flat                                                                                                                                                |
| port_security_enabled     | True                                                                                                                                                    |
| project_id                | 0769b940829c4078a4aa573e83d6520c                                                                                                                        |
| provider:network_type     | flat                                                                                                                                                    |
| provider:physical_network | provider                                                                                                                                                |
| provider:segmentation_id  | None                                                                                                                                                    |
| qos_policy_id             | None                                                                                                                                                    |
| revision_number           | 1                                                                                                                                                       |
| router:external           | External                                                                                                                                                |
| segments                  | None                                                                                                                                                    |
| shared                    | True                                                                                                                                                    |
| status                    | ACTIVE                                                                                                                                                  |
| subnets                   |                                                                                                                                                         |
| tags                      |                                                                                                                                                         |
| updated_at                | 2023-07-03T15:39:27Z                                                                                                                                    |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+

  • --share:表示这个网络是共享的,其他项目也可以使用该网络
  • --external:表示这个网络是外部网络,即连接到外部物理网络的网络
  • --provider-physical-network provider:指定了物理网络的名称为 “provider”,这是为了将该网络连接到特定的物理网络。
  • --provider-network-type flat:指定了网络类型为 “flat”
  • net-flat:指定了网络的名称为 “net-flat”

创建子网

[root@controller ~]# openstack subnet create --network net-flat  --allocation-pool start=192.168.200.50,end=192.168.200.100  --dns-nameserver 114.114.114.114 --gateway 192.168.200.2  --subnet-range 192.168.200.0/24 net-sub
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field             | Value                                                                                                                                                   |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| allocation_pools  | 192.168.200.50-192.168.200.100                                                                                                                          |
| cidr              | 192.168.200.0/24                                                                                                                                        |
| created_at        | 2023-07-03T15:40:51Z                                                                                                                                    |
| description       |                                                                                                                                                         |
| dns_nameservers   | 114.114.114.114                                                                                                                                         |
| enable_dhcp       | True                                                                                                                                                    |
| gateway_ip        | 192.168.200.2                                                                                                                                           |
| host_routes       |                                                                                                                                                         |
| id                | ea9230c9-128f-42fd-affa-42a53a995622                                                                                                                    |
| ip_version        | 4                                                                                                                                                       |
| ipv6_address_mode | None                                                                                                                                                    |
| ipv6_ra_mode      | None                                                                                                                                                    |
| location          | cloud='', project.domain_id=, project.domain_name='Default', project.id='0769b940829c4078a4aa573e83d6520c', project.name='admin', region_name='', zone= |
| name              | net-sub                                                                                                                                                 |
| network_id        | cfd04a6d-47c0-4144-b3a1-537179d037c8                                                                                                                    |
| prefix_length     | None                                                                                                                                                    |
| project_id        | 0769b940829c4078a4aa573e83d6520c                                                                                                                        |
| revision_number   | 0                                                                                                                                                       |
| segment_id        | None                                                                                                                                                    |
| service_types     |                                                                                                                                                         |
| subnetpool_id     | None                                                                                                                                                    |
| tags              |                                                                                                                                                         |
| updated_at        | 2023-07-03T15:40:51Z                                                                                                                                    |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  • --network net-flat:指定了要在名为 net-flat"的网络中创建子网
  • --allocation-pool start=192.168.200.50,end=192.168.200.100:指定了分配 IP 地址的范围,从 192.168.200.50 到 192.168.200.100
  • --dns-nameserver 114.114.114.114:指定了 DNS 服务器的 IP 地址为 114.114.114.114
  • --gateway 192.168.200.2:指定了子网的网关 IP 地址为 192.168.200.2
  • --subnet-range 192.168.200.0/24:指定了子网的 IP 地址范围为 192.168.200.0 到 192.168.200.255,使用 /24 表示子网掩码是 255.255.255.0
  • net-sub:指定了子网的名称为 net-sub

创建云主机

# 创建云主机
[root@controller ~]# openstack server create --flavor 777 --image Ubuntu-image  --nic net-id=cfd04a6d-47c0-4144-b3a1-537179d037c8 --security-group myanquanzu  --key-name mykey2 myserver
+-------------------------------------+-----------------------------------------------------+
| Field                               | Value                                               |
+-------------------------------------+-----------------------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                                              |
| OS-EXT-AZ:availability_zone         |                                                     |
| OS-EXT-SRV-ATTR:host                | None                                                |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                                |
| OS-EXT-SRV-ATTR:instance_name       |                                                     |
| OS-EXT-STS:power_state              | NOSTATE                                             |
| OS-EXT-STS:task_state               | scheduling                                          |
| OS-EXT-STS:vm_state                 | building                                            |
| OS-SRV-USG:launched_at              | None                                                |
| OS-SRV-USG:terminated_at            | None                                                |
| accessIPv4                          |                                                     |
| accessIPv6                          |                                                     |
| addresses                           |                                                     |
| adminPass                           | RVJeZLYfn4mi                                        |
| config_drive                        |                                                     |
| created                             | 2023-07-03T15:56:44Z                                |
| flavor                              | flavor2 (777)                                       |
| hostId                              |                                                     |
| id                                  | 629268c7-9bda-464b-bd86-e60192b0e02c                |
| image                               | Ubuntu-image (734207ab-6a85-473c-8021-00e7173e6441) |
| key_name                            | mykey2                                              |
| name                                | myserver                                            |
| progress                            | 0                                                   |
| project_id                          | 0769b940829c4078a4aa573e83d6520c                    |
| properties                          |                                                     |
| security_groups                     | name='849923e9-2eed-42b5-8eee-fa0f1b855026'         |
| status                              | BUILD                                               |
| updated                             | 2023-07-03T15:56:44Z                                |
| user_id                             | fef5f8c16d3d4b9d849bc1488bf50a21                    |
| volumes_attached                    |                                                     |
+-------------------------------------+-----------------------------------------------------+
[root@controller ~]# openstack server list
+--------------------------------------+----------+--------+-------------------------+--------------+---------+
| ID                                   | Name     | Status | Networks                | Image        | Flavor  |
+--------------------------------------+----------+--------+-------------------------+--------------+---------+
| 629268c7-9bda-464b-bd86-e60192b0e02c | myserver | ACTIVE | net-flat=192.168.200.72 | Ubuntu-image | flavor2 |
+--------------------------------------+----------+--------+-------------------------+--------------+---------+
# 测试连通性
[root@controller ~]# ping 192.168.200.72
PING 192.168.200.72 (192.168.200.72) 56(84) bytes of data.
64 bytes from 192.168.200.72: icmp_seq=1 ttl=64 time=2.12 ms
# 连接云主机
[root@controller ~]# ssh ubuntu@192.168.200.72
ubuntu@myserver:~$ pwd
/home/ubuntu

# 可以看到使用的是我们创建的规格类型
ubuntu@myserver:~$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda     252:0    0   20G  0 disk 
├─vda1  252:1    0 19.9G  0 part /
├─vda14 252:14   0    4M  0 part 
└─vda15 252:15   0  106M  0 part /boot/efi
# 也可以ping通百度 能连接到外网
ubuntu@myserver:/$ ping -c4 baidu.com
PING baidu.com (39.156.66.10) 56(84) bytes of data.
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=1 ttl=128 time=18.9 ms
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=2 ttl=128 time=19.0 ms
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=3 ttl=128 time=17.6 ms
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=4 ttl=128 time=17.2 ms

--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3009ms
rtt min/avg/max/mdev = 17.246/18.228/19.096/0.791 ms
ubuntu@myserver:/$ 

启动关闭云主机

[root@controller ~]# openstack server stop myserver
[root@controller ~]# openstack server list
+--------------------------------------+----------+---------+-------------------------+--------------+---------+
| ID                                   | Name     | Status  | Networks                | Image        | Flavor  |
+--------------------------------------+----------+---------+-------------------------+--------------+---------+
| 629268c7-9bda-464b-bd86-e60192b0e02c | myserver | SHUTOFF | net-flat=192.168.200.72 | Ubuntu-image | flavor2 |
+--------------------------------------+----------+---------+-------------------------+--------------+---------+

[root@controller ~]# openstack server start myserver
[root@controller ~]# openstack server list
+--------------------------------------+----------+--------+-------------------------+--------------+---------+
| ID                                   | Name     | Status | Networks                | Image        | Flavor  |
+--------------------------------------+----------+--------+-------------------------+--------------+---------+
| 629268c7-9bda-464b-bd86-e60192b0e02c | myserver | ACTIVE | net-flat=192.168.200.72 | Ubuntu-image | flavor2 |
+--------------------------------------+----------+--------+-------------------------+--------------+---------+

图形化界面

创建实例类型

image-20230704115519958

image-20230704115558946

image-20230704115615082

创建网络

image-20230704115719996

image-20230704115907841

image-20230704115924704

image-20230704115953312

image-20230704120015016

创建密钥对

[root@controller ~]# ssh-keygen -q -N ""
# -q:表示以静默模式生成密钥对,不会显示额外的输出信息。

# -N "":表示设置生成的密钥对的密码为空,即不设置密码保护。
# 执行这个命令后,会生成一对 SSH 密钥,包括私钥和公钥。
# 私钥将保存在默认的路径 ~/.ssh/id_rsa,而公钥将保存在 ~/.ssh/id_rsa.pub
# 私钥用于对 SSH 连接进行身份验证,而公钥则用于将其添加到目标服务器上的
# ~/.ssh/authorized_keys 文件中,以允许使用私钥进行身份验证。

image-20230704120823001

image-20230704120849903

image-20230704120911006

添加安全组规则

image-20230704121105987

image-20230704121209230

添加安全组规则

image-20230704121224225

放行所有ICMP TCP UDP 的入口出口

image-20230704121317241

创建云主机

image-20230704121503026

选择刚刚创建的资源

image-20230704121726145

image-20230704122226143

查看主机详细信息

image-20230704122251206

image-20230704122332880

image-20230704122403998

远程连接

image-20230704122517997

Cinder

命令行操作

查看cinder存储服务状态

[root@controller ~]# openstack volume service list
+------------------+-------------+------+---------+-------+----------------------------+
| Binary           | Host        | Zone | Status  | State | Updated At                 |
+------------------+-------------+------+---------+-------+----------------------------+
| cinder-scheduler | controller  | nova | enabled | up    | 2023-07-04T07:59:41.000000 |
| cinder-volume    | compute@lvm | nova | enabled | up    | 2023-07-04T07:59:38.000000 |
+------------------+-------------+------+---------+-------+----------------------------+

创建块存储

创建块存储

[root@controller ~]# openstack volume create --size 3 volume1
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attachments         | []                                   |
| availability_zone   | nova                                 |
| bootable            | false                                |
| consistencygroup_id | None                                 |
| created_at          | 2023-07-04T08:33:09.000000           |
| description         | None                                 |
| encrypted           | False                                |
| id                  | 3f277366-14e4-4ead-bcf1-2fde6ab595f1 |
| migration_status    | None                                 |
| multiattach         | False                                |
| name                | volume1                              |
| properties          |                                      |
| replication_status  | None                                 |
| size                | 3                                    |
| snapshot_id         | None                                 |
| source_volid        | None                                 |
| status              | creating                             |
| type                | __DEFAULT__                          |
| updated_at          | None                                 |
| user_id             | fef5f8c16d3d4b9d849bc1488bf50a21     |
+---------------------+--------------------------------------+

查看块存储

[root@controller ~]# openstack volume list
+--------------------------------------+---------+-----------+------+-------------+
| ID                                   | Name    | Status    | Size | Attached to |
+--------------------------------------+---------+-----------+------+-------------+
| 3f277366-14e4-4ead-bcf1-2fde6ab595f1 | volume1 | available |    3 |             |
+--------------------------------------+---------+-----------+------+-------------+

查看某一块存储的详细信息

[root@controller ~]# openstack volume show volume1
+--------------------------------+--------------------------------------+
| Field                          | Value                                |
+--------------------------------+--------------------------------------+
| attachments                    | []                                   |
| availability_zone              | nova                                 |
| bootable                       | false                                |
| consistencygroup_id            | None                                 |
| created_at                     | 2023-07-04T08:33:09.000000           |
| description                    | None                                 |
| encrypted                      | False                                |
| id                             | 3f277366-14e4-4ead-bcf1-2fde6ab595f1 |
| migration_status               | None                                 |
| multiattach                    | False                                |
| name                           | volume1                              |
| os-vol-host-attr:host          | compute@lvm#LVM                      |
| os-vol-mig-status-attr:migstat | None                                 |
| os-vol-mig-status-attr:name_id | None                                 |
| os-vol-tenant-attr:tenant_id   | 0769b940829c4078a4aa573e83d6520c     |
| properties                     |                                      |
| replication_status             | None                                 |
| size                           | 3                                    |
| snapshot_id                    | None                                 |
| source_volid                   | None                                 |
| status                         | available                            |
| type                           | __DEFAULT__                          |
| updated_at                     | 2023-07-04T08:33:10.000000           |
| user_id                        | fef5f8c16d3d4b9d849bc1488bf50a21     |
+--------------------------------+--------------------------------------+

挂载块存储

首先创建一台云主机

[root@controller ~]# openstack server list
+--------------------------------------+---------+--------+------------------------------+--------+---------+
| ID                                   | Name    | Status | Networks                     | Image  | Flavor  |
+--------------------------------------+---------+--------+------------------------------+--------+---------+
| efec3eb5-fa01-4224-bd7a-bd7e2352e186 | server1 | ACTIVE | flat-provider=192.168.200.62 | cirros | m1.nano |
+--------------------------------------+---------+--------+------------------------------+--------+---------+

将创建好的块存储添加到这台云主机上

[root@controller ~]# openstack server add volume efec3eb5-fa01-4224-bd7a-bd7e2352e186 3f277366-14e4-4ead-bcf1-2fde6ab595f1
# openstack server add volume <server name or ID> <volume name or ID>

查看块存储信息

[root@controller ~]# openstack volume list
+--------------------------------------+---------+--------+------+----------------------------------+
| ID                                   | Name    | Status | Size | Attached to                      |
+--------------------------------------+---------+--------+------+----------------------------------+
| 3f277366-14e4-4ead-bcf1-2fde6ab595f1 | volume1 | in-use |    3 | Attached to server1 on /dev/vdb  |
+--------------------------------------+---------+--------+------+----------------------------------+

登录云主机查看挂载信息

[root@controller ~]# ssh cirros@192.168.200.62
The authenticity of host '192.168.200.62 (192.168.200.62)' can't be established.
RSA key fingerprint is SHA256:w/aUcwAwx25Ol3MOJd3Yunu18Bif338H9tuFqt1pUOs.
RSA key fingerprint is MD5:9a:18:79:38:31:52:8e:56:a7:cf:6c:f4:9c:91:18:52.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.200.62' (RSA) to the list of known hosts.
$ lsblk
NAME   MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
vda    253:0    0      1G  0 disk 
`-vda1 253:1    0 1011.9M  0 part /
vdb    253:16   0      3G  0 disk 
$ 

扩展块存储

创建完卷后可能因为需求的变更,需要对已有的卷进行扩容操作

[root@controller ~]# openstack server remove volume  server1 volume1
[root@controller ~]# openstack volume set 
[root@controller ~]# openstack volume set volume1 --size 5
[root@controller ~]# openstack server add volume server1 volume1
[root@controller ~]# openstack volume list
+--------------------------------------+---------+--------+------+----------------------------------+
| ID                                   | Name    | Status | Size | Attached to                      |
+--------------------------------------+---------+--------+------+----------------------------------+
| 3f277366-14e4-4ead-bcf1-2fde6ab595f1 | volume1 | in-use |    5 | Attached to server1 on /dev/vdb  |
+--------------------------------------+---------+--------+------+----------------------------------+
[root@controller ~]# ssh cirros@192.168.200.62
$ lsblk
NAME   MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
vda    253:0    0      1G  0 disk 
`-vda1 253:1    0 1011.9M  0 part /
vdb    253:16   0      5G  0 disk 
$ 

删除块存储

删除很简单,如果你要删除挂载的块存储 首先你要先分离块存储然后再删除

[root@controller ~]# openstack server remove volume server1 volume1
[root@controller ~]# openstack volume delete volume1
[root@controller ~]# openstack volume list

Swift

命令行操作

查看服务状态

[root@controller ~]# swift stat
                        Account: AUTH_0769b940829c4078a4aa573e83d6520c
                     Containers: 0
                        Objects: 0
                          Bytes: 0
Containers in policy "policy-0": 0
   Objects in policy "policy-0": 0
     Bytes in policy "policy-0": 0
    X-Account-Project-Domain-Id: default
         X-Openstack-Request-Id: txc951de50e3464755a30b3-0064a3e3a7
                    X-Timestamp: 1688230822.33140
                     X-Trans-Id: txc951de50e3464755a30b3-0064a3e3a7
                   Content-Type: application/json; charset=utf-8
                  Accept-Ranges: bytes

创建容器

[root@controller ~]# openstack container create csq-swift
+---------------------------------------+-----------+------------------------------------+
| account                               | container | x-trans-id                         |
+---------------------------------------+-----------+------------------------------------+
| AUTH_0769b940829c4078a4aa573e83d6520c | csq-swift | txf3fe9450eb1444e18d9d3-0064a3e416 |
+---------------------------------------+-----------+------------------------------------+

查看容器

[root@controller ~]# openstack container list 
+-----------+
| Name      |
+-----------+
| csq-swift |
+-----------+

查看容器详细信息

[root@controller ~]# openstack container show csq-swift
+--------------+---------------------------------------+
| Field        | Value                                 |
+--------------+---------------------------------------+
| account      | AUTH_0769b940829c4078a4aa573e83d6520c |
| bytes_used   | 0                                     |
| container    | csq-swift                             |
| object_count | 0                                     |
+--------------+---------------------------------------+

创建对象

在使用命令创建对象前,需要将上传后的目录结构在本地创建。在本地创建名为test的目录/root/test,将/root/anaconda-ks.cfg文件复制至/root/test目录中。

[root@controller ~]# mkdir test
[root@controller ~]# mv anaconda-ks.cfg test/
[root@controller ~]# ls test/
anaconda-ks.cfg
[root@controller ~]# openstack object create csq-swift test/anaconda-ks.cfg 
+----------------------+-----------+----------------------------------+
| object               | container | etag                             |
+----------------------+-----------+----------------------------------+
| test/anaconda-ks.cfg | csq-swift | 31d063bfe3e1f5bb6b61b421ba5e21d7 |
+----------------------+-----------+----------------------------------+

查看对象

[root@controller ~]# openstack object list csq-swift
+----------------------+
| Name                 |
+----------------------+
| test/anaconda-ks.cfg |
+----------------------+

查询详细信息

[root@controller ~]# openstack object show csq-swift test/anaconda-ks.cfg 
+----------------+---------------------------------------+
| Field          | Value                                 |
+----------------+---------------------------------------+
| account        | AUTH_0769b940829c4078a4aa573e83d6520c |
| container      | csq-swift                             |
| content-length | 1698                                  |
| content-type   | application/octet-stream              |
| etag           | 31d063bfe3e1f5bb6b61b421ba5e21d7      |
| last-modified  | Tue, 04 Jul 2023 09:31:50 GMT         |
| object         | test/anaconda-ks.cfg                  |
+----------------+---------------------------------------+

下载对象

存储在容器中的对象,可以在需要使用时进行下载,命令如下

[root@controller ~]# cd /opt/
[root@controller opt]# openstack object save csq-swift test/anaconda-ks.cfg 
[root@controller opt]# ls test/
anaconda-ks.cfg

删除对象

[root@controller ~]# openstack object delete csq-swift test/anaconda-ks.cfg 
[root@controller ~]# openstack object list csq-swift

删除容器

[root@controller ~]# openstack container delete csq-swift
[root@controller ~]# openstack container list

分片存储案例

创建容器

[root@controller ~]# openstack container create swift-csq
+---------------------------------------+-----------+------------------------------------+
| account                               | container | x-trans-id                         |
+---------------------------------------+-----------+------------------------------------+
| AUTH_0769b940829c4078a4aa573e83d6520c | swift-csq | txb209ec3e4c2e439896cba-0064a3e96d |
+---------------------------------------+-----------+------------------------------------+

分片存储镜像

[root@controller ~]# swift upload swift-csq -S 10000000 image/cirros-0.3.4-x86_64-disk.img 
image/cirros-0.3.4-x86_64-disk.img segment 1
image/cirros-0.3.4-x86_64-disk.img segment 0
image/cirros-0.3.4-x86_64-disk.img

查看存储路径

[root@controller ~]# swift stat swift-csq image/cirros-0.3.4-x86_64-disk.img 
               Account: AUTH_0769b940829c4078a4aa573e83d6520c
             Container: swift-csq
                Object: image/cirros-0.3.4-x86_64-disk.img
          Content Type: application/octet-stream
        Content Length: 13287936
         Last Modified: Tue, 04 Jul 2023 09:50:53 GMT
                  ETag: "cca17a689bfcd70118fabc833af0d033"
              Manifest: swift-csq_segments/image/cirros-0.3.4-x86_64-disk.img/1687999427.910558/13287936/10000000/
            Meta Mtime: 1687999427.910558
         Accept-Ranges: bytes
           X-Timestamp: 1688464252.67141
            X-Trans-Id: tx4d69e4da9077494189878-0064a3eb95
X-Openstack-Request-Id: tx4d69e4da9077494189878-0064a3eb95

查看路径中的数据片

[root@controller ~]# swift list swift-csq_segments
image/cirros-0.3.4-x86_64-disk.img/1687999427.910558/13287936/10000000/00000000
image/cirros-0.3.4-x86_64-disk.img/1687999427.910558/13287936/10000000/00000001

--------------------------+
| AUTH_0769b940829c4078a4aa573e83d6520c | swift-csq | txb209ec3e4c2e439896cba-0064a3e96d |
±--------------------------------------±----------±-----------------------------------+


分片存储镜像

```shell
[root@controller ~]# swift upload swift-csq -S 10000000 image/cirros-0.3.4-x86_64-disk.img 
image/cirros-0.3.4-x86_64-disk.img segment 1
image/cirros-0.3.4-x86_64-disk.img segment 0
image/cirros-0.3.4-x86_64-disk.img

查看存储路径

[root@controller ~]# swift stat swift-csq image/cirros-0.3.4-x86_64-disk.img 
               Account: AUTH_0769b940829c4078a4aa573e83d6520c
             Container: swift-csq
                Object: image/cirros-0.3.4-x86_64-disk.img
          Content Type: application/octet-stream
        Content Length: 13287936
         Last Modified: Tue, 04 Jul 2023 09:50:53 GMT
                  ETag: "cca17a689bfcd70118fabc833af0d033"
              Manifest: swift-csq_segments/image/cirros-0.3.4-x86_64-disk.img/1687999427.910558/13287936/10000000/
            Meta Mtime: 1687999427.910558
         Accept-Ranges: bytes
           X-Timestamp: 1688464252.67141
            X-Trans-Id: tx4d69e4da9077494189878-0064a3eb95
X-Openstack-Request-Id: tx4d69e4da9077494189878-0064a3eb95

查看路径中的数据片

[root@controller ~]# swift list swift-csq_segments
image/cirros-0.3.4-x86_64-disk.img/1687999427.910558/13287936/10000000/00000000
image/cirros-0.3.4-x86_64-disk.img/1687999427.910558/13287936/10000000/00000001

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/718703.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【数据结构与算法】二叉树中从每个叶子结点到根结点的路径

题目 Qestion: 输出二叉树中从每个叶子结点到根结点的路径 数据结构与定义 #include <stdio.h> #include <stdlib.h>typedef struct TreeNode {int val;struct TreeNode *left;struct TreeNode *right; } TreeNode;二叉树形状 核心代码 void LeafToRoot(TreeNod…

[网络安全提高篇] 一二一.恶意软件动态分析Cape沙箱Report报告的API序列批量提取详解

终于忙完初稿,开心地写一篇博客。 “网络安全提高班”新的100篇文章即将开启,包括Web渗透、内网渗透、靶场搭建、CVE复现、攻击溯源、实战及CTF总结,它将更加聚焦,更加深入,也是作者的慢慢成长史。换专业确实挺难的,Web渗透也是块硬骨头,但我也试试,看看自己未来四年究…

HIve中的查询语句

文章目录 Hive中的查询语句1. 基础语法2. 基本查询&#xff08;Select…From&#xff09;2.1 数据准备&#xff08;0&#xff09;原始数据&#xff08;1&#xff09;创建部门表&#xff08;2&#xff09;创建员工表&#xff08;3&#xff09;导入数据 2.2 全表和特定列查询1&am…

【对象存储】那些事

最近在某个项目中使用了对象存储。以前看过一个新闻&#xff1a;某公司的对象存储被盗刷&#xff0c;一夜之间账户欠费几十万&#xff01;我们这点小买卖可经不起这么折腾&#xff01;所以下功夫研究了下&#xff0c;防患于未然。 说到防盗刷&#xff0c;我们还得了解对象存储是…

Jmeter使用之:怎么编写扩展函数(二)

目录 前言&#xff1a; 1、实现function的类的package声明必须包含".functions" 2、需要继承org.apache.jmeter.functions.AbstractFunction&#xff0c;并且实现相应的方法。 第一步&#xff1a;eclipse 导入jmeter目录&#xff1a;apache-jmeter-2.13libext下的…

【SLAM学习】FAST-LIO配置

本文主要记录如何配置FAST-LIO Eigen库 Eigen库安装&#xff1a; sudo apt install libeigen3-dev 查看Eigen版本&#xff1a; $ pkg-config --modversion eigen3 PCL库 PCL库安装&#xff1a; sudo apt install libpcl-dev 也可以指定版本安装&#xff1a; sudo apt …

AVS3:角度加权预测AWP

在一般的视频编码标准中帧间预测有两种方式&#xff1a;单向预测和双向预测。一般是将图像划分为矩形&#xff08;正方形&#xff09;块然后到参考帧中去搜索和它最接近的块作为预测块&#xff0c;单向预测只有一个预测块&#xff0c;而双向搜索会有2个预测块&#xff0c;将2个…

基于Java医院住院综合服务管理系统设计实现(源码+lw+部署文档+讲解等)

博主介绍&#xff1a;✌全网粉丝30W,csdn特邀作者、博客专家、CSDN新星计划导师、Java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专…

前端Vue自定义精美悬浮菜单按钮fab button 可设置按钮背景颜色 菜单按钮展开条目

前端Vue自定义精美悬浮菜单按钮fab button 可设置按钮背景颜色 菜单按钮展开条目,下载完整代码请访问uni-app插件市场地址&#xff1a;https://ext.dcloud.net.cn/plugin?id13321 效果图如下: # cc-suspensionMenu #### 使用方法 使用方法 <!-- scrollShow:是否显示滑动…

【Spark实战】Windows环境下编译Spark2 Linux上部署Spark On Yarn

Windows环境下编译Spark2 环境准备 git-2.14.1maven-3.9.2jdk-1.8scala-2.11.8zinc-0.3.15 主下载地址spark-2.3.4 github官方地址 编译准备 maven远程仓库使用的是阿里云的 解压源码包spark-2.3.4.zip,修改根模块的pom文件。主要目的是为了变更hadoop的版本号&#xff0c;…

飞控学习笔记-飞行器数学模型(2)

十字型模型 旋翼动力学 动力模型 电机模型 模型仿真 升力模型 力矩模型 反扭力 仿真

如何理解字符串不可变

字符串的不可变性: String类内部定义了 final char[ ] value ;数组用于存储字符串数据。 这里的value数组是通过final关键字修饰的,也就说字符串其实是一个常量,一旦在内存中申请出一个空间并且为其赋值之后这个空间中的字符串值就不可以修改了,将这个性质我们称之为不可变性。…

阿里云服务拆分部署

最近在工作中遇到需要将现网运行的服务拆分出一套&#xff0c;放置于本地机房&#xff0c;拆分服务运行有两种方案&#xff1a; 第一种是本地部署一个独立spring应用&#xff0c;业务上的要求是尽量隔离 第二种是采用阿里集群部署 采用第二种方案目前看是隔离度最高的

4.44ue4:相机抖动

1.创建相机抖动类 右键内容面板&#xff0c;点击创建蓝图类&#xff0c;搜索shake&#xff08;camera shake&#xff09; 2.使用相机抖动&#xff1a; 节点&#xff1a;play world .. api解释&#xff1a; epicenter&#xff1a;震源 inner Radius&#xff1a;内圈范围&a…

Git gui教程---第一篇 下载和安装

下载和安装 下载网址安装 下载网址 链接: 下载网址 有两种安装方式&#xff1a; 是用EXE的文件安装&#xff0c;我们用这个是便携版&#xff0c;好像是压缩包形式&#xff0c;没用过。 这是下载后的安装包文件&#xff0c;我的电脑是64位&#xff0c;所以下载的是64位。 安…

Unity2D横版游戏(深海潜水艇)

找到个挺有意思的小游戏Unity2D横版游戏&#xff08;深海潜水艇&#xff09; 这个也是曾经有段时间抖、音很火的一个小游戏。 鼠标左键点击让小艇上升 因为是unity开发的小游戏&#xff0c;可发布多个平台&#xff0c;有兴趣的拿去玩吧。 代码也是挺简单的 using UnityEngin…

【经典题目分析】数组分割问题

文章目录 698. 划分为k个相等的子集416. 分割等和数组 698. 划分为k个相等的子集 把一个数组&#xff0c;拆分成K个大小一样的子数组。方法可以是状态枚举&#xff0c;或者dfs class Solution { public:bool canPartitionKSubsets(vector<int>& nums, int k) {// 从…

C/C++图形库EasyX保姆级使用教程(三) 图形颜色的填充及相关应用

C/C图形库EasyX保姆级使用教程系列文章目录 第一章 Microsoft Visual Studio 2022和EasyX的下载及安装使用 第二章 图形化窗口设置以及简单图形的绘制 第三章 图形颜色的填充及相关应用 文章目录 C/C图形库EasyX保姆级使用教程系列文章目录前言一、如何填充颜色1.确定颜色1.1 …

TypeScript - 函数(下)

目录 1、在函数中声明this 2、其他需要知道的类型 2.1 void 2.2 object 2.3 unknow 2.4 never 2.5 Function 3、其余参数&#xff08;rest&#xff09;和参数 4、参数解构 5、函数的可分配性 1、在函数中声明this TypeScript 将通过代码流分析推断函数中应该是什么&…

jenkins_svn_maven持续集成

详解Jenkins &#xff0c;svn &#xff0c;maven 项目持续集成 第一步&#xff1a; 由于刚刚接触jenkins 并不知道他是个什么东西&#xff0c;首先百度一下&#xff0c;然后进入官网&#xff0c;下载安装包。 第二步 windows 安装&#xff1a; 下载完了&#xff0c;打开里面…