OpenStack 命令行速查表
這是可供參考的經常使用命令列表html
鏡像(glance)¶
列出您能夠訪問的鏡像網絡
$ openstack image list
刪除指定的鏡像ssh
$ openstack image delete IMAGE
描述一個指定的鏡像ide
$ openstack image show IMAGE
更新鏡像post
$ openstack image set IMAGE
上傳內核鏡像ui
$ openstack image create "cirros-threepart-kernel" \ --disk-format aki --container-format aki --public \ --file ~/images/cirros-0.3.5-x86_64-kernel
上傳RAM鏡像url
$ openstack image create "cirros-threepart-ramdisk" \ --disk-format ari --container-format ari --public \ --file ~/images/cirros-0.3.5-x86_64-initramfs
上傳第三方鏡像spa
$ 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
計算 (nova)¶
列出實例,覈實實例狀態
$ openstack server list
列出鏡像
$ openstack image list
Create a flavor named m1.tiny
$ openstack flavor create --ram 512 --disk 1 --vcpus 1 m1.tiny
列出規格類型
$ openstack flavor list
用類型和鏡像名稱(若是名稱惟一)來啓動雲主機
$ openstack server create --image IMAGE --flavor FLAVOR INSTANCE_NAME
$ openstack server create --image cirros-0.3.5-x86_64-uec --flavor m1.tiny \ MyFirstInstance
Log in to the instance (from Linux)
The ip command is available only on Linux. Using ip netns provides your environment a copy of the network stack with its own routes, firewall rules, and network devices for better troubleshooting.
# ip netns
# ip netns exec NETNS_NAME ssh USER@SERVER # ip netns exec qdhcp-6021a3b4-8587-4f9c-8064-0103885dfba2 \ ssh cirros@10.0.0.2
In CirrOS, the password for user cirros
is cubswin:)
. For any other operating system, use SSH keys.
Log in to the instance with a public IP address (from Mac)
$ ssh cloud-user@128.107.37.150
顯示實例詳細信息
$ openstack server show NAME
$ openstack server show MyFirstInstance
查看雲主機的控制檯日誌
$ openstack console log show MyFirstInstance
設置雲主機的元數據
$ nova meta volumeTwoImage set newmeta='my meta data'
建立一個實例快照
$ openstack image create volumeTwoImage snapshotOfVolumeImage
$ openstack image show snapshotOfVolumeImage
實例的暫停、掛起、中止、救援、調整規格、重建、重啓¶
暫停
$ openstack server pause NAME
$ openstack server pause volumeTwoImage
取消掛起
$ openstack server unpause NAME
掛起
$ openstack server suspend NAME
Unsuspend
$ openstack server resume NAME
關機
$ openstack server stop NAME
開始
$ openstack server start NAME
恢復
$ openstack server rescue NAME
$ openstack server rescue NAME --rescue_image_ref RESCUE_IMAGE
調整大小
$ openstack server resize NAME FLAVOR
$ openstack server resize my-pem-server m1.small $ openstack server resize --confirm my-pem-server1
重建
$ openstack server rebuild NAME IMAGE
$ openstack server rebuild newtinny cirros-qcow2
重啓
$ openstack server reboot NAME
$ openstack server reboot newtinny
將用戶數據和文件注入到實例
$ openstack server create --user-data FILE INSTANCE
$ openstack server create --user-data userdata.txt --image cirros-qcow2 \ --flavor m1.tiny MyUserdataInstance2
使用ssh鏈接到實例,查看``/var/lib/cloud``驗證文件是否成功注入
給實例注入一個密鑰對並經過密鑰對來訪問實例
建立祕鑰對
$ openstack keypair create test > test.pem $ chmod 600 test.pem
啓動實例
$ openstack server create --image cirros-0.3.5-x86_64 --flavor m1.small \ --key-name test MyFirstServer
使用ssh鏈接到實例
# ip netns exec qdhcp-98f09f1e-64c4-4301-a897-5067ee6d544f \ ssh -i test.pem cirros@10.0.0.4
管理安全組
在默認的安全組中,添加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
網絡 (neutron)¶
建立網絡
$ openstack network create NETWORK_NAME
建立子網
$ openstack subnet create --subnet-pool SUBNET --network NETWORK SUBNET_NAME
$ openstack subnet create --subnet-pool 10.0.0.0/29 --network net1 subnet1
塊存儲(cinder)¶
用於管理鏈接到實例的卷和卷快照。
建立一個新卷
$ openstack volume create --size SIZE_IN_GB NAME
$ openstack volume create --size 1 MyFirstVolume
啓動實例並將它連接到捲上
$ openstack server create --image cirros-qcow2 --flavor m1.tiny MyVolumeInstance
列出全部卷,注意卷狀態
$ openstack volume list
當實例爲正常狀態且卷爲可用狀態時,將卷鏈接到實例。
$ openstack server add volume INSTANCE_ID VOLUME_ID
$ openstack server add volume MyVolumeInstance 573e024d-5235-49ce-8332-be1576d323f8
在Xen Hypervisor能夠指定具體的設備名,而不使用自動分配的名稱,例如:
$ openstack server add volume --device /dev/vdb MyVolumeInstance 573e024d..1576d323f8
This is not currently possible when using non-Xen hypervisors with OpenStack.
登錄進實例以後管理卷組
列出存儲器
# fdisk -l
在捲上創建文件系統
# mkfs.ext3 /dev/vdb
建立一個掛載點
# mkdir /myspace
在掛載點掛載卷
# mount /dev/vdb /myspace
在捲上建立一個文件
# touch /myspace/helloworld.txt
# ls /myspace
卸載卷
# umount /myspace
對象存儲(Swift)¶
展現帳戶,容器以及對象的信息
$ swift stat
$ swift stat ACCOUNT $ swift stat CONTAINER $ swift stat OBJECT
列出容器
$ swift list