CentOS 7 KVM virtual machine actual combat

This paper is running environment:
uname -a
3.10.0-957.5.1.el7.x86_64 # 1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64 x86_64 x86_64 the GNU / Linux
CAT / etc / RedHat-Release
CentOS Linux Release 7.6. 1810 (Core)

Check if the hardware supports virtualization:
egrep "VMX | SVM" / proc / cpuinfo #vmx: SVM Intel: AMD

Installing the KVM and related tools:
yum install -y Bridge QEMU-KVM virt-install the libvirt-utils
lsmof | grep KVM # verify the installation
systemctl start libvirtd # libvirtd start service
systemctl status libvirtd # View libvirtd service startup state
systemctl is-enabled libvirtd # View libvirtd service autostart
systemctl enadble libvirtd # libvirtd service set to start automatically

Configure the bridge:
1, creating a bridge br0-the ifcfg:
the TYPE = Bridge
BOOTPROTO = static
IPV4_FAILURE_FATAL = NO
NAME = br0
the DEVICE = br0
ONBOOT = yes
IPADDR = 192.168.0.16
NETMASK = 255.255.255.0
GATEWAY = 192.168.0.1
DNS1 = 119.29. 29.29
DNS2 = 223.5.5.5
2, configure the binding-physical NIC eth0 the ifcfg:
the TYPE = Ethernet
BOOTPROTO = none
IPV4_FAILURE_FATAL = NO
NAME = eth0
the UUID = fe2685ec-266a-4bc8-a003-52198570a913
the DEVICE = eth0
the ONBOOT Yes =
the BRIDGE = BR0
3, restart the network services:
systemctl restart network.service
4, verify the results:
ip addr Show

Create a virtual machine:
1. Create a system installation ISO files and virtual machine images IMG file directory, and the system installation files into iso directory
mkdir -p / Home / iso / opt / Image
2, configure the firewall, open a VNC connection port
firewall --zone = public --add--cmd Port = 5900 / tcp --permanent
Firewall-cmd --reload
3, create a virtual machine:
QEMU-img the create -f qcow2 /opt/image/win2008.img 100 g # create IMG file
virt-install the Win2008 --disk /opt/image/win2008.img --network Bridge -n = br0 \
- OS-the Variant = win2k8r2 --cdrom /home/iso/cn_windows_server_2008_r2.iso \
--vnc --vncport 0.0.0.0 --vcpu --vnclisten = 5900 = 24 = 49152 - RAM
. 4, via a remote connection RealVNC virtual machine, the virtual machine to complete the installation of the system

xml copied to the corresponding directory of the target server. The following operation is performed on the target server.





















2, edit / etc / libvirt / qemu / <VM name> .xml, modify
<name> Win2008 </ name>
<UUID> 5284e097-373e-4e6e-85dB-ef5635240023 </ UUID>
Check:
<Disk type = ' File 'Device =' Disk '>
<Driver name =' QEMU 'type =' qcow2 '/>
<Source File =' / opt / Image / win2008.img '/>
<dev = target' HDA '= Bus' IDE' />
<address type = 'Drive' Controller = '0' Bus = '0' target = '0' unit = '0' />
</ Disk>
. 3, redefining the virtual machine
virsh define / etc / libvirt / qemu / <virtual machine name> .xml
. 4, boot, modified hostname, ip after the restart information
virsh start <VM name>
6, when virtual machines running Linux system configured to direct access from the host virtual machine console:
1, enter the virtual machine, modify / etc / default / GRUB:
GRUB_DISTRIBUTOR = "$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0,115200"
GRUB_DISABLE_RECOVERY="true"</pre>

2、更新启动文件,然后重启
     grub2-mkconfig -o /boot/grub2/grub.cfg
3、在宿主机上登录虚拟机,退出登录:Ctrl+]
    virsh console think8848-kvmbase

7, the system automatically enters the host virtual machine running
virsh autostart <VM name>

Guess you like

Origin blog.51cto.com/10248921/2400829