Bootstrap

OpenStack学习笔记之一:命令行基本操作

二、OpenStack命令行管理

1. 常用命令及基本操作

1.1 命令帮助

不知道命令的解决办法:

[root@openstack ~(keystone_bruce)]# glance list
usage: glance [--version] [-d] [-v] [--get-schema] [--timeout TIMEOUT]
              [--no-ssl-compression] [-f] [--os-image-url OS_IMAGE_URL]
              [--os-image-api-version OS_IMAGE_API_VERSION]
              [--profile HMAC_KEY] [-k] [--os-cert OS_CERT]
              [--cert-file OS_CERT] [--os-key OS_KEY] [--key-file OS_KEY]
              [--os-cacert <ca-certificate-file>] [--ca-file OS_CACERT]
              [--os-username OS_USERNAME] [--os-user-id OS_USER_ID]
              [--os-user-domain-id OS_USER_DOMAIN_ID]
              [--os-user-domain-name OS_USER_DOMAIN_NAME]
              [--os-project-id OS_PROJECT_ID]
              [--os-project-name OS_PROJECT_NAME]
              [--os-project-domain-id OS_PROJECT_DOMAIN_ID]
              [--os-project-domain-name OS_PROJECT_DOMAIN_NAME]
              [--os-password OS_PASSWORD] [--os-tenant-id OS_TENANT_ID]
              [--os-tenant-name OS_TENANT_NAME] [--os-auth-url OS_AUTH_URL]
              [--os-region-name OS_REGION_NAME]
              [--os-auth-token OS_AUTH_TOKEN]
              [--os-service-type OS_SERVICE_TYPE]
              [--os-endpoint-type OS_ENDPOINT_TYPE]
              <subcommand> ...
glance: error: argument <subcommand>: invalid choice: u'list' (choose from 'image-create', 'image-delete', 'image-download', 'image-list', 'image-show', 'image-update', 'member-create', 'member-delete', 'member-list', 'help')

查找某一条命令以及使用方法:

[root@openstack ~(keystone_bruce)]# glance --help |grep li
Command-line interface to the OpenStack Images API.
    image-list          List images you can access.
    member-list         Describe sharing permissions by image or tenant.
                        performance profiling of operation. This key should be
                        profiling will not be triggered even if osprofiler is
  -k, --insecure        Explicitly allow glanceclient to perform "insecure
  --os-key OS_KEY       Path of client key to use in SSL connection. This
[root@openstack ~(keystone_bruce)]# glance image-list
+--------------------------------------+---------------+-------------+------------------+-----------+--------+
| ID                                   | Name          | Disk Format | Container Format | Size      | Status |
+--------------------------------------+---------------+-------------+------------------+-----------+--------+
| 9ded416e-e660-470b-9275-b3d96c9c8754 | CentOS7-64bit | qcow2       | bare             | 356777984 | active |
+--------------------------------------+---------------+-------------+------------------+-----------+--------+

# 查询命令的使用

[root@openstack ~(keystone_bruce)]# nova help delete
usage: nova delete <server> [<server> ...]

Immediately shut down and delete specified server(s).

Positional arguments:
  <server>  Name or ID of server(s).

1.2 查看命令

查看运行的服务

[root@openstack ~(keystone_admin)]# openstack-service status
neutron-dhcp-agent (pid 4243) is active
neutron-l3-agent (pid 4242) is active
neutron-metadata-agent (pid 1573) is active
neutron-openvswitch-agent (pid 4244) is active
neutron-server (pid 1572) is active
openstack-ceilometer-alarm-evaluator (pid 1630) is active
openstack-ceilometer-alarm-notifier (pid 1625) is active
...

查看云服务器在哪台宿主机上(只能在管理员账号上看)

[root@openstack ~(keystone_admin)]# nova list --all-tenants
+--------------------------------------+-------+---------+------------+-------------+---------------------------------------+
| ID                                   | Name  | Status  | Task State | Power State | Networks                              |
+--------------------------------------+-------+---------+------------+-------------+---------------------------------------+
| 3c33a084-a32f-4cc7-99ae-17aaa1b8dfdb | web01 | SHUTOFF | -          | Shutdown    | private=192.168.119.2, 192.168.19.152 |
+--------------------------------------+-------+---------+------------+-------------+---------------------------------------+

[root@openstack ~(keystone_admin)]# nova show 3c33a084-a32f-4cc7-99ae-17aaa1b8dfdb
+--------------------------------------+----------------------------------------------------------+
| Property                             | Value                                                    |
+--------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                   |
| OS-EXT-AZ:availability_zone          | nova                                                     |
| OS-EXT-SRV-ATTR:host                 | openstack                                                |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | openstack                                                |
| OS-EXT-SRV-ATTR:instance_name        | instance-00000003                                        |
| OS-EXT-STS:power_state               | 4                                                        |
| OS-EXT-STS:task_state                | -                                                        |
| OS-EXT-STS:vm_state                  | stopped                                                  |
| OS-SRV-USG:launched_at               | 2023-07-31T15:43:51.000000                               |
| OS-SRV-USG:terminated_at             | -                                                        |
| accessIPv4                           |                                                          |
| accessIPv6                           |                                                          |
| config_drive                         |                                                          |
| created                              | 2023-07-31T15:43:35Z                                     |
| flavor                               | rhel.little (7a063e20-6b58-4fe8-be10-39801a4cd9f9)       |
| hostId                               | 396967f512d04e61ce25745058b1518b0522ac949ae6c50399fc9ae9 |
| id                                   | 3c33a084-a32f-4cc7-99ae-17aaa1b8dfdb                     |
| image                                | rhel7-64bit (37cf0b4b-4911-4763-96bb-3e539b8f8b8a)       |
| key_name                             | key001                                                   |
| metadata                             | {}                                                       |
| name                                 | web01                                                    |
| os-extended-volumes:volumes_attached | []                                                       |
| private network                      | 192.168.119.2, 192.168.19.152                            |
| security_groups                      | SG01                                                     |
| status                               | SHUTOFF                                                  |
| tenant_id                            | 668b9defbdf04ce3aeca8bae0e451e13                         |
| updated                              | 2023-08-01T09:11:45Z                                     |
| user_id                              | 67dc3389c42648298bcabb7b60290ac7                         |
+--------------------------------------+----------------------------------------------------------+

Linux排错思路

重现错误,实时查看日志的新增内容(前提是你知道哪个组件出了问题),例如创建云磁盘失败时:

[root@openstack cinder]# tail -f * |grep -iE -A3 -B3 '(err|warn)' 
# -f 		实时显示最新产生的日志文件
# *		  代表文件夹下面所有的日志文件
# grep -iE	过滤关键字,-i选项忽略大小写,-E给出两个选项,任一都可以
# -A3 -B3	关键字前后三行都显示出来,可能会有有用信息

1.3 查看OpenStack版本

OpenStack是不提供版本查看的命令,需要查看就只能曲线救国,先查看某一个组件的版本,比如nova

[root@openstack ~(keystone_admin)]# nova --version
2.20.0

OpenStack官网查看,发现是juno版本的OpenStack

;