访问虚拟机
概述
参考:
我们可以通过多种方式与虚拟机进行交互:
- Cockpit # 基于 Web 的控制台
- Virt Manager 程序 # GUI 程序
- Virt Viewer 程序 # GUI 程序
- virsh console 子命令 # CLI 程序
- 众所周知的 ssh
Cockpit
参考:
- GitHub 项目,cockpit-project
- 官网
- 注意:
- RHEL 8 仍支持虚拟机管理器(virt-manager)应用程序,但已弃用。Web 控制台打算在后续版本中替代它。因此,建议您熟悉用于在 GUI 中管理虚拟化的 Web 控制台。详见:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_and_managing_virtualization/index#overview-of-virtual-machine-management-using-the-web-console_using-the-rhel-8-web-console-for-managing-vms
Cockpit 是一个基于 Web 的用于管理服务器的图形界面
安装 Cockpit
CentOS
yum install cockpit -y && yum install cockpit-machines -y
systemctl start cockpit && systemctl enable cockpit
Ubuntu
apt update
apt install -y cockpit cockpit-machines
其中 cockpit-machines 是 cockpit 的插件,用于为 cockpit 添加虚拟机管理功能。
使用 Cockpit
Cockpit 开箱即用,安装完成后直接访问 http://IP:9090,打开 web 界面,使用系统的用户和密码登陆即可。web 页面管理虚拟机,效果如图
使用虚拟机的串行控制台
参考:
使用 virsh console 命令,可以连接到虚拟机的串行控制台。
有两种方法可以开启虚拟机内的串行控制台
方法一:修改 grub 参数
在虚拟机上,编辑 /etc/default/grub 文件并将 console=ttyS0 添加到以 GRUB_CMDLINE_LINUX 开头的行中。
清除可能会阻止您更改生效的内核选项。
# grub2-editenv - unset kernelopts
重新载入 Grub 配置:
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-948.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-948.el7.x86_64.img
[...]
done
重启虚拟机。
方法二:启动 serial-getty 服务
在虚拟机上启动 serial-getty@.service 服务并在开启服务的时候指定一个终端。执行如下命令即可:systemctl enable serial-getty@ttyS0.service --now
访问远程虚拟化主机
参考:
当我们想要使用 libvirt 程序管理远程主机上的 VM 时,可以使用 -c qemu+ssh://root@HOST/system 语法管理远程宿主机上的虚拟机。效果如下:
~]# virsh -c qemu+ssh://root@172.19.42.201/system list
root@172.19.42.201's password:
Id Name State
----------------------------------------------------
1 node-1.bj-net running
反馈
此页是否对你有帮助?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.