28.4 kvm介绍 28.5 Centos7上安装KVM 28.6 配置网卡 28.7 创建虚拟机安装CentOS7
28.4 kvm介绍
28.5 Centos7上安装KVM
28.6 配置网卡
28.7 创建虚拟机安装CentOS7
28.4 kvm介绍
KVM是以色列初创公司Qumranet开发,2008年9月RedHat公司收购了Qumranet
KVM是Linux内核的一个模块,它把Linux内核变成了一个Hypervisor
#linux内核就是一个一个的模块组成,很多功能
KVM是完全开源的,RedHat基于KVM的虚拟化解决方案叫做RHEV
KVM在Linux操作系统里面以进程的形式出现,由标准的Linux调度程序进行调度,这使得KVM能够使用Linux内核的已有功能
只有一个KVM内核模块还不能实现虚拟化的全部功能,就好比操作系统只有内核还不能成为一个完整的操作系统一样
QEMU是一个开源的虚拟化软件,纯软件,可以虚拟化所以的硬件,性能不强
KVM基于QEMU开发了一个能够运行在用户空间的工具QEMU-KVM
磁盘、网络设备等都是通过QEMU-KVM这个工具模拟出来的
KVM和QEMU-KVM通信是通过/dev/kvm实现的
libvirt是用来管理KVM虚拟机的API,其命令为virsh
kvm作为linux内核的模块在内核空间,利用/dev/kvm与用户空间通信。Qemu-kvm虚拟出虚拟硬件,在这基础上,我们安装GuestOS(虚拟机上的操作系统)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28.5 Centos7上安装KVM
实验是在vmware虚拟机里的,相当于在虚拟机里(vmware)安装虚拟机(kvm)
前提是CPU支持虚拟化
1.虚拟机设置内存2G,增加一个50G的虚拟磁盘,处理器2核,虚拟化引擎两个虚拟化相关的选项打上对勾
2.关闭iptables或者firewalld
3.关闭selinux
4.格式化新磁盘,挂载到/kvm_data
5.下载一个centos7的镜像文件
6.检查cpu参数是否支持虚拟化
grep -Ei 'vmx|svm' /proc/cpuinfo
7.安装kvm
yum install -y virt-* libvirt bridge-utils qemu-img
实例:
先将虚拟机关机,调整硬件资源
[root@axinlinux-01 ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 1.4G 214M 9.8M 207M 236M
Swap: 4.0G 264K 4.0G
[root@axinlinux-01 ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 78
model name : Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
stepping : 3
microcode : 0x9e
cpu MHz : 2400.250
cache size : 3072 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bogomips : 4800.50
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management:processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 78
model name : Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
stepping : 3
microcode : 0x9e
cpu MHz : 2400.250
cache size : 3072 KB
physical id : 2
siblings : 1
core id : 0
cpu cores : 1
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bogomips : 4800.50
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management:
[root@axinlinux-01 ~]# grep -Ei 'vmx|svm' /proc/cpuinfo #有无vmx的字样,代表cpu是否支持虚拟化。vmx和svm分别代表因特尔芯片或arm芯片
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
[root@axinlinux-01 ~]# fdisk -l #查看一下我们新配置的虚拟磁盘
磁盘 /dev/sda:85.9 GB, 85899345920 字节,167772160 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e482f设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 8800255 4194304 82 Linux swap / Solaris
/dev/sda3 8800256 167772159 79485952 83 Linux磁盘 /dev/sdb:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@axinlinux-01 ~]# mkfs.ext4 /dev/sdb #直接格式化成ext4,可以不必分区
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
无论如何也要继续? (y,n) y
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2162163712
400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@axinlinux-01 ~]# blkid /dev/sdb #查看这块磁盘
/dev/sdb: UUID="ea87b8ad-8973-4a8b-b686-11901a9637cc" TYPE="ext4"
[root@axinlinux-01 ~]# mkdir /kvm_data #创建目录
[root@axinlinux-01 ~]# mount /dev/sdb /kvm_data/ #挂载磁盘到这个目录
[root@axinlinux-01 ~]# vim /etc/fstab #编辑/etc/fstab,开机直接挂载新增加的硬盘
/dev/sdb /kvm_data ext4 defaults 0 0
[root@axinlinux-01 ~]# systemctl stop firewalld
[root@axinlinux-01 ~]# systemctl stop iptables
[root@axinlinux-01 ~]# systemctl disable firewalld
[root@axinlinux-01 ~]# systemctl disable iptables
[root@axinlinux-01 ~]# iptables -F #如果还有的话,就清空掉
[root@axinlinux-01 ~]# iptables -nvL #随着kvm的使用或启动,会产生kvm的规则
Chain INPUT (policy ACCEPT 28 packets, 2148 bytes)pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 8 packets, 660 bytes)pkts bytes target prot opt in out source destination
[root@axinlinux-01 ~]# yum install -y virt-* libvirt bridge-utils qemu-img #安装kvm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28.6 配置网卡
可选择桥接或NAT,亦或者其他
1.配置网卡,增加桥接网卡
先要虚拟一个桥接网卡出来,这个桥接网卡就是提供你的虚拟机和宿主机(物理机),相互连接起来的中间桥梁
2.设置一个br0网卡,TYPE为Bridge,IP地址设置为ens33的ip
ens33配置文件里把IP地址去掉,增加BRIDGE=br0
3.检查KVM模块是否加载
lsmod|grep kvm
4.启动libvirtd服务
systemctl start libvirtd
brctl show可以看到两个网卡br0和virbr0
实例:
[root@axinlinux-01 ~]# cd /etc/sysconfig/network-scripts/
[root@axinlinux-01 network-scripts]# cp ifcfg-ens33 ifcfg-br0
[root@axinlinux-01 network-scripts]# vim ifcfg-br0
TYPE=Bridge
BOOTPROTO=none
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.193.128
GATEWAY=192.168.193.2
DNS1=114.114.114.114
DNS2=8.8.8.8
PREFIX=24
[root@axinlinux-01 network-scripts]# vim ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
BRIDGE=br0
[root@axinlinux-01 network-scripts]# systemctl restart network.service
[root@axinlinux-01 network-scripts]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.193.128 netmask 255.255.255.0 broadcast 192.168.193.255inet6 fe80::20c:29ff:fe32:cee6 prefixlen 64 scopeid 0x20<link>ether 00:0c:29:32:ce:e6 txqueuelen 1000 (Ethernet)RX packets 204 bytes 17222 (16.8 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 63 bytes 11182 (10.9 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500ether 00:0c:29:32:ce:e6 txqueuelen 1000 (Ethernet)RX packets 51103 bytes 60556873 (57.7 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 19889 bytes 1819897 (1.7 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (Local Loopback)RX packets 34 bytes 2768 (2.7 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 34 bytes 2768 (2.7 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255ether 52:54:00:8d:04:55 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@axinlinux-02 network-scripts]# systemctl start libvirtd #axin到这一步报错,libvirtd服务起不来,换了台虚拟机就好了。报错信息是这样的“Job for libvirtd.service failed because the control process exited with error code. See "systemctl status libvirtd.service" and "journalctl -xe" for details.”
[root@axinlinux-02 ~]# ps aux |grep libvirt
nobody 1708 0.0 0.0 53852 1108 ? S 13:49 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 1709 0.0 0.0 53824 376 ? S 13:49 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 2699 0.0 0.8 943392 16304 ? Ssl 14:29 0:00 /usr/sbin/libvirtd
root 4918 0.0 0.0 112720 984 pts/0 S+ 15:44 0:00 grep --color=auto libvirt
[root@axinlinux-02 ~]# brctl show #查看桥接网卡的
bridge name bridge id STP enabled interfaces
br0 8000.000c2932cee6 no ens33
virbr0 8000.5254008d0455 yes virbr0-nic
virbro是libvirtd服务所启动的桥接网卡,类似于VM ware的vmnet8的nat的桥接网卡
在kvm没法用鼠标点选择桥接还是nat,因为是命令行的。他的网络类型是哪一个,取决于目标桥接网卡是哪一个。如果是br0就是桥接模式,virbr0就是NAT模式
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28.7 创建虚拟机安装CentOS7
首先要有centos7的镜像文件
命令行安装centos7
virt-install --name=aminglinux01 --memory=512,maxmemory=1024 --vcpus=1,maxvcpus=2 --os-type=linux --os-variant=rhel7 --location=/tmp/CentOS-7-x86_64-DVD-17081.iso --disk path=/kvm_data/aminglinux01.img,size=10 --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
--name 定义你虚拟机的名字
--memory 定义它的内存大小,就是安装完就是512
maxmemory 定义它的最大内存多大,就是可调整到1024(支持热调整)
--vcpus 定义cpu核数
maxvcpus 最大cpu为2核
--os-type 操作类型是linux
--os-variant 版本是rhel7(centos7)
--location 指定ISO文件的路径(可以是http:xxxxx,也就是可以在线安装)
--disk path 虚拟硬盘所在路径,包括名字、大小
--bridge 桥接网卡名字
--graphics 是否开启图形
--console 定义开启的终端、属性
--extra-args 也是终端的属性
实例:
Installation
1) [x] Language settings 2) [!] Time settings
(English (United States)) (Timezone is not set.)
3) [!] Installation source 4) [!] Software selection
(Processing...) (Processing...)
5) [!] Installation Destination 6) [x] Kdump
(No disks selected) (Kdump is enabled)
7) [ ] Network configuration 8) [!] Root password
(Not connected) (Password is not set.)
9) [!] User creation
(No user will be created)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]:
#按1 语言选择 回车 68 回车 1回车
#按2 时区 回车 1 回车 64(shanghai) 回车
#按5 分区 回车 1 回车 c(继续) 回车 c 回车 2(后面x代表默认) 回车 c 回车 1(标准分区) 回车 c 回车
#按8 root密码 wangxin789 回车 两遍
完成设置后,按b+回车
Installation
1) [x] Language settings 2) [x] Time settings
(Simplified Chinese (China)) (Asia/Shanghai timezone)
3) [x] Installation source 4) [x] Software selection
(Local media) (Minimal Install)
5) [x] Installation Destination 6) [x] Kdump
(Automatic partitioning (Kdump is enabled)
selected) 8) [x] Root password
7) [ ] Network configuration (Password is set.)
(Not connected)
9) [ ] User creation
(No user will be created)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]:
以上为设置完成后的,x代表为已设置的
最后按ctrl+],退出终端就可以了。到这一步,阿铭的宿主机(vmware虚拟机)也跟着重启了,阿鑫做的时候没有出现重启的现象。所以,在上面的设置完成以后,不要按回车退出,而是按ctrl+]退出终端,然后再针对axinlinux-02这一台虚拟机重启
转载于:https://my.oschina.net/u/3866192/blog/3066893
28.4 kvm介绍 28.5 Centos7上安装KVM 28.6 配置网卡 28.7 创建虚拟机安装CentOS7相关推荐
- VMware创建虚拟机,CentOS7系统中安装Anaconda3
VMware创建虚拟机,CentOS7系统中安装Anaconda3 创建虚拟机 本次虚拟机是用VMware Workstation来创建. So,第一步打开VMware Workstation,点击文 ...
- 在CentOS7上运行KVM虚拟机
在CentOS7上运行KVM虚拟机 准备工作 检查CPU特性 安装一些基础软件包(非必须) 安装KVM及相关工具 验证安装结果 启动服务并设置为开机自动运行 创建网络环境 使用KVM虚拟机 下载操作系 ...
- OpenStack入门修炼之KVM介绍及安装(3)
1.什么是虚拟化? 虚拟化是云计算的基础.简单的说,虚拟化使得在一台物理的服务器上可以跑多台虚拟机,虚拟机共享物理机的 CPU.内存.IO 硬件资源,但逻辑上虚拟机之间是相互隔离的. 物理机我们一般称 ...
- centos7.3部署kvm虚拟化
一.配置yum源:在自带的yum外,再配置个epel的yum 源. 二.安装: yum install qemu-kvm libvirt virt-install bridge-utils -y 三. ...
- Ubuntu22.04.1 LTS系统上实现KVM虚拟机显卡直通(AMD/NVIDIA+板载显卡)
先告诉你们最终效果 我的服务器上有两块显卡:板载显卡+独立显卡(1U服务器半高显卡 AMD RX550) 板载显卡用于ibmc上的远程桌面控制连接,服务器日常bios操作和linux宿主机桌面操作.板 ...
- 云计算基础课堂001 Linux系统与CentOS7的安装部署(小白向—怎么在VMware虚拟机安装基于Linux操作系统的CentOS7)
云计算基础课堂001 Linux系统与CentOS7的安装部署 一.通过VMware部署CENTOS7系统 软件 创建虚拟机 安装CentOS7 进入并登陆系统 二.Linux历史与其发行版故事 三. ...
- 华为服务器建虚拟机,在服务器上创建虚拟机
在服务器上创建虚拟机 内容精选 换一换 服务器迁移通常有三种手段:全新部署业务.主机迁移服务.镜像迁移,如表1所示.对于华为云上云服务器的跨帐号跨区域迁移,建议采用镜像迁移方式.跨帐号跨区域迁移云服务 ...
- CentOS7虚拟机安装
介绍一下CentOS7虚拟机安装过程,供参考. 1.虚拟机软件安装 推荐VMware workstation,下载地址:https://www.vmware.com/cn/products/works ...
- Android studio下将项目代码上传至github包括更新,同步,创建依赖
AS中设置GIT 一.开篇 本文讲如何使用Android Studio将项目上传到github,虽然讲上传github的文章很多,但是大部分都是使用Git Bash命令行,虽然效率高些,但是有点麻烦, ...
- windows安装程序创建_如何在Windows上创建已安装程序的列表
windows安装程序创建 Reinstalling Windows is a good way to fix serious problems with your computer, or just ...
最新文章
- 大年初一微信闪退?看看如何修复的
- Linux-目录结构说明
- uva1507(状态压缩+dfs)
- centos 输入密码正确进不去系统
- Halcon阈值分割方法简析
- react.js app_如何创建Next.js入门程序以轻松引导新的React App
- 各种编程语言,Linux命令行播放,Bio-Linux,Markdown编辑器等
- python matplotlib画图遇到的问题——画多个子图
- 苹果鼠标怎么充电_双十一苹果无线充电宝怎么选?充电兼容性强的品牌推荐_...
- formidable模块的使用
- Laravel的中间件
- 在linux添加驱动程序,linux下静态/动态加载驱动的两种方式
- 知网论文复制格式问题-文本修改器
- 新浪微博开发平台接入流程(1)---注册应用
- 掠食细菌—蛭弧菌B. bacteriovorus,可以对抗革兰氏阴性感染?
- 自然语言处理NLP星空智能对话机器人系列:深入理解Transformer自然语言处理 Training a GPT-2 language model Steps 7 to 9
- QT中设置字体和更改字体颜色
- 用python绘制玫瑰花
- 【移动端】屏幕、像素、视口、 viewport 控制
- Android studio 入门笔记
热门文章
- win7安装后计算机不在桌面,win7重装系统后进不了桌面的解决措施
- 桌面计算机图标变黑块,win7桌面图标变成有黑色方块怎么办?4个步骤轻松搞定...
- cs服务器协议,反恐精英服务端cs1.6 NoSteam V4554专业比赛服务端47/48双协议一键开启最终版...
- Exchange2010重装注意事项
- 各种卫星产品数据总结
- stm32蜂鸣器程序
- 华硕笔记本禁用触控板方法
- 坦克大战之继承的实现
- 18650锂电池保护板接线图_12v锂电池保护板电路图 - 全文
- PyQt5 与PyQt4的区别