Deployment of KVM virtualization platform (theory + practical)

KVM virtual machine:

1.KVM is the Kernel-based Virtual Machine for short, is an open source system virtualization module, since Linux 2.6.20 is integrated in each major release of Linux. It uses the Linux scheduler to manage itself, so relative to Xen, the core source code rarely. KVM has become one of the mainstream academic VMM

2.KVM of virtualization requires hardware support (such as Intel VT technology or AMD V technology). It is completely hardware-based virtualization. The early Xen is based on Para-Virtualization, a new version of the software simulation is based on full hardware support for virtualization. But Xen itself has its own process scheduler, memory management module, so the code is relatively large. Widespread commercial system virtualization software VMware ESX series is software-based simulation Full-Virtualization

Virtual development process:

IDC data center equipment rental → virtualization solutions proposed, there OpenVZ → share optimization occurs Xen, a virtual architecture proposed half, but the whole complex operation → enter the virtual KVM, the kernel and does not require contact only need to install management tools

Case Summary

1. Part of the company Linux server utilization is not high, to take advantage of these Linux servers can be deployed KVM, physical machine running on a plurality of business systems
2. For example. KVM deployed Nginx running on the server, and then run on a virtual machine Tomcat

Case pre-knowledge

KVM virtualization architecture

KVM module is directly integrated in the Linux kernel

<img src = " https://img-blog.csdnimg.cn/20191219094458210.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0phcnJ5Wmhv,size_16,color_FFFFFF,t_70 " alt = "Insert Picture Here description "style =" zoom: 67% ; "/>

KVM consists of:

Here Insert Picture Description

KVM Driver:

1. Create a virtual machine
2. Memory Allocation
3. virtual CPU write register
4. The virtual CPU running

The QEMU (simplified and modified):

1. Analog PC hardware user control assembly
pathways 2. Provide I / O devices and peripheral access model

KVM virtualization in three modes:

1. Customer mode (Virtual Machine)
2. User mode (tool)
3. kernel mode

<img src = " https://img-blog.csdnimg.cn/20191219094917435.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0phcnJ5Wmhv,size_16,color_FFFFFF,t_70 " alt = "Insert Picture Here description "style =" zoom: 67% ; "/>

KVM works:

<img src = " https://img-blog.csdnimg.cn/20191219095651288.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0phcnJ5Wmhv,size_16,color_FFFFFF,t_70 " alt = "Insert Picture Here description "style =" zoom: 67% ; "/>

Demo:

Preparing the environment:

1. The need to add a disk: 20G size

2. Processor settings: virtualization engine tick all the options
Here Insert Picture Description

[root@client ~]# cd /dev
[root@client dev]# ls
sda   sda1   sda2    sda3   sda4   sda5   sdb 
#此时有sdb硬盘

[root@client dev]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xba1e8e30 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n       #输入n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p       #输入p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):w      #输入w保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。

[root@client dev]# mkfs /dev/sdb1       #格式化
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
160 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
Allocating group tables: 完成
正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成

[root@client dev]# mkdir /data      #创建挂载
[root@client dev]# mount /dev/sdb1 /data/
[root@client data]# df -hT
文件系统       类型      容量  已用  可用 已用% 挂载点
/dev/sdb1      ext2       20G   44M   19G    1% /data
#此时显示已经挂载

#电脑中有CentOS 7镜像文件的文件夹需要进行共享,设置账户Everyone可以进行读取,然后使用smbclient -L查看挂载
[root@client data]# smbclient -L //192.168.10.190/
Enter SAMBA\root's password:
OS=[Windows 10 Home China 18363] Server=[Windows 10 Home China 6.3]

        Sharename       Type      Comment
        ---------       ----      -------
        database        Disk
        F$              Disk      默认共享
        gfs             Disk
        IPC$            IPC       远程 IPC
        ISO             Disk
        rpm             Disk
#此时显示ISO文件夹被共享

[root@client data]# mount.cifs //192.168.10.190/ISO /mnt
Password for root@//192.168.10.190/ISO:
[root@client data]# df -h
文件系统              容量  已用  可用 已用% 挂载点
/dev/sdb1              20G   44M   19G    1% /data
//192.168.10.190/ISO  226G  173G   54G   77% /mnt
#此时显示文件成功挂载在mnt目录下
[root@client data]# cd /mnt/
[root@client mnt]# ls
CentOS-7-x86_64-DVD-1708.iso

Installation KVM:

