openstack的云主机相关命令

Posted jks212454

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openstack的云主机相关命令相关的知识,希望对你有一定的参考价值。

一、环境介绍

openstack:RHEL7OSP-6.0

二、查看云主机相关信息

1.查看用户云主机列表

[root@controller ~]# nova --os-username user --os-tenant-name huawei01 --os-auth-url=http://192.168.9.102:5000/v2.0/  --os-password redhat  list
+--------------------------------------+---------+---------+------------+-------------+-----------------------------------+
| ID                                   | Name    | Status  | Task State | Power State | Networks                          |
+--------------------------------------+---------+---------+------------+-------------+-----------------------------------+
| 1d8d1b63-5720-4425-9044-e56ebf3914db | mysql10 | SHUTOFF | -          | Shutdown    | vpc=192.168.120.102, 192.168.9.61 |
+--------------------------------------+---------+---------+------------+-------------+-----------------------------------+
[root@controller ~]# 

2.查看用户的云硬盘信息

[root@controller ~]# cinder --os-username user --os-tenant-name huawei01 --os-auth-url=http://192.168.9.102:5000/v2.0/  --os-password redhat  list
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
|                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| 7de89cc2-7a95-40cd-a3f9-5a3c383b2e65 | available |   disk_01    |  5   |    iscsi    |  false   |             |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
[root@controller ~]# 

3.查看用户的router信息

[root@controller ~]# neutron router-list --os-username user --os-tenant-name huawei01 --os-auth-url=http://192.168.9.102:5000/v2.0/  --os-password redhat  
+--------------------------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                   | name     | external_gateway_info                                                                                                                                                                    |
+--------------------------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| b0b583f4-52b6-49d7-a82a-c76994d33502 | route010 | "network_id": "7af32ea1-517f-4465-8a5c-1cd5c0f352bc", "enable_snat": true, "external_fixed_ips": ["subnet_id": "37e3ff01-fcdd-4e1b-9953-69b406249547", "ip_address": "192.168.9.60"] |
+--------------------------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@controller ~]# 

4.查看用户的子网信息

[root@controller ~]# neutron subnet-list  --os-username user --os-tenant-name huawei01 --os-password redhat --os-auth-url=http://192.168.9.102:5000/v2.0/ 
+--------------------------------------+------------+------------------+------------------------------------------------------+
| id                                   | name       | cidr             | allocation_pools                                     |
+--------------------------------------+------------+------------------+------------------------------------------------------+
| 37e3ff01-fcdd-4e1b-9953-69b406249547 | it_network | 192.168.9.0/24   | "start": "192.168.9.60", "end": "192.168.9.80"     |
| 35b7a77a-64dd-4568-ad0a-26b9d1488326 | it_net     | 192.168.120.0/24 | "start": "192.168.120.1", "end": "192.168.120.253" |
+--------------------------------------+------------+------------------+------------------------------------------------------+
[root@controller ~]# 

5.查看用户的安全组信息

[root@controller ~]# neutron  security-group-list  --os-username user --os-tenant-name huawei01 --os-password redhat --os-auth-url=http://192.168.9.102:5000/v2.0/ 
+--------------------------------------+---------+-------------+
| id                                   | name    | description |
+--------------------------------------+---------+-------------+
| 2e4757f2-a7c1-4d99-a16e-8924009c2e9c | default | default     |
| 331cedb1-653f-42c1-8af8-f79332e3a701 | sg01    | sg01        |
+--------------------------------------+---------+-------------+
[root@controller ~]# 

6.查看镜像相关信息

[root@controller images(keystone_user)]# glance image-list
+--------------------------------------+-----------------+-------------+------------------+-----------+--------+
| ID                                   | Name            | Disk Format | Container Format | Size      | Status |
+--------------------------------------+-----------------+-------------+------------------+-----------+--------+
| e27e36f2-7919-4ae5-a0aa-4779a2ef96de | Centos7.1_64bit | qcow2       | bare             | 356777984 | active |
+--------------------------------------+-----------------+-------------+------------------+-----------+--------+
[root@controller images(keystone_user)]# 

三、直接在用户环境中查询相关信息

1.查询云主机信息

