OpenStack:常见问题记录

1. 基础服务连接问题

1.1 libvirt 连接失败

错误信息

1
2
error: failed to connect to the hypervisor
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory

解决方案

1
2
3
4
5
6
7
8
9
10
# Ubuntu/Debian 系统
sudo apt install qemu qemu-kvm libvirt-clients libvirt-daemon-system virtinst bridge-utils

# CentOS/RHEL 系统
sudo yum install qemu-kvm libvirt virt-install bridge-utils

# 启动服务
sudo systemctl enable libvirtd
sudo systemctl start libvirtd
sudo systemctl status libvirtd

2. 虚拟机控制台问题

2.1 virsh console 卡住

解决方法

1
2
3
4
5
6
# 在虚拟机内部执行:
echo "ttyS0" >> /etc/securetty
echo "S0:12345:respawn:/sbin/agetty ttyS0 115200" >> /etc/inittab
echo "console=ttyS0" >> /boot/grub/grub.conf # CentOS 6
echo "GRUB_CMDLINE_LINUX=\"console=tty0 console=ttyS0,115200n8\"" >> /etc/default/grub # CentOS 7+
grub2-mkconfig -o /boot/grub2/grub.cfg # CentOS 7+

3. 安装与内核问题

3.1 DFN error:Error in POSTTRANS scriptlet in rpm package kernel-core

解决方法

  1. 重新安装操作系统
  2. 在手动分区时,确保:
    • /boot 分区至少 300MB
    • 文件系统类型为 ext4

4. libvirt 内部错误

4.1 权限拒绝错误

错误信息

1
2
3
Original error from libvirt: internal error: process exited while connecting to monitor:
qemu-kvm: -chardev socket,id=charserial0,path=/tmp/libguestfsWLXpOT/console.sock:
Failed to connect socket /tmp/libguestfsWLXpOT/console.sock: Permission denied

解决方案

1
2
3
4
5
6
# 设置后端直接访问
export LIBGUESTFS_BACKEND=direct

# 或者永久设置
echo "export LIBGUESTFS_BACKEND=direct" >> ~/.bashrc
source ~/.bashrc

5. 镜像制作问题

5.1 内存分配失败

错误信息

1
qemu unexpectedly closed the monitor: Cannot set up guest memory 'pc.ram': Cannot allocate memory

解决方法

1
2
3
4
5
6
# 临时解决方案
sysctl vm.overcommit_memory=1

# 永久解决方案
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl -p

6. 网络配置问题

6.1 虚拟机网络不通

排查步骤

  1. 检查虚拟网桥状态:

    1
    2
    brctl show
    ip a
  2. 验证防火墙规则:

    1
    iptables -L -n -v
  3. 检查libvirt网络定义:

    1
    2
    virsh net-list --all
    virsh net-dumpxml default

7. 虚拟机管理命令参考

7.1 常用命令

命令 功能
virsh list --all 列出所有虚拟机
virsh start <vm-name> 启动虚拟机
virsh shutdown <vm-name> 正常关闭虚拟机
virsh destroy <vm-name> 强制停止虚拟机
virsh edit <vm-name> 编辑虚拟机配置
virsh console <vm-name> 连接虚拟机控制台
virsh vncdisplay <vm-name> 查看VNC显示端口

8. 日志查看

8.1 关键日志位置

日志文件 描述
/var/log/libvirt/qemu/<vm-name>.log 单个虚拟机日志
/var/log/libvirt/libvirtd.log libvirt主服务日志
/var/log/messages/var/log/syslog 系统日志
/var/log/qemu-kvm.log QEMU/KVM日志

8.2 实时日志监控

1
2
3
4
5
# 跟踪libvirt日志
tail -f /var/log/libvirt/libvirtd.log

# 跟踪特定虚拟机日志
tail -f /var/log/libvirt/qemu/<vm-name>.log