Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and run KVM in CentOS6

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to install and run KVM in CentOS6, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

Hardware enables virtualization support

Virtualization, which is generally supported by CPU, can be enabled in BIOS. About how to turn on the server, you can google on your own. I use my personal book to play KVM.

My hardware configuration: the company's loser book (DELL Inspiron14, i5-3337U, 8G, 500G, 100G ext3 partition of the hard drive, NTFS partition) + CentOS6.5 (please refer to this article installation and basic settings: CentOS installation and basic settings. I chose Development Enviroment during installation, and installed the corresponding virtualized package, you can decide by yourself)

Use the following command to confirm whether the current machine supports virtualization, and if there is an output, it supports it, otherwise it does not. Among them: vmx flag bit represents Intel VT virtualization technology, svm flag bit represents AMD-V virtualization technology.

Grep-E 'vmx | svm' / proc/cpuinfo

Here is my output, which shows that it is Intel VT virtualization technology.

[mwu@morgan local] $grep-E 'vmx | svm' / proc/cpuinfo flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi Flexpriority ept vpid fsgsbase smep ermsflags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep ermsflags: fpu Vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep ermsflags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca Cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms installation and configuration of KVM

KVM and virtualization can be installed at installation time, or later.

Installation process

Because KVM is not compatible with Xen, make sure that Linux is not running a Kernel of Xen, which can be detected with the uname-a command. If you find an output like "2.6.18-164.el5Xen", you need to stop the Xen Kernel first.

Install the KVM software:

Yum install kvm

Install Virtualization Management Pack

Yum install virt-manager libvirt libvirt-python python-virtinst

Configuration process

Load the KVM module

Modprobe kvm

Load chip-related KVM modules

Modprobe kvm-amd (svm flag bit) modprobe kvm-intel (vmx flag bit)

Verify that the module is loaded successfully

[root@morgan local] # lsmod | grep kvmkvm_intel 54285 0 kvm 333172 1 kvm_intel

Turn on the libvirtd backend service and

[root@morgan local] # / etc/init.d/libvirtd startStarting libvirtd daemon: [OK]

Set the libvirtd service to start automatically

Chkconfig libvirtd on

Ensure that the default virtual network is working properly. The default isolated virtual network has a virtual bridge, virbr0, with 192.168.122.x as its subnet by default. The host machine, that is, the IP address of the machine running the libvirtd service is 192.168.122.1, and you can set its IP during or after installing the system in the guest virtual machine. Verify the operation of the virtual bridge device, similar to the following:

[root@morgan local] # ifconfig virbr0virbr0 Link encap:Ethernet HWaddr 52:54:00:94:70:F4 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:5 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 Txqueuelen:0 RX bytes:0 (0.0b) TX bytes:290 (290.0 b)

Configure the network

You can use the default network configuration or reset a Linux bridge. The default network can only be accessed from the KVM virtual machine and communicate with the outside network. If the KVM virtual machine requires two-way communication, you need to set up a Linux bridge on the host machine.

Use the default network configuration

Use the default network configuration in the following cases

Only the host machine and the KVM virtual machine need to communicate with each other

You only need to access the external network from the KVM virtual machine, not the other way around

Set up a Linux bridge on the host machine

Ensure that the network card is working properly, and the KVM virtual machine will also use the network card to communicate with the outside world. The output similar to the following works normally, indicating that there is a p1p2 network card. If your network card is not working properly, it is beyond the scope of this article.

[root@morgan local] # ifconfiglo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: 1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:13471 errors:0 dropped:0 overruns:0 frame:0 TX packets:13471 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:6107173 (5.8 MiB) TX bytes:6107173 (5.8 MiB) p1p2 Link encap:Ethernet HWaddr E0:DB:55:94:AB:15 inet addr:10.10.10.77 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::e2db:55ff:fe94:ab15/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets: 306724 errors:0 dropped:0 overruns:0 frame:0 TX packets:224917 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:252108544 (240.4 MiB) TX bytes:36948789 (35.2 MiB) virbr0 Link encap:Ethernet HWaddr 52:54:00:94:70:F4 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:5 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0b) TX bytes:290 (290.0 b)

Note: KVM does not support wireless network cards!

Configure the network process

Back up the corresponding Nic script file to a different folder. Never copy it to the same folder.

[root@morgan local] # cp / etc/sysconfig/network-scripts/ifcfg-p1p2 / root/

Copy the existing Nic file to br0 Nic file, and we will modify it based on this Nic file.

Cp / etc/sysconfig/network-scripts/ifcfg-p1p2 / etc/sysconfig/network-scripts/if-cfg br0

Configure the bridge file br0

# static IP case DEVICE=eth0 TYPE=Ethernet HWADDR=00:14:5E:C2:1E:40 ONBOOT=yes NM_CONTROLLED=no BRIDGE=br0 # Bridge setting. MAC address needs to be set in eth0 and IP address needs to be set in br0. The Bridge in eth0 points to br0 to use eth0 as the bridge. DEVICE=br0TYPE=BridgeNM_CONTROLLED=noBOOTPROTO=staticIPADDR=10.10.1.152NETMASK=255.255.255.0ONBOOT=yesDEFROUTE=yes# dynamic IP DEVICE=eth0 TYPE=Ethernet HWADDR=00:14:5E:C2:1E:40 ONBOOT=yes NM_CONTROLLED=no BRIDGE=br0 # bridge setting, eth0 needs to set MAC address, br0 needs to set dhcp, and the Bridge in eth0 points to br0 to use eth0 as the bridge. DEVICE=br0TYPE=BridgeNM_CONTROLLED=noBOOTPROTO=dhcpONBOOT=yes

Note that the NetworkManager service is turned off.

Restart the network to make the bridge Nic configuration effective.

Service network restart

Add the following code to the file / etc/sysctl.conf to disable bridging Netfilter in the network (off by default)

Net.bridge.bridge-nf-call-ip6tables = 0net.bridge.bridge-nf-call-iptables = 0net.bridge.bridge-nf-call-arptables = 0

Verify that the network settings are correct.

[root@morgan etc] # ifconfigbr0 Link encap:Ethernet HWaddr E0:DB:55:94:AB:15 inet addr:10.10.10.77 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::e2db:55ff:fe94:ab15/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:57088 errors:0 dropped:0 overruns:0 frame:0

[root@morgan etc] # brctl showbridge name bridge id STP enabled interfacesbr0 8000.e0db5594ab15 no p1p2virbr0 8000.5254009470f4 yes virbr0-nic

Create a KVM virtual machine to install the operating system

Virt-manager is a GUI tool for creating and managing KVM virtual machines. The following procedure is to use virt-manager to install the SLES 11 virtual machine system.

Open the X11 environment

Ssh-X root@127.0.0.1

Create a virtual machine, enter basic information, step by step down on the line, needless to say, anyway, mouse click.

Network environment configuration inside the virtual machine

The internal network uses NAT (set up in virt-manager) so that:

1. Virtual machines can access host machines and external networks

two。 The IP of the virtual machine is the IP of 192.168.122.*.

3. Virtual machines can access each other.

An example of VM's network configuration:

DEVICE=eth0HWADDR=52:54:00:3A:F0:FATYPE=EthernetUUID=6332797f-a76a-43ea-97b9-729a96acaebdONBOOT=yesNM_CONTROLLED=noBOOTPROTO=staticIPADDR=192.168.122.2NETMASK=255.255.255.0DEFROUTE=yesGATEWAY=192.168.122.1 thank you for reading this article carefully. I hope the article "how to install and run KVM in CentOS6" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report