[root@client mnt]# yum list         #进行自检
[root@client mnt]# yum groupinstall "GNOME Desktop" -y      #桌面环境
[root@client mnt]# yum install qemu-kvm -y      #KVM模块
[root@client mnt]# yum install qemu-kvm-tools -y        #KVM调试工具
[root@client mnt]# yum install virt-install -y      #构建虚拟机的命令工具
[root@client mnt]# yum install qemu-img -y      #qemu组件,创建磁盘,启动虚拟机
[root@client mnt]# yum install bridge-utils -y      #网络支持工具
[root@client mnt]# yum install libvirt -y       #虚拟机管理工具
[root@client mnt]# yum install virt-manager -y      #图像化管理虚拟机
[root@client mnt]# egrep '(vmx|svm)' /proc/cpuinfo      #查看是否支持虚拟化

[root@client mnt]# lsmod | grep kvm     #检查KVM是否安装
kvm_intel             170086  0
kvm                   566340  1 kvm_intel
irqbypass              13503  1 kvm

[root@client mnt]# systemctl start libvirtd
[root@client mnt]# systemctl enable libvirtd        #开机自启动

Bridge configuration examples:

[root@client mnt]# cd /data/
[root@client data]# mkdir vdisk viso
[root@client data]# ls
lost+found  vdisk  viso
[root@client data]# cp -r /mnt/CentOS-7-x86_64-DVD-1708.iso /data/viso/
[root@client data]# ls viso/
CentOS-7-x86_64-DVD-1708.iso
[root@client data]# cd /etc/sysconfig/network-scripts/
[root@client network-scripts]# cp -p ifcfg-ens33 ifcfg-br0
[root@client network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.18.145  netmask 255.255.255.0  broadcast 192.168.18.255
        inet6 fe80::6a0c:e6a0:7978:3543  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:a4:cb:c7  txqueuelen 1000  (Ethernet)
        RX packets 6559352  bytes 9624037086 (8.9 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 364406  bytes 30690747 (29.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
......此处省略多行
[root@client network-scripts]# vim ifcfg-ens33
#在末行按o转下行插入
BRIDGE=br0
#插入完成后按Esc退出插入模式,输入:wq保存退出
[root@client network-scripts]# vim ifcfg-br0
TYPE="bridge"               #Ethernet改为bridge
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"          #dhcp改为static
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="br0"                  #ens33改为br0
DEVICE="br0"                #ens33改为br0
ONBOOT="yes"
IPADDR=192.168.18.145       #输入ens33的IP地址
NETMASK=255.255.255.0       #输入子网掩码
GATEWAY=192.168.18.1        #输入网关
#修改退出插入模式,输入:wq保存退出
[root@client network-scripts]# service network restart      #重启网络服务
Restarting network (via systemctl):                        [  确定  ]

[root@client network-scripts]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.18.145  netmask 255.255.255.0  broadcast 192.168.18.255
        inet6 fe80::e169:c641:eeea:50f7  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:a4:cb:c7  txqueuelen 1000  (Ethernet)
        RX packets 20  bytes 1298 (1.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 35  bytes 4588 (4.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:a4:cb:c7  txqueuelen 1000  (Ethernet)
        RX packets 6559967  bytes 9624087097 (8.9 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 364793  bytes 30733147 (29.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
......以下省略多行
#桥接之后原来ens33的网卡IP到br0上了

Back to the graphical interface Input:

[root@client ~]# virt-manager 

At this time, will jump out of the virtual system management interface, we need to add a storage pool

Click on the name of a custom pool browse the directory, select the directory to / data / vdisk, we look to mount CentOS7 folder directory, click Finish

Then click Add a new volume

Add mirrored storage pool: iso, click forward path selection / data / viso

Here Insert Picture Description

Once created, you can click on the upper left corner of File → Close

Select New Virtual Machine in the upper left corner of the virtual file system manager

Installing the operating system is installed locally, click Forward

Here Insert Picture Description

Use ISO image: Click Browse, select the iso storage pool, find a mirror, click to select the volume

Here Insert Picture Description

And then click Forward, memory enter 2048, and then click Forward

Here Insert Picture Description

Select or create a custom storage, click Manage, select the disk storage pools, volumes before the click, click to select the volume

Here Insert Picture Description

And then click Forward, and then click Finish, then will enter the installation interface Centos7 of:

Here Insert Picture Description

At this point KVM virtualization deployments successful test!

Guess you like

Origin blog.51cto.com/14464303/2460057