OpenStack一些常用命令整理。
配置 stack 用户
创建 stack 用户
# |
Source the admin credentials to gain access to admin-only CLI commands:$
source admin-openrc.sh
openstack相关
# |
glance相关
上传image(public)
$ glance add name="my-image" is_public=True|False disk_format=qcow2 container_format=ovf architecture=x86_64 < my-image.img |
查看image
glance image-list |
Set an image to public:
glance update [image-id] is_public=true |
rabbitmq 相关
rabbitmqctl list_queues |
nova相关
nova服务状态#
nova-manage service list
nova service-list
开启或者禁用服务nova-manage service enable|disable --host=host --service=nova-compute
- 虚拟机相关
创建密钥nova keypair-add oskey > oskey.priv
chmod 600 oskey.priv
查看虚拟机配置种类nova flavor-list
查看镜像nova image-list
创建虚拟机nova boot --flavor [flavor-id] --image [image-id] --key_name [key1] --security_groups [default] [instance-name]
查看虚拟机nova list
查看实例详细信息nova show [instance-name]
执行block_migrationnova live-migration --block_migrate [INSTANCE_ID] [TARGET_SERVER]
查看计算节点的所有实例nova-manage vm list | column -t
删除虚拟机nova delete [INSTANCE_ID]
创建snapshot ( 完成后可以通过 nova image-list 查看)nova image-create [INSTANCE_ID] "snapshot 1"
Take a snapshot from an instance but first commit the buffer cache to disk:#
sync
echo 3 | sudo tee /proc/sys/vm/drop_caches
nova image-create [INSTANCE_ID] [snapshot-name]
虚拟机重启,停止nova suspend [INSTANCE_ID]
nova resume [INSTANCE_ID]
nova reboot [INSTANCE_ID]
- 卷组相关
创建1G的volumenova volume-create --display_name "test volume" 1
查看nova volume情况
nova volume-list |
把volume添加到虚拟机上( ID是虚拟机的id,后面的1,是volume的ID)添加完后可以通过 nova volume-list查看结果
nova volume-attach [INSTANCE_ID] 1 /dev/vdc |
删除volumenova volume-detach [INSTANCE_ID] Volume_ID
- 网络相关
添加网络nova-manage network create --label vlan1 --fixed_range_v4 10.0.1.0/24 --num_networks 1 --network_size 256 --vlan 1
删除网络, 先从project分离再删除nova-manage project scrub projectname
nova-manage network delete [cidr]
查看网络nova-manage network list
添加floating IP范围nova-manage floating create --pool [my-pool] --ip_range 172.17.1.1/24
申请floating IPnova floating-ip-create [my-pool]
查看flating IPnova floating-ip-list
添加floating IP给虚拟机(ID就是虚拟机ID,通过 nova list 获得)nova add-floating-ip [INSTANCE_ID] [IP]
删除flating IP (ID就是虚拟机ID,通过 nova list 获得)nova remove-floating-ip [INSTANCE_ID] [IP]
- 安全组相关命令
查看安全组列表nova secgroup-list
nova secgroup-list-rules default
添加安全组nova secgroup-create web-server "Web server running"
添加规则到安全组nova secgroup-add-rule web-server tcp 80 80 0.0.0.0/0
添加规则,允许 ping 和 sshnova secgroup-add-rule web-server icmp -1 -1 0.0.0.0/0
nova secgroup-add-rule web-server tcp 22 22 0.0.0.0/0
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
- 下面是一个虚拟机的完整创建流程:
nova keypair-add oskey > oskey.priv
chmod 600 oskey.priv
nova flavor-list
nova image-list
nova boot --flavor 2 --key_name oskey --image ea3ffba1-065e-483f-bfe2-c84184ee76be demo
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
#ssh到虚拟机上
ssh -i oskey.priv cirros@192.168.22.2
#查询vnc信息
nova get-vnc-console myserver20 novnc
keystone相关
创建新用户keystone user-create --name [username] --tenant_id [tenant-id] --pass [password] --email [email] --enabled true
keystone user-get 7a98251d2efd4385bb06128d5f98086d |
查看keystone的用户keystone user-list
查看keystone endpointkeystone endpoint-list
查看keystone的rolekeystone role-list
查看keystone 服务keystone service-list
查看keystone租户keystone tenant-list
查看租户情况keystone tenant-get ID
查看keystone进程ps -ef | grep -i keystone-all
查看日志是否有错误grep ERROR /var/log/keystone/keystone.log
cinder相关
cinder service-list |
neutron相关
neutron subnet-list |