我在用着桉树在 Ubuntu 10.04 上设置私有云。有时我无法通过 ssh 进入 VM 实例,我希望能够直接连接到 VM 实例的控制台。但是,默认情况下,这似乎无法通过 virsh 实现:
$ sudo virsh -c qemu:///system console i-486B085E
No console available for domain
是否有某种方法可以实现此功能,例如,通过改变 Eucalyptus 生成传递给 libvirt 的 XML 文件的方式?
以下是 Eucalyptus 生成的 libvirt.xml 文件:
$ cat /var/lib/eucalyptus/instances/admin/i-486B085E/libvirt.xml
<domain type='kvm'>
<name>i-486B085E</name>
<os>
<type>hvm</type>
<kernel>/var/lib/eucalyptus/instances//admin/i-486B085E/kernel</kernel>
<initrd>/var/lib/eucalyptus/instances//admin/i-486B085E/ramdisk</initrd>
<cmdline>root=/dev/sda1 console=ttyS0</cmdline>
</os>
<features>
<acpi/>
</features>
<memory>262144</memory>
<vcpu>1</vcpu>
<devices>
<disk type='file'>
<source file='/var/lib/eucalyptus/instances//admin/i-486B085E/disk'/>
<target dev='sda'/>
</disk>
<interface type='bridge'>
<source bridge='eucabr10'/>
<mac address='d0:0d:48:6B:08:5E'/>
<model type='e1000'/>
</interface>
<serial type="file">
<source path='/var/lib/eucalyptus/instances//admin/i-486B085E/console.log'/>
<target port='1'/>
</serial>
</devices>
</domain>
这是 virsh dumpxml 的输出:
$ sudo virsh dumpxml i-486B085E
<domain type='kvm' id='3'>
<name>i-486B085E</name>
<uuid>3b762376-4de1-f6ac-7327-9df520fa4862</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc-0.12'>hvm</type>
<kernel>/var/lib/eucalyptus/instances//admin/i-486B085E/kernel</kernel>
<initrd>/var/lib/eucalyptus/instances//admin/i-486B085E/ramdisk</initrd>
<cmdline>root=/dev/sda1 console=ttyS0</cmdline>
<boot dev='hd'/>
</os>
<features>
<acpi/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<source file='/var/lib/eucalyptus/instances//admin/i-486B085E/disk'/>
<target dev='sda' bus='scsi'/>
</disk>
<interface type='bridge'>
<mac address='d0:0d:48:6b:08:5e'/>
<source bridge='eucabr10'/>
<target dev='vnet0'/>
<model type='e1000'/>
</interface>
<serial type='file'>
<source path='/var/lib/eucalyptus/instances//admin/i-486B085E/console.log'/>
<target port='0'/>
</serial>
<console type='file'>
<source path='/var/lib/eucalyptus/instances//admin/i-486B085E/console.log'/>
<target port='0'/>
</console>
</devices>
<seclabel type='dynamic' model='apparmor'>
<label>libvirt-3b762376-4de1-f6ac-7327-9df520fa4862</label>
<imagelabel>libvirt-3b762376-4de1-f6ac-7327-9df520fa4862</imagelabel>
</seclabel>
</domain>
以下是最终调用的完整 KVM 命令行:
/usr/bin/kvm -S -M pc-0.12 -enable-kvm -m 256 -smp 1 -name i-486B085E -uuid 3b762376-4de1-f6ac-7327-9df520fa4862 -nographic -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/i-486B085E.monitor,server,nowait -monitor chardev:monitor -boot c -kernel /var/lib/eucalyptus/instances//admin/i-486B085E/kernel -initrd /var/lib/eucalyptus/instances//admin/i-486B085E/ramdisk -append root=/dev/sda1 console=ttyS0 -drive file=/var/lib/eucalyptus/instances//admin/i-486B085E/disk,if=scsi,index=0,boot=on -net nic,macaddr=d0:0d:48:6b:08:5e,vlan=0,model=e1000,name=e1000.0 -net tap,fd=55,vlan=0,name=tap.0 -chardev file,id=serial0,path=/var/lib/eucalyptus/instances//admin/i-486B085E/console.log -serial chardev:serial0 -parallel none -usb
答案1
随着 Eucalyptus 3 及更高版本的出现,这种情况似乎有所改变 - 这是一个更新的解决方案,以避免任何人遭受我今天早上所经历的烦恼。
结合以下两个链接中的信息:http://gobertelli.blogspot.co.uk/2012/08/customize-instance-libvirt-environment.html https://www.redhat.com/archives/libvirt-users/2012-May/msg00048.html
在您的节点控制器上,编辑 /etc/eucalyptus/libvirt.xsl 使其看起来像这样:
<xsl:choose>
<xsl:when test="(/instance/hypervisor/@type = 'kvm' or /instance/hypervisor/@type = 'qemu')">
<serial type="pty">
<target port="0"/>
</serial>
</xsl:when>
<xsl:when test="/instance/hypervisor/@type = 'xen' and /instance/os/@platform = 'windows'">
<serial type="pty">
<source path="/dev/pts/3"/>
<target port="0"/>
</serial>
<input type="tablet" bus="usb"/>
<input type="mouse" bus="ps2"/>
</xsl:when>
<xsl:when test="/instance/hypervisor/@type = 'xen' and /instance/backing/root/@type = 'ebs'">
<console type="pty"/>
<target port="0"/>
</xsl:when>
</xsl:choose>
<!-- <graphics type='vnc' port='-1' autoport='yes' keymap='en-us' -->
</devices>
</domain>
</xsl:template>
将串行和控制台定义都更改为类型“pty”和目标“0”。
停止并启动任何正在运行的虚拟机,然后您应该能够像往常一样通过“virsh console”进入它们。
答案2
我明白了...您需要编辑 /usr/share/eucalyptus/gen_kvm_libvirt_xml 文件。以下是差异:
--- /usr/share/eucalyptus/gen_kvm_libvirt_xml.bak 2010-09-28 14:54:20.259266161 -0400
+++ /usr/share/eucalyptus/gen_kvm_libvirt_xml 2010-09-28 15:01:25.269265897 -0400
@@ -109,9 +109,9 @@
<mac address='PRIVMACADDR'/>
<model type='e1000'/>
</interface>
- <serial type="file">
- <source path='BASEPATH/console.log'/>
- <target port='1'/>
+ <serial type='pty'>
+ <source path='/dev/pts/2'/>
+ <target port='0'/>
</serial>
</devices>
</domain>