Skip to content Skip to main navigation Skip to footer

CentOS 6.x 安装和配置KVM虚拟化环境

如何在centos 6.x系统上配置给予内核的虚拟化环境呢?如何使用KVM安装并管理虚机?
KVM是CentOS或RHEL系统的一部分,我们仍然需要安装一下KVM包相关的一些软件包。
kvm

CentOS 安装kvm相关软件包

输入下面的命令:

yum groupinstall "Virtualisation Tools" "Virtualization Platform"
yum install python-virtinst
 

或者

 yum install kvm qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools
 

命令输出:

Loaded plugins: fastestmirror, refresh-packagekit, security, versionlock
Loading mirror speeds from cached hostfile
 * base: mirrors.pubyun.com
 * extras: mirrors.pubyun.com
 * updates: mirrors.pubyun.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package libguestfs-tools.x86_64 1:1.20.11-11.el6 will be installed
--> Processing Dependency: libguestfs-tools-c = 1:1.20.11-11.el6 for package: 1:libguestfs-tools-1.20.11-11.el6.x86_64
--> Processing Dependency: libguestfs = 1:1.20.11-11.el6 for package: 1:libguestfs-tools-1.20.11-11.el6.x86_64
--> Processing Dependency: perl(Win::Hivex) >= 1.2.7 for package: 1:libguestfs-tools-1.20.11-11.el6.x86_64
--> Processing Dependency: perl(XML::Writer) for package: 1:libguestfs-tools-1.20.11-11.el6.x86_64
--> Processing Dependency: perl(Sys::Virt) for package: 1:libguestfs-tools-1.20.11-11.el6.x86_64
--> Processing Dependency: perl(Sys::Guestfs::Lib) for package: 1:libguestfs-tools-1.20.11-11.el6.x86_64
--> Processing Dependency: perl(Sys::Guestfs) for package: 1:libguestfs-tools-1.20.11-11.el6.x86_64
...
 

启动libvirtd 服务

libvirtd 程序是一个服务器端的进程组件,用来做虚拟化的管理。 输入下面的命令来设置libvirtd服务系统自启动:

chkconfig libvirtd on
 

输入下面的命令启动libvirtd服务:

service libvirtd start
 

命令输出:

Starting libvirtd daemon:                                  [  OK  ]
 

使用下面的命令来检测libvirtd服务的状态:

service libvirtd status
 

命令输出:

libvirtd (pid  31128) is running...
# virsh -c qemu:///system list
 Id    Name                           State
----------------------------------------------------
 

安装并配置网桥

所有的VM虚机会通过一个私有网络来进行网络通信。所以你需要创建一个网桥让各主机之间进行互相通信。输入下面的命令来装网桥组件:

yum install birdge-utils
 

命令输出:

[root@devops Desktop]# yum install bridge-utils
Loaded plugins: fastestmirror, refresh-packagekit, security, versionlock
Loading mirror speeds from cached hostfile
 * base: mirrors.pubyun.com
 * extras: mirrors.pubyun.com
 * updates: mirrors.pubyun.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bridge-utils.x86_64 0:1.2-9.el6 will be updated
---> Package bridge-utils.x86_64 0:1.2-10.el6 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package               Arch            Version              Repository     Size
================================================================================
Updating:
 bridge-utils          x86_64          1.2-10.el6           base           30 k
Transaction Summary
================================================================================
Upgrade       1 Package(s)
Total download size: 30 k
Downloading Packages:
bridge-utils-1.2-10.el6.x86_64.rpm                       |  30 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : bridge-utils-1.2-10.el6.x86_64                               1/2
  Cleanup    : bridge-utils-1.2-9.el6.x86_64                                2/2
  Verifying  : bridge-utils-1.2-10.el6.x86_64                               1/2
  Verifying  : bridge-utils-1.2-9.el6.x86_64                                2/2
Updated:
  bridge-utils.x86_64 0:1.2-10.el6
Complete!
 

配置网桥
编辑网卡配置文件/etc/sysconfig/network-scripts/ifcfg-eth0 :

DEVICE=eth0
ONBOOT=yes
BRIDGE=br0
 

创建一个网桥文件ifcfg-br0:”/etc/sysconfig/network-scripts/ifcfg-br0″,并进入下面的内容:

DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.192
DELAY=0
 

重启网络服务
输入下面的命令:

service network restart
 
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.