一,安装CentOS6.5,使用最小化的minimal安装二、安装完CentOS后,使用root登录配置网卡,使虚拟机可以使用外网上网
vi /etc/sysconifg/network-scripts/ifcfg-eth0
下图作为参考:
保存后,重启网络服务
service network restart
然后测试是否能联网
ping
三、关闭selinux和清空iptables
修改selinux配置文件
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
设置当前selinux
setenforce 0
清空iptables
iptables -F
保存iptables规则
service iptables save
四、安装KVM
使用yum安装:
yum -y install qemu-kvm libvirt python-virtinst bridge-utils avahi dmidecode
安装完成后重启虚拟机
init 6
重启完成后,测试kvm是否安装成功
stat /dev/kvm
执行结果:
File: "/dev/kvm"
Size: 0 Blocks: 0 IO Block: 4096 字符特殊文件
Device: 5h/5d Inode: 9503 Links: 1 Device type: a,e8
Access: (0666/crw-rw-rw-) Uid: ( 0/ root) Gid: ( 36/ kvm)
Access: 2015-06-28 16:56:11.463134124 +0800
Modify: 2015-06-28 16:56:11.463134124 +0800
Change: 2015-06-28 16:56:11.463134124 +0800
在vb上执行这个命令不会有结果, 我这个是在真机上执行的结果
测试libvirtd是否可以正常启动
service libvirtd start
service libvirtd restart
五、配置网络桥接
检查系统中是否启用了NetworkManager,最好关闭该服务,因为该服务与network有冲突。
chkconfig |grep NetworkManager
如果存在NetworkManager
chkconfig NetworkManager off
service NetworkManager stop
从ifcfg-eth0复制现有网卡的配置文件,改名为ifcfg-br0:
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-br0
修改ifcfg-br0,注意红色的两行,其他部分基本上不用改。
vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
HWADDR=08:00:27:1D:26:B2
UUID=251576f1-0ae3-4a52-b0e1-9343a7ad936d
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=stataic
IPADDR=10.0.0.156
NETMASK=255.255.255.0
GATEWAY=10.0.0.1
DNS1=202.96.64.68
DNS2=202.96.69.38
修改ifcfg-eth0,仅保存以下几行。
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:1D:26:B2
UUID=251576f1-0ae3-4a52-b0e1-9343a7ad936d
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BRIDGE=br0
重启network服务
service network restart
正在关闭接口 eth0: bridge br0 does not exist!
[确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
弹出界面 br0: Determining if ip address 10.0.0.156 is already in use for device br0...
[确定]
执行ifconfig
br0 Link encap:Ethernet HWaddr 08:00:27:1D:26:B2
inet addr:10.0.0.156 Bcast:10.0.0.1 Mask:255.255.255.0
inet6 addr: fe80::ba97:5aff:feb7:98b5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1210 errors:0 dropped:0 overruns:0 frame:0
TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:74677 (72.9 KiB) TX bytes:7509 (7.3 KiB)
eth0 Link encap:Ethernet HWaddr 08:00:27:1D:26:B2
inet6 addr: fe80::ba97:5aff:feb7:98b5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5625 errors:0 dropped:0 overruns:0 frame:0
TX packets:359 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:425234 (415.2 KiB) TX bytes:65054 (63.5 KiB)