openstack常规操作命令梳理

时间:2022-01-03 05:06:58

之前顺利部署了openstack+kvm的虚拟化云平台管理环境,其中,涉及到不少openstack操作命令,记录如下:

查看rabbitmq 队列
[root@openstack ~]#rabbitmqctl list_queues

查看keystone的用户
[root@openstack ~]#keystone user-list

查看keystone endpoint
[root@openstack ~]#keystone endpoint-list

查看keystone的role
[root@openstack ~]#keystone role-list

查看keystone 服务
[root@openstack ~]#keystone service-list

查看keystone租户
[root@openstack ~]#keystone tenant-list

查看租户情况
[root@openstack ~]#keystone tenant-get ID

查看keystone进程
[root@openstack ~]#ps -ef | grep -i keystone-all

查看日志是否有错误
[root@openstack ~]#grep ERROR /var/log/keystone/keystone.log

上传image
[root@openstack ~]#glance add name="Ubuntu 12.04 cloudimg amd64" is_public=true container_format=ovf disk_format=qcow2 < /root/precise-server-cloudimg-amd64-disk1.img

查看image
[root@openstack ~]#glance index

nova 命令查看image
[root@openstack ~]#nova image-list

查看image具体信息(ID是通过 glance index 查看获得)
[root@openstack ~]#glance show ID

查看nova 服务
[root@openstack ~]#nova-manage service list

创建密钥
[root@openstack ~]#nova keypair-add oskey > oskey.priv
[root@openstack ~]#chmod 600 oskey.priv

申请floating IP
[root@openstack ~]#nova floating-ip-create

安全组相关命令
[root@openstack ~]#nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
[root@openstack ~]#nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
[root@openstack ~]#nova secgroup-list
[root@openstack ~]#nova secgroup-list-rules default

查看虚拟机配置种类
[root@openstack ~]#nova flavor-list

创建虚拟机(一个test的虚拟机)
[root@openstack ~]#nova boot --flavor 2 --key_name oskey --image ea3ffba1-065e-483f-bfe2-c84184ee76be test1

完整创建一个虚拟机的流程
[root@openstack ~]#nova keypair-add oskey > oskey.priv
[root@openstack ~]#chmod 600 oskey.priv
[root@openstack ~]#nova flavor-list
[root@openstack ~]#nova image-list
[root@openstack ~]#nova boot --flavor 2 --key_name oskey --image ea3ffba1-065e-483f-bfe2-c84184ee76be test1
[root@openstack ~]#nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
[root@openstack ~]#nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0

查看申请flating IP 列表
[root@openstack ~]#nova floating-ip-list

查看虚拟机
[root@openstack ~]#nova list

添加floating IP给虚拟机(id是虚拟机的ID,通过nova list获得)
[root@openstack ~]#nova add-floating-ip 7eb1d4b3-13fa-4e39-be17-3a27eb0db218 10.1.199.33

查看虚拟机的floating IP (nova list,就可以查看,需要等待1分钟)
[root@openstack ~]#nova list

ssh到虚拟机上 (ubuntu的虚拟机,默认的用户名是ubuntu,只能用密钥登陆)
[root@openstack ~]#ssh -i oskey.priv ubuntu@192.168.22.2

删除flating IP (ID就是虚拟机ID,通过 nova list 获得)
[root@openstack ~]#nova remove-floating-ip ID 10.1.199.33

删除虚拟机
[root@openstack ~]#nova delete ID

创建10G的volume
[root@openstack ~]#nova volume-create --display_name "test volume" 10

查看nova volume情况
[root@openstack ~]#nova volume-list

把volume添加到虚拟机上
( ID是虚拟机的id,后面的1,是volume的ID)添加完后可以通过 nova volume-list查看结果
[root@openstack ~]#nova volume-attach 7eb1d4b3-13fa-4e39-be17-3a27eb0db218 1 /dev/vdc

查看虚拟机里的volume情况(登陆虚拟机里)
[root@openstack ~]# cat /proc/partitions
major minor #blocks name
253 0 10485760 vda
253 1 10474380 vda1
253 16 20971520 vdb
253 32 10485760 vdc

格式化分区并挂载
[root@openstack ~]#mkfs.ext4 /dev/vdc
[root@openstack ~]#mkdir -p /mnt/volume
[root@openstack ~]#mount /dev/vdc /mnt/volume

删除volume
[root@openstack ~]#nova volume-detach VM_ID Volume_ID

创建snapshot ( 完成后可以通过 nova image-list 查看)
[root@openstack ~]#nova image-create 7eb1d4b3-13fa-4e39-be17-3a27eb0db218 "snapshot 1"

虚拟机重启,停止
[root@openstack ~]#nova suspend ac9e6a9f-58c3-47c3-9b4c-485aa421b8a8
[root@openstack ~]#nova resume ac9e6a9f-58c3-47c3-9b4c-485aa421b8a8
[root@openstack ~]#nova reboot ac9e6a9f-58c3-47c3-9b4c-485aa421b8a8

vnc
[root@openstack ~]#nova get-vnc-console myserver20 novnc