在centos 6 环境下KVM的安装部分,我写过kvm虚拟化小结(一)kvm环境安装 。由于centos 7较之前的版本有了很大的变化,目前测试了centos 7 环境下kvm的安装与搭建,具体如下。

一、安装kvm 软件

由于之前已做过较详细的 kvm 的安装与总结,这里只大致列下步骤:

1[root@361way ~]# yum -y install qemu-kvm libvirt virt-install bridge-utils
2[root@361way ~]# lsmod | grep kvm  # make sure modules are loaded
3kvm                   441119  0
4[root@361way ~]# systemctl start libvirtd
5[root@361way ~]# systemctl enable libvirtd

注:centos7上服务的管理方式换成了systemctl 。

二、配置网卡桥接

centos7上默认已不再是eth0、eth1 ,我的pc server上安装好的第一块网卡变成了enp3s0 ,修改步骤和centos 6上没有区别,如下

 1[root@361way ~]# cd /etc/sysconfig/network-scripts/
 2[root@361way network-scripts]# cat ifcfg-br0
 3TYPE=Bridge
 4BOOTPROTO=none
 5DEVICE=br0
 6ONBOOT=yes
 7IPADDR0=192.168.0.102
 8PREFIX0=24
 9GATEWAY0=192.168.0.1
10[root@361way network-scripts]# cat ifcfg-enp3s0
11DEVICE=enp3s0
12TYPE=Ethernet
13ONBOOT=yes
14BRIDGE=br0
15[root@361way ~]reboot
16[root@361way network-scripts]# ifconfig
17br0: flags=4163<up,broadcast,running,multicast>  mtu 1500
18        inet 192.168.0.102  netmask 255.255.255.0  broadcast 192.168.0.255
19        inet6 fe80::7a24:afff:fe46:ca60  prefixlen 64  scopeid 0x20<link />
20        ether 78:24:af:46:ca:60  txqueuelen 0  (Ethernet)
21        RX packets 129  bytes 14676 (14.3 KiB)
22        RX errors 0  dropped 0  overruns 0  frame 0
23        TX packets 148  bytes 21994 (21.4 KiB)
24        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
25enp3s0: flags=4163<up,broadcast,running,multicast>  mtu 1500
26        ether 78:24:af:46:ca:60  txqueuelen 1000  (Ethernet)
27        RX packets 129  bytes 16482 (16.0 KiB)
28        RX errors 0  dropped 0  overruns 0  frame 0
29        TX packets 148  bytes 21994 (21.4 KiB)
30        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
31lo: flags=73<up,loopback,running>  mtu 65536
32        inet 127.0.0.1  netmask 255.0.0.0
33        inet6 ::1  prefixlen 128  scopeid 0x10<host>
34        loop  txqueuelen 0  (Local Loopback)
35        RX packets 9  bytes 728 (728.0 B)
36        RX errors 0  dropped 0  overruns 0  frame 0
37        TX packets 9  bytes 728 (728.0 B)
38        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
39virbr0: flags=4099<up,broadcast,multicast>  mtu 1500
40        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
41        ether a6:88:9f:14:b2:66  txqueuelen 0  (Ethernet)
42        RX packets 0  bytes 0 (0.0 B)
43        RX errors 0  dropped 0  overruns 0  frame 0
44        TX packets 1  bytes 90 (90.0 B)
45        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
46[root@361way network-scripts]# ip add show
471: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state UNKNOWN
48    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
49    inet 127.0.0.1/8 scope host lo
50       valid_lft forever preferred_lft forever
51    inet6 ::1/128 scope host
52       valid_lft forever preferred_lft forever
532: enp3s0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
54    link/ether 78:24:af:46:ca:60 brd ff:ff:ff:ff:ff:ff
553: br0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc noqueue state UP
56    link/ether 78:24:af:46:ca:60 brd ff:ff:ff:ff:ff:ff
57    inet 192.168.0.102/24 brd 192.168.0.255 scope global br0
58       valid_lft forever preferred_lft forever
59    inet6 fe80::7a24:afff:fe46:ca60/64 scope link
60       valid_lft forever preferred_lft forever
614: virbr0: <no-carrier,broadcast,multicast,up> mtu 1500 qdisc noqueue state DOWN
62    link/ether a6:88:9f:14:b2:66 brd ff:ff:ff:ff:ff:ff
63    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
64       valid_lft forever preferred_lft forever</no-carrier,broadcast,multicast,up></broadcast,multicast,up,lower_up></broadcast,multicast,up,lower_up></loopback,up,lower_up></up,broadcast,multicast></host></up,loopback,running></up,broadcast,running,multicast></up,broadcast,running,multicast>

注:由于ip 命令属于iproute2软件包中的工具,由于代替旧的ifconfig命令,尽可能的习惯使用新的命令和工具包来淘汰老的软件和工具。

三、selinux防火墙关闭

1# setenforce  0
2# sed -i 's/=enforcing/=disabled/g' /etc/selinux/config