KVM安装配置
2015-12-25 12:53
274 查看
1. vmware安装centos6.5 64位 (略) 其中有几个注意的地方:
a. 内存给2g
b. 磁盘给50g, 或者再单独分一个磁盘,用来存储虚拟机文件
c. 最关键的一步,在创建虚拟机时,cpu是需要配置一下虚拟化的如图
2. 安装kvm前的准备工作
a. 清除iptables规则
service iptables stop; service iptables save
b. 关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/configsetenforce 03. 开始安装kvm
a. 检查你的系统是否支持虚拟化
grep -Ei 'vmx|svm' /proc/cpuinfo
如果有输出内容,则支持,其中intel cpu支持会有vmx,amd cpu支持会有svm
b. 通过yum安装虚拟化的软件包
yum install -y kvm virt-* libvirt bridge-utils qemu-img
说明:
kvm:软件包中含有KVM内核模块,它在默认linux内核中提供kvm管理程序
libvirts:安装虚拟机管理工具,使用virsh等命令来管理和控制虚拟机。
bridge-utils:设置网络网卡桥接。
virt-*:创建、克隆虚拟机命令,以及图形化管理工具virt-manager
qemu-img:安装qemu组件,使用qemu命令来创建磁盘等。
c. 检查kvm模块是否加载
lsmod |grep kvm
正常应该是:
kvm_intel 55496 3
kvm 337772 1 kvm_intel
如果没有,需要执行
modprobe kvm-intel
还没有就重启一下试试
d. 配置网卡
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-br0
分别编辑eth0和br0
ifcfg-eth0改成如下:
DEVICE=eth0
HWADDR=00:0C:29:55:A7:0A
TYPE=Ethernet
UUID=2be47d79-2a68-4b65-a9ce-6a2df93759c6
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BRIDGE=br0
ifcfg-br0改成如下:
DEVICE=br0
#HWADDR=00:0C:29:55:A7:0A
TYPE=Bridge
#UUID=2be47d79-2a68-4b65-a9ce-6a2df93759c6
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.11.17
NETMASK=255.255.255.0
GATEWAY=192.168.11.1
DNS1=202.106.0.20
说明: 我的虚拟机是桥接模式,所以设置br0的ip和我的真机同样的网段,包括网关也是我路由器的ip,大家可以根据自己的环境去配置,目的是为了让虚拟机可以上网。e. 启动或重启libvirtd服务和messagebus 服务
/etc/init.d/libvirtd start
/etc/init.d/messagebus restart
此时可以查看网络接口列表
brctl show 结果如下:
bridge name bridge id STP enabled interfaces
br0 8000.000c2955a70a no eth0virbr0 8000.52540014efd5 yes virbr0-nic4.磁盘格式化fdisk -l可以看到下面的磁盘信息和新加的/dev/sdb 50G磁盘Disk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00076ca2
Device Boot Start End Blocks Id System/dev/sda1 * 1 13 102400 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 13 274 2097152 82 Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda3 274 2611 18770944 83 Linux
Disk /dev/sdb: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
格式化fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x78d55522.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').
Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-6527, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):Using default value 6527
Command (m for help): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x78d55522
Device Boot Start End Blocks Id System/dev/sdb1 1 6527 52428096 83 Linux
Command (m for help): wThe partition table has been altered!
Calling ioctl() to re-read partition table.Syncing disks.
mkfs.ext4 /dev/sdb1 指定磁盘文件格式mkdir /kvm 创建挂载盘mount /dev/sdb1 /kvm 磁盘挂载5.创建虚拟机virt-install \--name xy1 \--ram 512 \--disk path=/kvm/xy1.img,size=30 \--vcpus 1 \
--os-type linux \
--os-variant rhel6 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://mirrors.163.com/centos/6.7/os/i386/' \--extra-args 'console=ttyS0,115200n8 serial'
说明:
--name 指定虚拟机的名字--ram 指定内存分配多少--disk path 指定虚拟磁盘放到哪里,size=30 指定磁盘大小为30G,这样磁盘文件格式为raw,raw格式不能做快照,后面有说明,需要转换为qcow2格式,如果要使用qcow2格式的虚拟磁盘,需要事先创建qcow2格式的虚拟磁盘。 参考 http://www.361way.com/kvm-qcow2-preallocation-metadata/3354.html 示例:qemu-img create -f qcow2 -o preallocation=metadata /data/test02.img 7G; 之前的--disk path需要修改成 --disk path=/data/test02.img,format=qcow2,size=7,bus=virtio;之前的--location需要改成--location '/mnt/' (/mnt/是本地光盘的挂载路径)--vcpus 指定分配cpu几个
--os-type 指定系统类型为linux
--os-variant 指定系统版本
--network 指定网络类型
--graphics 指定安装通过哪种类型,可以是vnc,也可以没有图形,在这里我们没有使用图形直接使用文本方式
--console 指定控制台类型
--location 指定安装介质地址,可以是网络地址,也可以是本地的一个绝对路径,如果是绝对路径,那么后面还需要指定一个安装介质,比如NFS,假如虚拟机设置ip后,不能连外网,那么就会提示让我们选择安装途径: ┌───┤ Installation Method ├───┐
│ │
│ What type of media contains │
│ the installation image? │
│ │
│ Local CD/DVD │
│ Hard drive │
│ NFS directory │
│ URL │
│ │
│ ┌────┐ ┌──────┐ │
│ │ OK │ │ Back │ │
│ └────┘ └──────┘ │
│ │
│ │
└─────────────────────┘
我在这里选择NFS,设置参数如下:
┌───────────────────────────┤ NFS Setup ├─────────
│ │
│ Please enter the server and NFSv3 path to your CentOS installation │
│ image and optionally additional NFS mount options. │
│ │
│ NFS server name: 172.7.15.3______________ │
│ CentOS directory: /mnt/images/install.img_ │
│ NFS mount options (optional): ro______________________ │
--extra-args 设定内核参数
当按下回车后,稍等几秒钟就可以看到安装提示了。
开始安装......
搜索文件 .treeinfo...... | 720 B 00:00 ...
搜索文件 vmlinuz...... | 7.7 MB 00:02 ...
搜索文件 initrd.img...... | 63 MB 00:23 ...
创建存储文件 centos6.6_1.img | 30 GB 00:00
创建域...... | 0 B 00:00
连接到域 centos6.6_1
Escape character is ^]
然后就是我们非常熟悉的OK or Next 了 ,只不过这个过程是文本模式,如果想使用图形,只能开启vnc啦。
最后安装完,reboot就进入刚刚创建的虚拟机了。要想退回到宿主机,ctrl ] 即可。
virsh list 可以列出当前的子机列表。virsh console centos6.6_1 可以进入指定的子机
本文出自 “echo xiayun” 博客,请务必保留此出处http://linuxerxy.blog.51cto.com/10707334/1728214
a. 内存给2g
b. 磁盘给50g, 或者再单独分一个磁盘,用来存储虚拟机文件
c. 最关键的一步,在创建虚拟机时,cpu是需要配置一下虚拟化的如图
2. 安装kvm前的准备工作
a. 清除iptables规则
service iptables stop; service iptables save
b. 关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/configsetenforce 03. 开始安装kvm
a. 检查你的系统是否支持虚拟化
grep -Ei 'vmx|svm' /proc/cpuinfo
如果有输出内容,则支持,其中intel cpu支持会有vmx,amd cpu支持会有svm
b. 通过yum安装虚拟化的软件包
yum install -y kvm virt-* libvirt bridge-utils qemu-img
说明:
kvm:软件包中含有KVM内核模块,它在默认linux内核中提供kvm管理程序
libvirts:安装虚拟机管理工具,使用virsh等命令来管理和控制虚拟机。
bridge-utils:设置网络网卡桥接。
virt-*:创建、克隆虚拟机命令,以及图形化管理工具virt-manager
qemu-img:安装qemu组件,使用qemu命令来创建磁盘等。
c. 检查kvm模块是否加载
lsmod |grep kvm
正常应该是:
kvm_intel 55496 3
kvm 337772 1 kvm_intel
如果没有,需要执行
modprobe kvm-intel
还没有就重启一下试试
d. 配置网卡
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-br0
分别编辑eth0和br0
ifcfg-eth0改成如下:
DEVICE=eth0
HWADDR=00:0C:29:55:A7:0A
TYPE=Ethernet
UUID=2be47d79-2a68-4b65-a9ce-6a2df93759c6
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BRIDGE=br0
ifcfg-br0改成如下:
DEVICE=br0
#HWADDR=00:0C:29:55:A7:0A
TYPE=Bridge
#UUID=2be47d79-2a68-4b65-a9ce-6a2df93759c6
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.11.17
NETMASK=255.255.255.0
GATEWAY=192.168.11.1
DNS1=202.106.0.20
说明: 我的虚拟机是桥接模式,所以设置br0的ip和我的真机同样的网段,包括网关也是我路由器的ip,大家可以根据自己的环境去配置,目的是为了让虚拟机可以上网。e. 启动或重启libvirtd服务和messagebus 服务
/etc/init.d/libvirtd start
/etc/init.d/messagebus restart
此时可以查看网络接口列表
brctl show 结果如下:
bridge name bridge id STP enabled interfaces
br0 8000.000c2955a70a no eth0virbr0 8000.52540014efd5 yes virbr0-nic4.磁盘格式化fdisk -l可以看到下面的磁盘信息和新加的/dev/sdb 50G磁盘Disk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00076ca2
Device Boot Start End Blocks Id System/dev/sda1 * 1 13 102400 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 13 274 2097152 82 Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda3 274 2611 18770944 83 Linux
Disk /dev/sdb: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
格式化fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x78d55522.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').
Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-6527, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):Using default value 6527
Command (m for help): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x78d55522
Device Boot Start End Blocks Id System/dev/sdb1 1 6527 52428096 83 Linux
Command (m for help): wThe partition table has been altered!
Calling ioctl() to re-read partition table.Syncing disks.
mkfs.ext4 /dev/sdb1 指定磁盘文件格式mkdir /kvm 创建挂载盘mount /dev/sdb1 /kvm 磁盘挂载5.创建虚拟机virt-install \--name xy1 \--ram 512 \--disk path=/kvm/xy1.img,size=30 \--vcpus 1 \
--os-type linux \
--os-variant rhel6 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://mirrors.163.com/centos/6.7/os/i386/' \--extra-args 'console=ttyS0,115200n8 serial'
说明:
--name 指定虚拟机的名字--ram 指定内存分配多少--disk path 指定虚拟磁盘放到哪里,size=30 指定磁盘大小为30G,这样磁盘文件格式为raw,raw格式不能做快照,后面有说明,需要转换为qcow2格式,如果要使用qcow2格式的虚拟磁盘,需要事先创建qcow2格式的虚拟磁盘。 参考 http://www.361way.com/kvm-qcow2-preallocation-metadata/3354.html 示例:qemu-img create -f qcow2 -o preallocation=metadata /data/test02.img 7G; 之前的--disk path需要修改成 --disk path=/data/test02.img,format=qcow2,size=7,bus=virtio;之前的--location需要改成--location '/mnt/' (/mnt/是本地光盘的挂载路径)--vcpus 指定分配cpu几个
--os-type 指定系统类型为linux
--os-variant 指定系统版本
--network 指定网络类型
--graphics 指定安装通过哪种类型,可以是vnc,也可以没有图形,在这里我们没有使用图形直接使用文本方式
--console 指定控制台类型
--location 指定安装介质地址,可以是网络地址,也可以是本地的一个绝对路径,如果是绝对路径,那么后面还需要指定一个安装介质,比如NFS,假如虚拟机设置ip后,不能连外网,那么就会提示让我们选择安装途径: ┌───┤ Installation Method ├───┐
│ │
│ What type of media contains │
│ the installation image? │
│ │
│ Local CD/DVD │
│ Hard drive │
│ NFS directory │
│ URL │
│ │
│ ┌────┐ ┌──────┐ │
│ │ OK │ │ Back │ │
│ └────┘ └──────┘ │
│ │
│ │
└─────────────────────┘
我在这里选择NFS,设置参数如下:
┌───────────────────────────┤ NFS Setup ├─────────
│ │
│ Please enter the server and NFSv3 path to your CentOS installation │
│ image and optionally additional NFS mount options. │
│ │
│ NFS server name: 172.7.15.3______________ │
│ CentOS directory: /mnt/images/install.img_ │
│ NFS mount options (optional): ro______________________ │
--extra-args 设定内核参数
当按下回车后,稍等几秒钟就可以看到安装提示了。
开始安装......
搜索文件 .treeinfo...... | 720 B 00:00 ...
搜索文件 vmlinuz...... | 7.7 MB 00:02 ...
搜索文件 initrd.img...... | 63 MB 00:23 ...
创建存储文件 centos6.6_1.img | 30 GB 00:00
创建域...... | 0 B 00:00
连接到域 centos6.6_1
Escape character is ^]
然后就是我们非常熟悉的OK or Next 了 ,只不过这个过程是文本模式,如果想使用图形,只能开启vnc啦。
最后安装完,reboot就进入刚刚创建的虚拟机了。要想退回到宿主机,ctrl ] 即可。
virsh list 可以列出当前的子机列表。virsh console centos6.6_1 可以进入指定的子机
本文出自 “echo xiayun” 博客,请务必保留此出处http://linuxerxy.blog.51cto.com/10707334/1728214
相关文章推荐
- Xcode插件管理插件:Alcatraz
- 标准MD5加密算法
- MVC中--异常详细信息: System.ArgumentNullException: 值不能为 null。 参数名: value
- Android网络图片查看器
- Scala 类型约束
- Android之string.xml 使用总结
- react-native for android windows开发环境搭建详细记录
- tomcat部署上之后,运行报错
- 服务器控件转换成HTML
- 请求参数里面有汉字的处理
- Zmap安装、使用教程
- web设置session超时时间
- Write operations are not allowed in read-only mode (FlushMode.MANUAL)错误解决的一种方法
- 互联网创业的感想
- 死锁演示 Lock
- WEB级HTTP请求内容的工具
- 设置文本框样式和修改按钮样式
- [BZOJ3675] [Apio2014]序列分割
- 使用AfxBeginThread须注意的问题...
- iOS 的VFL知识详解