centos 7.0安装kvm
时间:2015-04-14 00:12 来源:linux.it.net.cn 作者:IT
PRE-INSTALL
=============================================================
kvm相关安装包及其作用
qemu-kvm 主要的KVM程序包
python-virtinst 创建虚拟机所需要的命令行工具和程序库
virt-manager GUI虚拟机管理工具
virt-top 虚拟机统计命令
virt-viewer GUI连接程序,连接到已配置好的虚拟机
libvirt C语言工具包,提供libvirt服务
libvirt-client 为虚拟客户机提供的C语言工具包
virt-install 基于libvirt服务的虚拟机创建命令
bridge-utils 创建和管理桥接设备的工具
INSTALL
=============================================================
[root@localhost ~]# yum install qemu-kvm libvirt virt-install bridge-utils
#查看是否加载kvm模块
[root@kvm ~]# lsmod|grep kvm
kvm_intel 138567 0
kvm 441119 1 kvm_intel
#如果没有这两条,可以用"modprobe kvm"加载;
#相关命令"insmod;rmmod;modinfo"
#启动libvirtd
[root@localhost ~]# systemctl start libvirtd;systemctl enable libvirtd
[root@localhost ~]# systemctl list-unit-files|grep libvirtd
libvirtd.service enabled
NETWORK CONFIGURATION
=============================================================
#修改网卡文件eno16777736
[root@kvm ~]# cd /etc/sysconfig/network-scripts/
[root@kvm network-scripts]# echo "BRIDGE=br0" >> ifcfg-eno16777736 #在ifcfg-e**原网卡文件中增加"BRIDGE=br0"
#新建网桥文件ifcfg-br0(网桥名称),增加内容如下
[root@kvm network-scripts]# vi ifcfg-br0
*************************************************
DEVICE=br0
TYPE="Bridge" #大小写敏感,所以必须是Bridge
BOOTPROTO="dhcp"
ONBOOT="yes"
DELAY="0"
STP="yes" #这一行是来启动STP,和brctl命令行出来的结果有关
*************************************************
#重启NetworkManager及network服务:
[root@kvm network-scripts]# systemctl restart NetworkManager
#当你手动修改了网卡文件后,需要重启NetworkManager服务来重新接管网络配置
#网卡配置文件和NetworkManager配置冲突时,解决方案:{1、重启NetworkManager;2、关闭NetworkManager}
[root@kvm network-scripts]# systemctl restart network
[root@kvm network-scripts]# ip a #ip命令用来查看和管理ip信息
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link/ether 00:0c:29:61:5c:1d brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 52:54:00:b6:45:5b brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
link/ether 52:54:00:b6:45:5b brd ff:ff:ff:ff:ff:ff
6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 00:0c:29:61:5c:1d brd ff:ff:ff:ff:ff:ff
inet 192.168.0.32/24 brd 192.168.0.255 scope global dynamic br0
valid_lft 11979sec preferred_lft 11979sec
inet6 fe80::20c:29ff:fe61:5c1d/64 scope link
valid_lft forever preferred_lft forever
7: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 500
link/ether fe:54:00:cb:63:b2 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fecb:63b2/64 scope link
valid_lft forever preferred_lft forever
#查看网桥连接
[root@kvm network-scripts]# brctl show #brctl是一个网桥连接管理命令
bridge name bridge id STP enabled interfaces #如果上面不设置STP=yes,这里就会显示no
br0 8000.000c29615c1d yes eno16777736
vnet0
virbr0 8000.525400b6455b yes virbr0-nic
CLOSE SELINUX
=============================================================
[root@kvm network-scripts]# setenforce 0
[root@kvm network-scripts]# getenforce
Permissive
[root@kvm network-scripts]#vi /etc/selinux/config
******************************************
SELINUX=permissive #修改配置文件使其永久生效
******************************************
CREATE A VM
=============================================================
[root@kvm ~]# mkdir -p /var/kvm/images
[root@kvm ~]# virt-install \
--network bridge:br0 \
--name vm1 \
--ram=1024 \
--vcpus=1 \
--disk path=/var/kvm/images/vm1.img,size=10 \
--graphics none \
--location 'http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/' \
--extra-args="console=tty0 console=ttyS0,115200"
#详细每个参数的意义可以查看扩展资料
#安装过程会让你选择textmode 还是vnc,选择textmode继续安装吧
#如果网络会有问题的话,尽量选择用--cdrom /path/to/centos7.iso
#virt-install --name vm1 --ram=1024 --vcpus=1 --network bridge:br0 --disk path=/var/kvm/images/centos7.img,size=10 --graphics none --location=http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/ --extra-args="console=tty0 console=ttyS0,115200"
PS:图形化下安装虚拟机需要X-WINDOW和virt-manager,安装虚拟机之前的操作都一样,图形下操作很简单
扩展资料
=============================================================
http://wiki.centos.org/zh/HowTos/KVM
http://techlinux.net/2014/09/kvm-centos-7/
http://www.server-world.info/en/note?os=CentOS_7&p=kvm&f=2
本文出自 “三零妖人” 博客,请务必保留此出处http://301ren.blog.51cto.com/8887653/1631133
(责任编辑:IT)
PRE-INSTALL ============================================================= kvm相关安装包及其作用 qemu-kvm 主要的KVM程序包 python-virtinst 创建虚拟机所需要的命令行工具和程序库 virt-manager GUI虚拟机管理工具 virt-top 虚拟机统计命令 virt-viewer GUI连接程序,连接到已配置好的虚拟机 libvirt C语言工具包,提供libvirt服务 libvirt-client 为虚拟客户机提供的C语言工具包 virt-install 基于libvirt服务的虚拟机创建命令 bridge-utils 创建和管理桥接设备的工具 INSTALL ============================================================= [root@localhost ~]# yum install qemu-kvm libvirt virt-install bridge-utils #查看是否加载kvm模块 [root@kvm ~]# lsmod|grep kvm kvm_intel 138567 0 kvm 441119 1 kvm_intel #如果没有这两条,可以用"modprobe kvm"加载; #相关命令"insmod;rmmod;modinfo" #启动libvirtd [root@localhost ~]# systemctl start libvirtd;systemctl enable libvirtd [root@localhost ~]# systemctl list-unit-files|grep libvirtd libvirtd.service enabled NETWORK CONFIGURATION ============================================================= #修改网卡文件eno16777736 [root@kvm ~]# cd /etc/sysconfig/network-scripts/ [root@kvm network-scripts]# echo "BRIDGE=br0" >> ifcfg-eno16777736 #在ifcfg-e**原网卡文件中增加"BRIDGE=br0" #新建网桥文件ifcfg-br0(网桥名称),增加内容如下 [root@kvm network-scripts]# vi ifcfg-br0 ************************************************* DEVICE=br0 TYPE="Bridge" #大小写敏感,所以必须是Bridge BOOTPROTO="dhcp" ONBOOT="yes" DELAY="0" STP="yes" #这一行是来启动STP,和brctl命令行出来的结果有关 ************************************************* #重启NetworkManager及network服务: [root@kvm network-scripts]# systemctl restart NetworkManager #当你手动修改了网卡文件后,需要重启NetworkManager服务来重新接管网络配置 #网卡配置文件和NetworkManager配置冲突时,解决方案:{1、重启NetworkManager;2、关闭NetworkManager} [root@kvm network-scripts]# systemctl restart network [root@kvm network-scripts]# ip a #ip命令用来查看和管理ip信息 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000 link/ether 00:0c:29:61:5c:1d brd ff:ff:ff:ff:ff:ff 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN link/ether 52:54:00:b6:45:5b brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500 link/ether 52:54:00:b6:45:5b brd ff:ff:ff:ff:ff:ff 6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 00:0c:29:61:5c:1d brd ff:ff:ff:ff:ff:ff inet 192.168.0.32/24 brd 192.168.0.255 scope global dynamic br0 valid_lft 11979sec preferred_lft 11979sec inet6 fe80::20c:29ff:fe61:5c1d/64 scope link valid_lft forever preferred_lft forever 7: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 500 link/ether fe:54:00:cb:63:b2 brd ff:ff:ff:ff:ff:ff inet6 fe80::fc54:ff:fecb:63b2/64 scope link valid_lft forever preferred_lft forever #查看网桥连接 [root@kvm network-scripts]# brctl show #brctl是一个网桥连接管理命令 bridge name bridge id STP enabled interfaces #如果上面不设置STP=yes,这里就会显示no br0 8000.000c29615c1d yes eno16777736 vnet0 virbr0 8000.525400b6455b yes virbr0-nic CLOSE SELINUX ============================================================= [root@kvm network-scripts]# setenforce 0 [root@kvm network-scripts]# getenforce Permissive [root@kvm network-scripts]#vi /etc/selinux/config ****************************************** SELINUX=permissive #修改配置文件使其永久生效 ****************************************** CREATE A VM ============================================================= [root@kvm ~]# mkdir -p /var/kvm/images [root@kvm ~]# virt-install \ --network bridge:br0 \ --name vm1 \ --ram=1024 \ --vcpus=1 \ --disk path=/var/kvm/images/vm1.img,size=10 \ --graphics none \ --location 'http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/' \ --extra-args="console=tty0 console=ttyS0,115200" #详细每个参数的意义可以查看扩展资料 #安装过程会让你选择textmode 还是vnc,选择textmode继续安装吧 #如果网络会有问题的话,尽量选择用--cdrom /path/to/centos7.iso #virt-install --name vm1 --ram=1024 --vcpus=1 --network bridge:br0 --disk path=/var/kvm/images/centos7.img,size=10 --graphics none --location=http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/ --extra-args="console=tty0 console=ttyS0,115200" PS:图形化下安装虚拟机需要X-WINDOW和virt-manager,安装虚拟机之前的操作都一样,图形下操作很简单 扩展资料 ============================================================= http://wiki.centos.org/zh/HowTos/KVM http://techlinux.net/2014/09/kvm-centos-7/ http://www.server-world.info/en/note?os=CentOS_7&p=kvm&f=2 本文出自 “三零妖人” 博客,请务必保留此出处http://301ren.blog.51cto.com/8887653/1631133 (责任编辑:IT) |