KVM | centos 安装 window 虚拟机
环境: CENTOS 7.3
1. 准备
1.1 检查是否支持虚拟化
cat /proc/cpuinfo | egrep 'vmx|svm'
要求结果中返回相关字段
1.2 关闭 selinux
vi /etc/sysconfig/selinux
要求SELINUX=disabled
2. 安装
yum -y install qemu-kvm qemu-kvm-tools
yum -y install libvirt python-virtinst libvirt-python virt-manager libguestfs-tools bridge-utils virt-install
2.1 加载 KVM
lsmod | grep kvm
kvm_intel 170181 0
kvm 554609 1 kvm_intel
irqbypass 13503 1 kvm
2.2 启动 KVM
systemctl start libvirtd.service
systemctl enable libvirtd.service
systemctl status libvirtd
systemctl is-enabled libvirtd
2.3 搭建网桥
将原有网卡的配置备份一份,然后进行修改
物理网卡的配置ifcfg-eth0
DEVICE=eth0
BRIDGE=br0 #指向网桥br0
ONBOOT=yes
TYPE=Ethernet
ifcfg-br0网卡配置
TYPE=Bridge
DEVICE=br0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.24.18.151
GATEWAY=10.24.18.254
NETMASK=255.255.255.128
因为我这是同时连接了2个网段,因此还会设置eth2和br2,区别就是,网关只能在一个口上设置。
systemctl restart network.service
后即可。
brctl show
可以看到网桥名字
2.4 安装 VNC 环境
yum -y install tigervnc tigervnc-server
virt-install --name $name --ram $ram --vcpus=$cpu --disk path=$img,size=$sizeG --network bridge=$eth --os-type=windows --os-variant=$os --cdrom $iso --vnclisten=$ip --vncport=$port --vnc
--name: 虚拟机名称
--ram:虚拟机内存
--vcpus:虚拟机 CPU 个数
--cdrom:从本地安装
--disk: 生成的磁盘文件路径,以及磁盘大小
--network:网络模式,默认为 nat
或直接拷贝现有的配置文件/etc/libvirt/qemu/
目录下xml文件。
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit win8_8_200_6902
or other application using the libvirt API.
-->
<domain type='kvm'>
<name>win8_8_200_wx_3</name>
<uuid>29420437-571d-4965-7c54-b27d3311b95a</uuid> # 有多个node的话要不同的值
<memory>8388608</memory>
<currentMemory>8388608</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type> #支持的服务器类型可用命令查看
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator> # 这位实际的位置,默认是在此目录
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/data/iso/win8_8.img'/> # 镜像包位置
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/data/iso/win8_8.img'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='bridge'>
<mac address='60:f1:8a:30:27:10'/> # 这必须注意,MAC地址不能和机器上的地址相同
<source bridge='br0'/> # 否则会有环路报警,可随意写个不同的即可
<target dev='vnet0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x00' function='0x0'/> # 不同网口slot不同
</interface>
<interface type='bridge'>
<mac address='60:f1:8a:30:27:11'/> # 同上
<source bridge='br2'/>
<target dev='vnet1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='6901' autoport='no' listen='10.24.18.151'> # vnc连接监控端口
<listen type='address' address='10.24.18.151'/>
</graphics>
<video>
<model type='vga' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</memballoon>
</devices>
</domain>
virsh list --all
列出所有虚拟机
# virsh list --all
Id Name State
----------------------------------------------------
3 win_2008 running
5 win8_8_200 running
然后就可以通过vnc viewer来远程访问这个window了,进去之后配置网卡等或管理BMC
virsh shutdown win8_8_200
用于关闭
virsh start win8_8_200
用于启动
virsh destroy win8
: 销毁虚拟机
virsh undefine win_2008
从列表中删除
参考
https://github.com/jaywcjlove/handbook/blob/master/CentOS/CentOS7安装KVM虚拟机详解.md