[root@controller ~(keystone_user)]# nova list
+--------------------------------------+---------+---------+------------+-------------+-----------------------------------+
| ID                                   | Name    | Status  | Task State | Power State | Networks                          |
+--------------------------------------+---------+---------+------------+-------------+-----------------------------------+
| 1d8d1b63-5720-4425-9044-e56ebf3914db | mysql10 | SHUTOFF | -          | Shutdown    | vpc=192.168.120.102, 192.168.9.61 |
+--------------------------------------+---------+---------+------------+-------------+-----------------------------------+
[root@controller ~(keystone_user)]# 

2.查询云硬盘信息

[root@controller ~(keystone_user)]# cinder list
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
|                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| 7de89cc2-7a95-40cd-a3f9-5a3c383b2e65 | available |   disk_01    |  5   |    iscsi    |  false   |             |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
[root@controller ~(keystone_user)]# 

3.查询路由器信息

[root@controller ~(keystone_user)]# neutron router-list
+--------------------------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                   | name     | external_gateway_info                                                                                                                                                                    |
+--------------------------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| b0b583f4-52b6-49d7-a82a-c76994d33502 | route010 | "network_id": "7af32ea1-517f-4465-8a5c-1cd5c0f352bc", "enable_snat": true, "external_fixed_ips": ["subnet_id": "37e3ff01-fcdd-4e1b-9953-69b406249547", "ip_address": "192.168.9.60"] |
+--------------------------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@controller ~(keystone_user)]# 

4.查询网络节点信息

[root@controller ~(keystone_user)]# ip netns ls
qdhcp-14d1dc89-776f-44eb-8044-5e54af6b42fe
qrouter-b0b583f4-52b6-49d7-a82a-c76994d33502
[root@controller ~(keystone_user)]# 

5.查询路由器防火墙规则信息

[root@controller ~(keystone_admin)]# source keystonerc_user 
[root@controller ~(keystone_user)]# ip netns ls
qdhcp-14d1dc89-776f-44eb-8044-5e54af6b42fe
qrouter-b0b583f4-52b6-49d7-a82a-c76994d33502
[root@controller ~(keystone_user)]# ip netns exec qrouter-b0b583f4-52b6-49d7-a82a-c76994d33502  iptables -t nat -nL
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
neutron-l3-agent-PREROUTING  all  --  0.0.0.0/0            0.0.0.0/0           

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
neutron-l3-agent-OUTPUT  all  --  0.0.0.0/0            0.0.0.0/0           

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
neutron-l3-agent-POSTROUTING  all  --  0.0.0.0/0            0.0.0.0/0           
neutron-postrouting-bottom  all  --  0.0.0.0/0            0.0.0.0/0           

Chain neutron-l3-agent-OUTPUT (1 references)
target     prot opt source               destination         
DNAT       all  --  0.0.0.0/0            192.168.9.61         to:192.168.120.102

Chain neutron-l3-agent-POSTROUTING (1 references)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ! ctstate DNAT

Chain neutron-l3-agent-PREROUTING (1 references)
target     prot opt source               destination         
REDIRECT   tcp  --  0.0.0.0/0            169.254.169.254      tcp dpt:80 redir ports 9697
DNAT       all  --  0.0.0.0/0            192.168.9.61         to:192.168.120.102

Chain neutron-l3-agent-float-snat (1 references)
target     prot opt source               destination         
SNAT       all  --  192.168.120.102      0.0.0.0/0            to:192.168.9.61

Chain neutron-l3-agent-snat (1 references)
target     prot opt source               destination         
neutron-l3-agent-float-snat  all  --  0.0.0.0/0            0.0.0.0/0           
SNAT       all  --  192.168.120.0/24     0.0.0.0/0            to:192.168.9.60

Chain neutron-postrouting-bottom (1 references)
target     prot opt source               destination         
neutron-l3-agent-snat  all  --  0.0.0.0/0            0.0.0.0/0           
[root@controller ~(keystone_user)]# 

四、管理权限下查询

1.查询私有云所有用户

[root@controller ~(keystone_admin)]# keystone user-list 
+----------------------------------+------------+---------+----------------------+
|                id                |    name    | enabled |        email         |
+----------------------------------+------------+---------+----------------------+
| f199c9647c0640ce9026b028208322e4 |   admin    |   True  |    root@localhost    |
| 72b20a1d097b440fbc2e78e50d179492 | ceilometer |   True  | ceilometer@localhost |
| 79ed6e09859b45adabd9cfe224f08cc3 |   cinder   |   True  |   cinder@localhost   |
| c376ec183b914448961d29b36278dfb0 |   glance   |   True  |   glance@localhost   |
| add2c05800d44ef4b182525d3ca0fe47 |  neutron   |   True  |  neutron@localhost   |
| 4828e19232634e388d2246d03243aa4f |    nova    |   True  |    nova@localhost    |
| 29e96756e0494aa4ac3bfbc4298ab3b5 |   swift    |   True  |   swift@localhost    |
| 7bc5356de3854f6e8b2e9ff16f001d65 |    user    |   True  |     user@qq.com      |
+----------------------------------+------------+---------+----------------------+
[root@controller ~(keystone_admin)]# 

