KVM虚拟化

本文详细介绍了KVM虚拟化的安装过程,包括调整虚拟机设置、启动KVM、配置CPU和内存、挂载新磁盘以及安装CentOS 7镜像。此外,还涵盖了虚拟机管理、克隆和快照管理等高级操作。
摘要由CSDN通过智能技术生成

安装KVM

  1. 调整虚拟机
    双击“编辑虚拟机设置” ,关机设置
    在这里插入图片描述
    虚拟机设置内存2G/4G,增加一个50G的虚拟磁盘,处理器2核,虚拟化引擎两个虚拟化相关的选项打上对勾
    在这里插入图片描述
    配置完成,我们启动虚拟机

  2. 检查CPU参数
    查看内存是否更改成功

[root@jing ~]#free
              total        used        free      shared  buff/cache   available
Mem:        3866948      136852     3568068        8672      162028     3541164
Swap:       2097148           0     2097148

检查CPU是否开启虚拟化支持(vmx为英特尔的cpu;svm为AMD的cpu)

[root@jing ~]# cat /proc/cpuinfo |grep vmx
[root@jing ~]# cat /proc/cpuinfo |grep svm
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw perfctr_core arat npt svm_lock nrip_save vmcb_clean flushbyasid decodeassists fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt xsaveopt xsavec xsaves
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw perfctr_core arat npt svm_lock nrip_save vmcb_clean flushbyasid decodeassists fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt xsaveopt xsavec xsaves
  1. 挂载新磁盘

查看磁盘

[root@jing ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   60G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 59.5G  0 part 
  ├─centos-root 253:0    0 38.6G  0 lvm  /
  ├─centos-swap 253:1    0    2G  0 lvm  [SWAP]
  └─centos-home 253:2    0 18.9G  0 lvm  /home
sdb               8:16   0   50G  0 disk 
sr0              11:0    1 1024M  0 rom  

格式化磁盘

[root@jing ~]# mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=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, 11239424

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

查看磁盘信息

[root@jing ~]# blkid
/dev/sda1: UUID="cc9882ae-f269-43f8-9186-9e8cb66a5908" TYPE="xfs" 
/dev/sda2: UUID="gM8PCH-kdry-0KqO-0adE-cvjU-wKcn-j2qcIG" TYPE="LVM2_member" 
/dev/sdb: UUID="9b5c3d5f-d651-4996-86ca-718d424dbfee" TYPE="ext4" 
/dev/mapper/centos-root: UUID="2aa3de63-1745-4e84-bb01-a59b81a9c9fc" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="c44ac98c-475f-4851-a272-b87c84af3880" TYPE="swap" 
/dev/mapper/centos-home: UUID="8220dbcd-2bfc-4018-af82-0b050732e1b4" TYPE="xfs" 

[root@jing ~]# blkid /dev/sdb
/dev/sdb: UUID="9b5c3d5f-d651-4996-86ca-718d424dbfee" TYPE="ext4" 

创建挂载目录/kvm_data,进行挂载

[root@jing ~]# mkdir /kvm_data
[root@jing ~]# mount /dev/sdb /kvm_data/

编写/etc/fstab文件(为了方便开机后可以自动挂载)

[root@jing ~]# vi /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Nov 26 16:16:43 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=cc9882ae-f269-43f8-9186-9e8cb66a5908 /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sdb                /kvm_data               ext4    defaults        0 0     添加此条

关闭防火墙并设置开机不自启

[root@jing ~]# systemctl stop firewalld
[root@jing ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

看一下是否被清理掉
[root@jing ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 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 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination  

Yum进行安装KVM

[root@jing ~]# yum install -y virt-*  libvirt  bridge-utils qemu-img

启动KVM

配置网卡

增加桥接网卡ifcfg-br0
[root@jing ~]# cd /etc/sysconfig/network-scripts
[root@jing network-scripts]# ls
ifcfg-eno16777728  ifdown-ppp       ifup-ib      ifup-Team
ifcfg-lo           ifdown-routes    ifup-ippp    ifup-TeamPort
ifdown             ifdown-sit       ifup-ipv6    ifup-tunnel
ifdown-bnep        ifdown-Team      ifup-isdn    ifup-wireless
ifdown-eth         ifdown-TeamPort  ifup-plip    init.ipv6-global
ifdown-ib          ifdown-tunnel    ifup-plusb   network-functions
ifdown-ippp        ifup             ifup-post    network-functions-ipv6
ifdown-ipv6        ifup-aliases     ifup-ppp
ifdown-isdn        ifup-bnep        ifup-routes
ifdown-post        ifup-eth         ifup-sit
[root@jing network-scripts]# cp ifcfg-eno16777728 ifcfg-br0

修改桥接网卡ifcfg-br0的内容
[root@jing network-scripts]# vi ifcfg-br0
TYPE=Bridge
BOOTPROTO=none
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.200.90
PREFIX=24
GATEWAY=192.168.200.2
DNS1=114.114.114.114

修改NAT网卡ifcfg-eno16777736
[root@jing network-scripts]# vi ifcfg-eno16777728 
TYPE=Ethernet
BOOTPROTO=none
NAME=eno16777736
DEVICE=eno16777736
ONBOOT=yes
BRIDGE=br0

重新启动网卡服务

[root@jing network-scr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值