OpenStack Redhat命令行操作
命令行删除
环境变量
OpenStack的九个组件必须熟记,命令不需要死记硬背,我们可以通过help来查询相关的命令和参数。
如果你直接使用命令来查询或者做其他操作,那么会涉及到环境变量,操作起来非常麻烦,比如:
所以需要提前加载好环境变量,而默认情况下创建好OP,会自动生成一个admin的环境变量文件:
文件内容:
那这个文件是如何生成的?
在应答文件中cloudcs.txt
如果你的环境没有这个文件,怎么办?
可以进行手工创建,也可以从其他地方拷贝一份。
现在有了admin的环境变量文件,我们就可以进行加载环境变量,让它变为admin的用户变量。
但是没有普通用户的环境变量,可以拷贝一份,然后进行修改
之后,就可以通过两个环境变量文件,快速切换。
查询租户信息(admin)
删除实例云主机(nova)
因为主机实例是在普通用户下创建的,所有切换普通用户
[root@controller ~(keystone_admin)]# source keystonerc_user
[root@controller ~(keystone_user)]# nova list
[root@controller ~(keystone_user)]# nova delete zhuji1
删除云硬盘(cinder)
[root@controller ~(keystone_user)]# cinder -h |grep del
[root@controller ~(keystone_user)]# cinder help delete
[root@controller ~(keystone_user)]# cinder delete abc
删除安全组(neutron)
[root@controller ~(keystone_user)]# neutron -h |grep del
[root@controller ~(keystone_user)]# neutron -h |grep list
[root@controller ~(keystone_user)]# neutron security-group-list
[root@controller ~(keystone_user)]# neutron help security-group-delete
[root@controller ~(keystone_user)]# neutron security-group-delete sec
删除密钥对(nova)
[root@controller ~(keystone_user)]# nova -h |grep key
flavor-key Set or unset extra_spec for a flavor.
keypair-add Create a new key pair for use with servers.
keypair-delete Delete keypair given by its name.
keypair-list Print a list of keypairs for a user
keypair-show Show details about the given keypair.
[root@controller ~(keystone_user)]# nova keypair-list
[root@controller ~(keystone_user)]# nova keypair-delete miyao
[root@controller ~(keystone_user)]# nova keypair-list
删除浮动IP(neutron)
[root@controller ~(keystone_user)]# neutron floatingip-list
[root@controller ~(keystone_user)]# neutron floatingip-delete 63c221b9-e7af-437b-acc8-ad87d81b1554
Deleted floatingip: 63c221b9-e7af-437b-acc8-ad87d81b1554
[root@controller ~(keystone_user)]# neutron floatingip-list
删除网络(neutron)
清除网关--删除公网线
[root@controller ~(keystone_user)]# neutron -h |grep rout
[root@controller ~(keystone_user)]# neutron router-list
[root@controller ~(keystone_user)]# neutron help router-gateway-clear
[root@controller ~(keystone_user)]# neutron router-gateway-clear route
Removed gateway from router route
清除路由接口--删除私网线
[root@controller ~(keystone_user)]# neutron router-list --获取路由的ID
[root@controller ~(keystone_user)]# neutron subnet-list --获取私网子网的ID
[root@controller ~(keystone_user)]# neutron router-interface-delete d2979f27-2eae-433a-ad2b-eb99f1195144 5a5ddaa8-911a-4801-87b4-2e18d28ca490
Removed interface from router d2979f27-2eae-433a-ad2b-eb99f1195144.
清除路由
[root@controller ~(keystone_user)]# neutron -h |grep rout
[root@controller ~(keystone_user)]# neutron help router-delete
[root@controller ~(keystone_user)]# neutron router-delete route
Deleted router: route
删除网络
[root@controller ~(keystone_user)]# neutron net-list
+--------------------------------------+------+-------------------------------------------------------+
| id | name | subnets |
+--------------------------------------+------+-------------------------------------------------------+
| 3e293301-6928-4732-ae08-eb5cf0ba215b | pri | 78877c7c-6b3b-477a-9cea-4948fec61e1e 192.168.200.0/24 |
| 6920e565-34c6-46fc-aa87-a27f00f12064 | pub | 3ed7fb24-1590-402b-a636-dcd4650e963f 192.168.100.0/24 |
+--------------------------------------+------+-------------------------------------------------------+
[root@controller ~(keystone_user)]# neutron net-delete pub
Deleted network: pub
[root@controller ~(keystone_user)]# neutron net-list
+--------------------------------------+------+-------------------------------------------------------+
| id | name | subnets |
+--------------------------------------+------+-------------------------------------------------------+
| 3e293301-6928-4732-ae08-eb5cf0ba215b | pri | 78877c7c-6b3b-477a-9cea-4948fec61e1e 192.168.200.0/24 |
+--------------------------------------+------+-------------------------------------------------------+
[root@controller ~(keystone_user)]# neutron net-delete pri
Deleted network: pri
删除镜像(glance)
[root@controller ~(keystone_user)]# source keystonerc_admin
[root@controller ~(keystone_admin)]# glance image-list
因为镜像是受保护的,索引要更新一下
[root@controller ~(keystone_admin)]# glance -h |grep update
[root@controller ~(keystone_admin)]# glance image-update --is-protected false cirros
删除规格(nova)
[root@controller ~(keystone_admin)]# glance image-delete cirros
[root@controller ~(keystone_admin)]# nova -h |grep fla
[root@controller ~(keystone_admin)]# nova flavor-list
[root@controller ~(keystone_admin)]# nova flavor-delete 11d33a6a-e3eb-4aec-9f67-94169a624e53
[root@controller ~(keystone_admin)]# nova flavor-list
删除用户(keystone)
[root@controller ~(keystone_admin)]# keystone -h |grep user
[root@controller ~(keystone_admin)]# keystone user-list
[root@controller ~(keystone_admin)]# keystone user-delete kongshuo
删除租户(keystone)
[root@controller ~(keystone_admin)]# keystone -h |grep tenan
[root@controller ~(keystone_admin)]# keystone tenant-list
[root@controller ~(keystone_admin)]# keystone tenant-delete myweb
命令行创建
创建租户(keystone)
[root@controller ~(keystone_admin)]# keystone -h |grep crea
[root@controller ~(keystone_admin)]# keystone help tenant-create
[root@controller ~(keystone_admin)]# keystone tenant-create --name webapp --description webapp.app
创建用户(keystone)
[root@controller ~(keystone_admin)]# keystone -h |grep user
[root@controller ~(keystone_admin)]# keystone help user-create
[root@controller ~(keystone_admin)]# keystone user-create --name kongshuo --tenant webapp
[root@controller ~(keystone_admin)]# keystone user-password-update --pass redhat kongshuo
当然你也可以在创建用户的时候,直接带上密码
[root@controller ~(keystone_admin)]# keystone user-create --name kongshuo --pass redhat --tenant webapp
上传镜像(glance)
[root@controller ~(keystone_admin)]# glance -h |grep image
[root@controller ~(keystone_admin)]# glance help image-create
[root@controller ~(keystone_admin)]# glance image-create --name cirros --disk-format qcow2 --container-format bare --file=/root/cirros-0.5.2-x86_64-disk.img --is-public true --progress
创建规格(nova)
[root@controller ~(keystone_admin)]# nova -h |grep fla
[root@controller ~(keystone_admin)]# nova help flavor-create
[root@controller ~(keystone_admin)]# nova flavor-create w2.webapp auto 2048 5 1
创建网络(neutron)
普通用户创建
创建公网
[root@controller ~(keystone_admin)]# source keystonerc_user
[root@controller ~(keystone_user)]# neutron help subnet-create
[root@controller ~(keystone_user)]# neutron net-create pub2
[root@controller ~(keystone_user)]# neutron subnet-create --name pub_sub --allocation-pool start=192.168.100.160,end=192.168.100.170 --disable-dhcp --gateway 192.168.100.254 pub2 192.168.100.0/24
该公网没有被共享,所以切换到管理员
[root@controller ~(keystone_user)]# source keystonerc_admin
[root@controller ~(keystone_admin)]# neutron net-show pub2
[root@controller ~(keystone_admin)]# neutron net-update --shared=true --router:external=true pub2
Updated network: pub2
[root@controller ~(keystone_admin)]# neutron net-show pub2
创建私网
[root@controller ~(keystone_user)]# neutron help subnet-create
[root@controller ~(keystone_user)]# neutron net-create pri2
[root@controller ~(keystone_user)]# neutron subnet-create --name pri_sub --enable-dhcp pri2 192.168.200.0/24
创建路由器
[root@controller ~(keystone_user)]# neutron -h |grep route
[root@controller ~(keystone_user)]# neutron router-create route
设置网关
[root@controller ~(keystone_user)]# neutron -h |grep gatewa
[root@controller ~(keystone_user)]# neutron router-gateway-set route pub2
设置路由接口
[root@controller ~(keystone_user)]# neutron -h |grep inter
[root@controller ~(keystone_user)]# neutron router-interface-add route pri_sub
设置安全组(neutron)
[root@controller ~(keystone_user)]# neutron -h |grep sec
[root@controller ~(keystone_user)]# neutron security-group-create sec
添加规则
[root@controller ~(keystone_user)]# neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 80 --port-range-max 80 sec
[root@controller ~(keystone_user)]# neutron security-group-rule-create --direction ingress --protocol icmp sec
[root@controller ~(keystone_user)]# neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 22 --port-range-max 22 sec
创建密钥(nova)
[root@controller ~(keystone_user)]# nova -h|grep key
[root@controller ~(keystone_user)]# nova keypair-add keyyao > keyyao.pem
创建浮动IP(neutron)
[root@controller ~(keystone_user)]# neutron -h|grep flo
[root@controller ~(keystone_user)]# neutron floatingip-create pub2
创建云主机(nova)
[root@controller ~(keystone_user)]# nova boot --flavor w2.webapp --image cirros --min-count 1 --key-name keyyao --security-groups sec --nic net-id=9d8b33e9-7284-4697-92ac-96414b4e03c3 ks01
绑定浮动IP(nova)
浮动的创建是由neutron,而分配和取消分配是由nova
[root@controller ~(keystone_user)]# nova -h| grep flo
[root@controller ~(keystone_user)]# nova floating-ip-associate ks01 192.168.100.161
绑定云硬盘(cinder+nova)
创建云硬件
[root@controller ~(keystone_user)]# cinder -h |grep vol
[root@controller ~(keystone_user)]# cinder help create
[root@controller ~(keystone_user)]# cinder create --display-name vol1 2
[root@controller ~(keystone_user)]# cinder list
绑定云硬盘
[root@controller ~(keystone_user)]# nova -h | grep att
[root@controller ~(keystone_user)]# nova help volume-attach
[root@controller ~(keystone_user)]# nova volume-attach ks01 15266d24-dbd3-48dc-b8e8-13fa40f2ee89
查看云硬盘
[root@controller ~(keystone_user)]# ssh -i keyyao.pem cirros@192.168.100.161
# 密码 gocubsgo
本文作者:kongshuo
本文链接:https://www.cnblogs.com/kongshuo/p/16629026.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
OpenStack
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步