openstack之kilo安装 常用命令

OpenStack一些常用命令整理。

配置 stack 用户

创建 stack 用户

#
groupadd stack
useradd -g stack -s /bin/bash -d /opt/stack -m stack
echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
su - stack

Source the admin credentials to gain access to admin-only CLI commands:

$
source admin-openrc.sh

openstack相关

#
openstack-status

glance相关

上传image(public)

$ glance add name="my-image" is_public=True|False disk_format=qcow2 container_format=ovf architecture=x86_64 < my-image.img
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

glance image-list
glance index
glance show ID

Set an image to public:

glance update [image-id] is_public=true

rabbitmq 相关

rabbitmqctl list_queues
rabbitmqctl status

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_migration

nova 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的volume

nova 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

删除volume

nova 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 IP

nova floating-ip-create [my-pool]

查看flating IP

nova 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 和 ssh

nova 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 user-password-update \
--pass new_passwd \
user_id

查看keystone的用户

keystone user-list

查看keystone endpoint

keystone endpoint-list

查看keystone的role

keystone 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
neutron port-list
neutron agent-list
neutron router-list

heat相关