Openstack中有時候虛擬機啟動不正常,這時可以通過查看虛擬機console log能得到一些有用的信息。
有這些方法可以查看或獲取虛擬機console log:
1)openstack控制台圖形界面(horizon):
進入虛擬機(Instance)列表界面,選中相應虛擬機,點擊Log頁面即可;或點擊右側的“View Full Log”查看完整的log。

2)在虛擬機所在的compute節點上找到log文件:
通過virsh dumpxml指令,找到如下關鍵段:
<console type='file'>
<source path='/var/lib/nova/instances/842d5f63-6c0f-4582-8237-076ccc29e759/console.log'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
再到相應的目錄下即可:
root@compute-1:~# cd /var/lib/nova/instances/842d5f63-6c0f-4582-8237-076ccc29e759
root@compute-1:/var/lib/nova/instances/842d5f63-6c0f-4582-8237-076ccc29e759# ls
console.log disk disk.config disk.info libvirt.xml
3)使用指令nova console-log,這是最便捷的方法:
如下所示,能看到通過DHCP成功獲取IP的信息:
root@controller:~# nova console-log test_vm68|more
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 4.4.0-28-generic (buildd@lcy01-13) (gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2.1) ) #47-Ubuntu S
MP Fri Jun 24 10:09:13 UTC 2016 (Ubuntu 4.4.0-28.47-generic 4.4.13)
[ 0.000000] Command line: LABEL=cirros-rootfs ro console=tty1 console=ttyS0
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: xstate_offset[3]: 960, xstate_sizes[3]: 64
[ 0.000000] x86/fpu: xstate_offset[4]: 1024, xstate_sizes[4]: 64
[ 0.000000] x86/fpu: xstate_offset[5]: 1088, xstate_sizes[5]: 64
[ 0.000000] x86/fpu: xstate_offset[6]: 1152, xstate_sizes[6]: 512
[ 0.000000] x86/fpu: xstate_offset[7]: 1664, xstate_sizes[7]: 1024
Starting network...
udhcpc (v1.23.2) started
Sending discover...
Sending select for 1.3.11.10...
Lease of 1.3.11.10 obtained, lease time 86400
順便提供通過vnc console用http訪問虛擬機的方法:
usage: nova get-vnc-console <server> <console-type>
Get a vnc console to a server.
Positional arguments:
<server> Name or ID of server.
<console-type> Type of vnc console ("novnc" or "xvpvnc").
1)獲取vnc console口的URL:
root@controller:~# nova get-vnc-console test01 novnc
+-------+----------------------------------------------------------------------------------------+
| Type | Url |
+-------+----------------------------------------------------------------------------------------+
| novnc | https://72.60.60.60:6080/vnc_auto.html?token=9253ac64-bfd1-4ed9-b7b1-35bfd371bd7a |
+-------+----------------------------------------------------------------------------------------+
2)在瀏覽器中輸入上述URL即可。
