d、kvm的网络管理
默认情况是NAT情况,但是在生产情况,使用更多的是桥接模式
更改虚拟机为网桥模式,原理图如下,网桥的基本原理就是创建一个桥接接口br0,在物理网卡和虚拟网络接口之间传递数据。
修改eth0(这里Centos7的eth0在装机的时候就指定,不需要特意指定了)
添加一个网桥并查看
[root@chuck ~]
# brctl addbr br0
把eth0加入网桥,使用桥接模式,给br设置ip,添加路由网关,关闭防火墙
[root@chuck ~]
# brctl addif br0 eth0 && ip addr del dev eth0 10.0.0.123/24 && ifconfig br0 10.0.0.123/24 up && route add default gw 10.0.0.2 && iptables -F
编辑虚拟机的网络配置使用br0网桥模式
[root@chuck ~]# virsh edit CentOS-7.1-x86_64
<
interface
type
=
"bridge"
>
<!--虚拟机网络连接方式-->
<
source
bridge
=
"br0"
/>
<!-- 当前主机网桥的名称-->
<
mac
address
=
"00:16:e4:9a:b3:6a"
/>
<!--为虚拟机分配mac地址,务必唯一,如果是dhcp获得同样ip,引起冲突-->
</
interface
>
重启虚拟机,网桥模式生效,此时使用crt便可以链接到所创建的虚拟机了,
在vmvare机器上使用ifconfig查看详情
[root@chuck ~]
# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.123 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe67:5a43 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:67:5a:43 txqueuelen 0 (Ethernet)
RX packets 5178 bytes 278872 (272.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7599 bytes 862371 (842.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::20c:29ff:fe67:5a43 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:67:5a:43 txqueuelen 1000 (Ethernet)
RX packets 13641 bytes 973732 (950.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 21843 bytes 2417546 (2.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 10 bytes 1044 (1.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 1044 (1.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:fc:d1:d1 txqueuelen 0 (Ethernet)
RX packets 97 bytes 8122 (7.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 36 bytes 5157 (5.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fe99:1b4e prefixlen 64 scopeid 0x20<link>
ether fe:54:00:99:1b:4e txqueuelen 500 (Ethernet)
RX packets 42 bytes 7295 (7.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 45 bytes 4919 (4.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
6、kvm的优化
a、cpu的优化
inter的cpu的运行级别,按权限级别高低Ring3->Ring2->Ring1->Ring0,(Ring2和Ring1暂时没什么卵用)Ring3为用户态,Ring0为内核态
Ring3的用户态是没有权限管理硬件的,需要切换到内核态Ring0,这样的切换(系统调用)称之为上下文切换,物理机到虚拟机多次的上下文切换,势必会导致性能出现问题。对于全虚拟化,inter实现了技术VT-x,在cpu硬件上实现了加速转换,CentOS7默认是不需要开启的。