openstack考试需要的部署操作

openstack操作大全

一,keystone

用户

1.创建用户

openstack user create --password 密码 --email邮箱 --domain 域名 用户名字

2.删除用户

opensatck user delete 用户名

3.查看用户列表

openstack user list

4.查看用户详细信息

openstack user show 用户名

5.其他

# 语法
openstack
  user create    Create new user           # 创新新用户
  user delete    Delete user(s)            # 删除用户
  user list      List users                # 查看用户列表
  user password set  Change current user password    # 修改用户密码
  user set       Set user properties       # 更新用户信息
  user show      Display user details      # 查看用户详情

角色

1.查询所有keystone角色

openstack role list

2.查询某一个角色的详细信息

openstack role show 角色名

端点

1.查看平台所有服务使用的端点地址

openstack endpoint list

1.创建域

openstack domain create --description "描述" 名字

2.查看域列表

openstack domain list

3.更新域
命令格式:
openstack domain set[--options] <domain-name>
--name New domain name # 新名字
--description New domain description # 新的描述
--enable Enable domain # 启用域
--disable Disable domain # 禁用域
eg:

 openstack domain set --description "描述" --name 域名  用户名

4.查看域的详情

openstack domain show 域名

5.删除域

openstack domain set --disable 域名(此时的域要求处于disable状态)

项目

1.查看项目列表

opensatck project list

2.查看项目详情

openstack project show 项目名

3.删除项目

openstack project delete 项目名

二,glance

1.查看镜像列表

glance image list
```bash
2.查看镜像详情
```bash
opensatck image <镜像id号>|<镜像名>
```bash
3.制作镜像
```bash
openstack image create --file 镜像文件名字 --disk-format 磁盘格式(qcow2) --container-format bare(容器格式) --public cirros(名字)

opensatck image create create --file cirros.... --disk-format qcow2 --container-format bare --public cirros

上传内核镜像
 openstack image create "cirros-threepart-kernel" \
  --disk-format aki --container-format aki --public \
  --file ~/images/cirros-0.3.5-x86_64-kernel


上传RAW镜像
  openstack image create "cirros-threepart-ramdisk" \
  --disk-format ari --container-format ari --public \
  --file ~/images/cirros-0.3.5-x86_64-initramfs
  
上传第三方镜像
 openstack image create "cirros-threepart" --disk-format ami \
  --container-format ami --public \
  --property kernel_id=$KID-property ramdisk_id=$RID \
  --file ~/images/cirros-0.3.5-x86_64-rootfs.img

注册RAW镜像
 openstack image create "cirros-raw" --disk-format raw \
  --container-format bare --public \
  --file ~/images/cirros-0.3.5-x86_64-disk.img

4.删除镜像

glance image-delete <镜像id号>
```bash
5.更新镜像
```bash
openstack image set <镜像名>

三,placement

创建服务

openstack service create --name 服务名 类型

1.端口占用情况

2.当前用户的角色

3.服务的list

4.端口的list

四,nova

1.nova提供了一个检测工具nova-status,检查四个服务

nova-status upgrade cheack

2.发现新的计算节点

su nova -s /bin/sh -c "nova-anage cell_v2 discover_hosts --verbose"

3.设置自动发现

vi /etc/nova/nova.conf
[scheduler]
discover_hosts_in_cells_interval = 60

systemctl restart openstack-nova-api

五,neutron

openstack
network create Create new network # 创建网络
network delete Delete network(s) # 删除网络
network list List networks # 列出网络
network set Set network properties # 设置网络参数
network unset Unset network properties # 取消网络参数——标签tag
network show Show network details # 显示网络详情
1.创建flavor类型的共享外部网络

openstack network create --share --external \
--provider-physical-network provider \
--provider-network-type flat \
vm-network

2.查看当前网络列表

openstack network list

3.查看网络详情

