centos 安装 KVM 并配置bridge桥接网络

检测是否支持KVM
KVM 是基于 x86 虚拟化扩展(Intel VT 或者 AMD-V) 技术的虚拟机软件,所以查看 CPU 是否支持 VT 技术,就可以判断是否支持KVM。有返回结果,如果结果中有vmx(Intel)或svm(AMD)字样,就说明CPU的支持的。

[root@localhost ~]# cat /proc/cpuinfo | egrep 'vmx|svm'
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 pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat pln pts dtherm tpr_shadow vnmi flexpriority ept vpid xsaveopt
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 pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat pln pts dtherm tpr_shadow vnmi flexpriority ept vpid xsaveopt

安装 kvm

yum install qemu-kvm libvirt virt-install bridge-utils

如果要显示virtual machine manager的界面 , 还需要安装 virt-manager

[root@localhost ~]# yum install virt-manager

确保模块已加载

[root@localhost ~]#  lsmod | grep kvm 
kvm_intel             170181  0 
kvm                   554609  1 kvm_intel
irqbypass              13503  1 kvm

开机启动

[root@localhost ~]# systemctl enable libvirtd

创建桥接网卡 否则在创建虚拟机的时候无法选择桥接

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

配置桥接网卡

[root@localhost network-scripts]# vim ifcfg-br0
TYPE=Bridge
BOOTPROTO=static
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=10.18.218.58
PREFIX=24
GATEWAY=10.18.218.1
DNS1=10.19.3.199

配置本地网卡为bridge模式

[root@localhost network-scripts]# vim ifcfg-em3
TYPE=Ethernet
BOOTPROTO=none
NAME=em3
DEVICE=em3
ONBOOT=yes
BRIDGE="br0"

重启网络

[root@localhost network-scripts]# systemctl restart network

查看网络,配置成功

[root@localhost network-scripts]# ifconfig 
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.18.218.58  netmask 255.255.255.0  broadcast 10.18.218.255
        inet6 fe80::92b1:1cff:fe5b:e89  prefixlen 64  scopeid 0x20<link>
        ether 90:b1:1c:5b:0e:89  txqueuelen 1000  (Ethernet)
        RX packets 485  bytes 188133 (183.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 152  bytes 15332 (14.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

em1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 90:b1:1c:5b:0e:85  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 55  memory 0xd5000000-d57fffff  

em2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 90:b1:1c:5b:0e:87  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 67  memory 0xd6000000-d67fffff  

em3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 90:b1:1c:5b:0e:89  txqueuelen 1000  (Ethernet)
        RX packets 647548  bytes 792095967 (755.4 MiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 298972  bytes 27976410 (26.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  c
        ```

你可能感兴趣的:(Linux)