2.查看租户信息

[root@controller ~(keystone_admin)]# keystone tenant-list
+----------------------------------+----------+---------+
|                id                |   name   | enabled |
+----------------------------------+----------+---------+
| 284089db6b6f45e995b0cc9958d476c6 |  admin   |   True  |
| a00aa09c6c5d4c0488896f08f354ea8d | huawei01 |   True  |
| 88f54bcc11334644a8bb7c735ab36a99 | services |   True  |
+----------------------------------+----------+---------+
[root@controller ~(keystone_admin)]# 

3.查询镜像信息

[root@controller ~(keystone_admin)]# glance image-list
+--------------------------------------+-----------------+-------------+------------------+-----------+--------+
| ID                                   | Name            | Disk Format | Container Format | Size      | Status |
+--------------------------------------+-----------------+-------------+------------------+-----------+--------+
| e27e36f2-7919-4ae5-a0aa-4779a2ef96de | Centos7.1_64bit | qcow2       | bare             | 356777984 | active |
+--------------------------------------+-----------------+-------------+------------------+-----------+--------+
[root@controller ~(keystone_admin)]# 

4.查询事件信息

[root@controller ~(keystone_admin)]# ceilometer event-list
+------------+------------+-----------+--------+
| Message ID | Event Type | Generated | Traits |
+------------+------------+-----------+--------+
+------------+------------+-----------+--------+

五、查看镜像存储位置

1.查看镜像配置文件

[root@controller ~(keystone_user)]# grep ^[a-z] /etc/glance/glance-api.conf 
verbose=True
debug=False
bind_host=0.0.0.0
bind_port=9292
log_file=/var/log/glance/api.log
backlog=4096
workers=2
show_image_direct_url=False
use_syslog=False
registry_host=0.0.0.0
registry_port=9191
registry_client_protocol=http
notification_driver = messaging
rabbit_host=192.168.9.102
rabbit_port=5672
rabbit_use_ssl=False
rabbit_userid=guest
rabbit_password=guest
rabbit_virtual_host=/
rabbit_notification_exchange=glance
rabbit_notification_topic=notifications
image_cache_dir=/var/lib/glance/image-cache
rabbit_ha_queues=False
rabbit_hosts=192.168.9.102:5672
amqp_durable_queues=False
log_dir=/var/log/glance
os_region_name=RegionOne
connection=mysql://glance:a28c5f50ba71489d@192.168.9.102/glance
idle_timeout=3600
admin_tenant_name=services
admin_user=glance
admin_password=f5535e97fe8e4a97
auth_port=35357
auth_host=192.168.9.102
auth_protocol=http
auth_uri=http://192.168.9.102:5000/
flavor=keystone
[root@controller ~(keystone_user)]# 

2、过滤镜像存放位置信息

[root@controller ~(keystone_user)]# grep ^[a-z] /etc/glance/glance-api.conf |grep image
show_image_direct_url=False
image_cache_dir=/var/lib/glance/image-cache
[root@controller ~(keystone_user)]# 

3.查看镜像文件

[root@controller ~(keystone_user)]# cd /var/lib/glance/images/
[root@controller images(keystone_user)]# ll
total 348416
-rw-r----- 1 glance glance 356777984 Nov 18 21:49 e27e36f2-7919-4ae5-a0aa-4779a2ef96de
[root@controller images(keystone_user)]# ll -h
total 341M
-rw-r----- 1 glance glance 341M Nov 18 21:49 e27e36f2-7919-4ae5-a0aa-4779a2ef96de
[root@controller images(keystone_user)]# 

以上是关于openstack的云主机相关命令的主要内容,如果未能解决你的问题,请参考以下文章

如何使用SSH连接OpenStack上的云主机,sshopenstack

openstack安装配置—— dnshboard安装配置

用OpenStack搭建简单的云平台并启动云主机

python开发云主机类型管理脚本

Docker架构:安装与基本命令

openstack——使用命令行发放云主机