openstack network show 10f3ff17-a6aa-48de-977d-0b11740e9bd1(可以用id或者名称0

4.删除网络

openstack network delete 网络名

5.创建外部网络

neutron  net-create --shared --router:external=true --provider:network_type  gre net-test-gre

6.创建内部网络

neutron  net-create --shared --provider:network_type  gre int-test-gre

7.查看网络详情

neutron net-show int-test-gre

8.重命名

openstack network set net-test-gre --name net-test11-gre --disable --no-share

子网

openstack
subnet create Create a subnet # 创建子网
subnet delete Delete subnet(s) # 删除子网
subnet list List subnets # 列出子网
subnet set Set subnet properties # 设置子网参数
subnet show Display subnet details # 显示子网详细信息
subnet unset Unset subnet properties # 取消子网参数设置
1.创建子网

openstack subnet create --network vm-network \    # 设置子网所属的网络
> --allocation-pool start=10.10.10.101,end=10.10.10.201 \              # DHCP分配的IP地址池
> --dns-nameserver 114.114.114.114 \                                   # 设置DNS服务器地址
> --subnet-range 10.10.10.0/24 \                                       # 设置子网网段
> vm-subnetwork                                                        # 子网名称

2.查看子网详情(名称或者id)

openstack subnet  show id|name

3.修改子网名称并设置网关

openstack subnet set --name new-subvnet --gateway 10.10.10.2 vm-subnetwork

4.取消子网参数

 openstack subnet unset -h
optional arguments:
  -h, --help            show this help message and exit
  --allocation-pool start=<ip-address>,end=<ip-address>    删除DHCP地址池
  --dns-nameserver <dns-nameserver>    删除dns
  --host-route destination=<subnet>,gateway=<ip-address>   删除路由网关
  --service-type <service-type>   删除服务类型
  --tag <tag>           删除指定的标签
  --all-tag             删除所有的标签

5.删除子网

openstack subnet delete vm-subnetwork

设置网络参数

 1.改名、改非共享
[root@controller ~]# openstack network set --name new-vnet  --no-share  vm-network
 查看更改效果
 改之前 shared 值为 True,改之后 shared 值为 False
[root@controller ~]# openstack network show new-vnet
 2.加标签tag
 执行查看详情可看到:tags 的值为hqs
[root@controller ~]# openstack network set --tag hqs  new-vnet


取消网络参数(仅限标签)
[root@controller ~]# openstack network unset -h  new-vnet
usage: openstack network unset [-h] [--tag <tag> | --all-tag] <network>
Unset network properties
positional arguments:
  <network>    Network to modify (name or ID)
optional arguments:
  -h, --help   show this help message and exit
  --tag <tag>  Tag to be removed from the network (repeat option to remove
               multiple tags)
  --all-tag    Clear all tags associated with the network
# 去除tags对应的值
[root@controller ~]# openstack network unset --tag hqs  new-vnet
# 去除所有tags对应的值
[root@controller ~]# openstack network unset --all-tag  new-vnet


 删除网络
[root@controller ~]# openstack network delete vm-network

六,dashboard(0)

七,cinder

1.卷列表查看
··

cinder  list

2.卷详情查看

cinder show 卷id

3.创建卷
cinder create [--name , --volume-type ] <size(GB)>

cinder create --size 10 --description "描述" --name myvol --availability-zone nova 2

4.删除卷

cinder delete 卷id

5.更新卷
(1)重命名

cinder rename <volume> <name>
cinder rename test test-volume-01

(2)修改状态

# 可修改的状态:"available", "error", "creating", "deleting", "in-use", "attaching", "detaching", "error_deleting" and "maintenance".
# 附加状态:"attached" , "detached". 默认状态为:None.

cinder reset-state [--state <state>,--attach-status <attach-status>,--reset-migration-status] <volume>
cinder reset-state --state deleting test-volume-01

(3)修改类型

cinder retype <volume> <volume_type>

eg:
修改卷状态为available

[root@controller ~]# cinder reset-state --state available test-volume-01

(4)查看(创建)卷类型

cinder  type-create lvm

(5)扩容
:::注意,只能从小改到大,不能从大改到小。且卷的类型只能是整数值

cinder extend <volume> <new size>
cinder extend test-volume-01 5

卷类型

type-create Creates a volume type. # 类型创建
type-default List the default volume type.
type-delete Deletes a volume type. # 类型删除
type-key Sets or unsets extra_spec for a volume type.
type-list Lists available 'volume types'. (Admin only will see
private types) # 类型列表查看
type-show Show volume type details. # 类型详情查看
type-update Updates volume type name, description, and/or
is_public. # 类型更新

cinder type-create lvm
cinder type-create 1000GB
### 卷快照
openstack
  server image create    Create a new server disk image from an existing server  # 为已存在的服务器创建一个新的硬盘镜像
  volume snapshot create  Create new volume snapshot    # 创建新的卷快照
  volume snapshot delete  Delete volume snapshot(s)     # 删除卷快照
  volume snapshot list   List volume snapshots           # 查看卷快照列表
  volume snapshot set   Set volume snapshot properties   # 修改卷快照属性
  volume snapshot show   Display volume snapshot details     # 查看卷快照详情
  volume snapshot unset   Unset volume snapshot properties   # 取消卷快照修改设置

# 对云主机拍摄快照生成镜像,可用来还原云主机或创建新云主机
# 语法:
openstack server image create [--name <image-name>] [--wait]  <server>
# 为云主机拍快照,生成镜像
[root@controller ~]# openstack server image create hqs01 --name vmSnapshot


# 操作前置——有卷volume存在
[root@controller ~]# openstack volume list

# 创建卷快照
openstack volume snapshot create [--options] <snapshot-name>
  --volume <volume>     Volume to snapshot (name or ID) (default is <snapshot-
                        name>)          # 指定要快照的卷
  --description <description>           # 描述快照
                        Description of the snapshot
  --force               Create a snapshot attached to an instance. Default is
                        False           # 强制拍快照,默认只有available的卷可以快照
   --property <key=value>               # 设置快照的属性
                        Set a property to this snapshot (repeat option to set
                        multiple properties)
  --remote-source <key=value>           # 远程快照属性?
                        The attribute(s) of the exsiting remote volume
                        snapshot (admin required)
[root@controller ~]# openstack volume snapshot create --description 'test snapshot' --volume  87d595dd-3089-4d37-b8e4-bc0a597c92c7 --force  hqs01_backup
+-------------+--------------------------------------+
| Field       | Value                                |
+-------------+--------------------------------------+
| created_at  | 2022-12-09T12:01:21.472986           |
| description | test snapshot                        |
| id          | d23fb39f-7078-46ef-9148-be9f42145838 |
| name        | hqs01_backup                         |
| properties  |                                      |
| size        | 10                                   |
| status      | creating                             |
| updated_at  | None                                 |
| volume_id   | 87d595dd-3089-4d37-b8e4-bc0a597c92c7 |
+-------------+--------------------------------------+

# 查看卷快照列表(包含openstack server image create创的)
[root@controller ~]# openstack volume snapshot list
+--------------------------------------+-------------------------+---------------+-----------+------+
| ID                                   | Name                    | Description   | Status    | Size |
+--------------------------------------+-------------------------+---------------+-----------+------+
| d23fb39f-7078-46ef-9148-be9f42145838 | hqs01_backup            | test snapshot | available |   10 |
| f6829d63-9ac6-419e-91df-8fb2cb489bbb | snapshot for vmSnapshot |               | available |   10 |
+--------------------------------------+-------------------------+---------------+-----------+------+

# 查看卷快照详情
[root@controller ~]# openstack volume snapshot show hqs01_backup
+--------------------------------------------+--------------------------------------+
| Field                                      | Value                                |
+--------------------------------------------+--------------------------------------+
| created_at                                 | 2022-12-09T12:01:21.000000           |
| description                                | test snapshot                        |
| id                                         | d23fb39f-7078-46ef-9148-be9f42145838 |
| name                                       | hqs01_backup                         |
| os-extended-snapshot-attributes:progress   | 100%                                 |
| os-extended-snapshot-attributes:project_id | 4188570a34464b938ed3fa7e08681df8     |
| properties                                 |                                      |
| size                                       | 10                                   |
| status                                     | available                            |
| updated_at                                 | 2022-12-09T12:01:22.000000           |
| volume_id                                  | 87d595dd-3089-4d37-b8e4-bc0a597c92c7 |
+--------------------------------------------+--------------------------------------+

# 删除卷快照
[root@controller ~]# openstack volume snapshot delete hqs01_backup
## 八,云主机相关操作
### 创建和开机
1.创造一个flavor实例,名字m1.tiny
```bash
openstack flavor create --ram 512 --disk 1 --vcpus 1 m1.tiny

2.用类型和镜像名称(如果名称唯一)启动云主机

openstack server create --image IMAGE --flavor FLAVOR INSTANCE_NAME
openstack server create --image cirros-0.3.5-x86_64-uec --flavor m1.tiny \
  MyFirstInstance

3.显示实例详细信息

$ openstack server show NAME
$ openstack server show MyFirstInstance

4.查看云主机的控制台日志

$ openstack console log show MyFirstInstance

5.设置云主机的元数据

$ nova meta volumeTwoImage set newmeta='my meta data'

6.创建一个实例快照

$ openstack image create volumeTwoImage snapshotOfVolumeImage
$ openstack image show snapshotOfVolumeImage

实例的暂停,挂起,救援,调整规格,重建,重启

1.暂停实例

$ openstack server pause NAME

2.挂起实例

$ openstack server suspend NAME

3.取消挂起

$ openstack server unpause NAME

4.冻结

$ openstack server resume NAME

5.关机

$ openstack server stop NAME

6.开机

$ openstack server start NAME

8.恢复

$ openstack server rescue NAME
$ openstack server rescue NAME --rescue_image_ref RESCUE_IMAGE

9.调整大小

$ openstack server resize NAME FLAVOR
$ openstack server resize my-pem-server m1.small
$ openstack server resize --confirm my-pem-server1

10.重建

$ openstack server rebuild NAME IMAGE
$ openstack server rebuild newtinny cirros-qcow2

11.重启

$ openstack server reboot NAME
$ openstack server reboot newtinny

12.将用户数据和文件注入到实例

$ openstack server create --user-data FILE INSTANCE
$ openstack server create --user-data userdata.txt --image cirros-qcow2 \
  --flavor m1.tiny MyUserdataInstance2

13.管理安全组,在默认的安全组中加入ping和ssh规则

$ openstack security group rule create default \
    --remote-group default --protocol icmp
$ openstack security group rule create default \
    --remote-group default --dst-port 22

14.使用密钥对来进行访问实例
(1)创建密钥对

$ openstack keypair create test > test.pem
$ chmod 600 test.pem

(2)启动实例

$ openstack server create --image cirros-0.3.5-x86_64 --flavor m1.small \
  --key-name test MyFirstServer

(3)使用ssh连接到实例

$ openstack server create --image cirros-0.3.5-x86_64 --flavor m1.small \
  --key-name test MyFirstServer

网络

1创建网络

$ openstack network create NETWORK_NAME

2创建子网

$ openstack subnet create --subnet-pool SUBNET --network NETWORK SUBNET_NAME
$ openstack subnet create --subnet-pool 10.0.0.0/29 --network net1 subnet1

存储

1创建一个新卷

$ openstack volume create --size SIZE_IN_GB NAME
$ openstack volume create --size 1 MyFirstVolume

2.启动实例并连接到卷上

$ openstack server create --image cirros-qcow2 --flavor m1.tiny MyVolumeInstance

3列出所有卷

$ openstack server add volume INSTANCE_ID VOLUME_ID
$ openstack server add volume MyVolumeInstance 573e024d-5235-49ce-8332-be1576d323f8

4当卷的状态为可用,连接到实例

$ openstack server add volume INSTANCE_ID VOLUME_ID
$ openstack server add volume MyVolumeInstance 573e024d-5235-49ce-8332-be1576d323f8

posted on   代码你敲我不敲  阅读(47)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南

导航

统计

返回顶端
点击右上角即可分享
微信分享提示