Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

KVM Virtualization basic deployment

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

KVM virtual machine:

1.KVM, short for Kernel-based Virtual Machine, is an open source system virtualization module that has been integrated in major releases of Linux since Linux 2.6.20. It is managed by Linux's own scheduler, so its core source code is relatively small compared to Xen. KVM has become one of the mainstream VMM in academic circles.

2.KVM virtualization requires hardware support (such as Intel VT technology or AMD V technology). Is full virtualization based on hardware. In the early days, Xen was based on software simulation of Para-Virtualization, while the new version was based on full virtualization supported by hardware. But Xen itself has its own process scheduler, storage management module and so on, so the code is relatively large. The widely spread commercial system virtualization software VMware ESX series is Full-Virtualization based on software simulation.

Virtualization development process:

IDC data center equipment lease → proposed a virtualization solution, OpenVZ → sharing optimization appeared Xen, proposed semi-virtual architecture, but the operation of complex → into full virtual KVM, do not need to contact with the kernel, only need to install management tools

Case Overview

1. The utilization rate of some Linux servers in the company is not high. In order to make full use of these Linux servers, KVM can be deployed to run multiple business systems on physical machines.

two。 For example, on a server running Nginx. Deploy KVM on the, and then run Tomcat on the virtual machine

Case pre-knowledge Point KVM Virtualization Architecture

The KVM module is directly integrated into the Linux kernel

KVM Driver:

1. Virtual machine creation

two。 Virtual machine memory allocation

3. Virtual CPU register read and write

4. Virtual CPU running

QEMU (simplified and modified):

1. User control components that simulate PC hardware

two。 Provide Icano device model and access to peripherals

There are three modes of KVM virtualization:

1. Customer mode (virtual machine)

two。 User mode (tool)

3. Kernel mode

How KVM works:

Demo: environmental preparation:

1. You need to add a disk first: the size is 20g

two。 Processor settings: all options for virtualization engine are checked

[root@client ~] # cd / dev [root@client dev] # lssda sda1 sda2 sda3 sda4 sda5 sdb # there is a sdb hard disk at this time

[root@client dev] # fdisk / dev/sdb

Welcome to fdisk (util-linux 2.23.2).

The changes remain in memory until you decide to write them to disk.

Think twice before using the write command.

Device does not contain a recognized partition table

Create a new DOS disk label using the disk identifier 0xba1e8e30.

Command (enter m for help): n # enter n

Partition type:

P primary (0 primary, 0 extended, 4 free)

E extended

Select (default p): P # enter p

Partition number (1-4, default 1):

Start sector (2048-41943039, default is 2048):

The default value of 2048 will be used

Last sector, + sector or + size {K _ Magne _ M _ G} (2048-41943039, default is 41943039):

The default value of 41943039 will be used

Partition 1 has been set to type Linux and the size is set to 20 GiB

Command (enter m for help): W # enter w to save exit

The partition table has been altered!

Calling ioctl () to re-read partition table.

Synchronizing disks.

[root@client dev] # mkfs / dev/sdb1 # format

Mke2fs 1.42.9 (28-Dec-2013)

File system label =

OS type: Linux

Block size = 4096 (log=2)

Chunk size = 4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5242624 blocks

262131 blocks (5.00%) reserved for the super user

First data block = 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: done

Writing inode table: complete

Writing superblocks and filesystem accounting information: done

[root@client dev] # mkdir / data # create mount

[root@client dev] # mount / dev/sdb1 / data/

[root@client data] # df-hT

File system type capacity used available used mount point

/ dev/sdb1 ext2 20G 44m 19G 1% / data

# now shows that it has been mounted

# the folder with CentOS 7 image files on the computer needs to be shared. Set the account Everyone to read it, and then use smbclient-L to view the mount.

[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 default share gfs Disk IPC$ IPC remote IPC ISO Disk rpm Disk

# now shows that the ISO folder is shared

[root@client data] # mount.cifs / / 192.168.10.190/ISO / mnt

Password for root@//192.168.10.190/ISO:

[root@client data] # df-h

File system capacity used available used% mount point

/ dev/sdb1 20G 44m 19G 1% / data

/ / 192.168.10.190/ISO 226G 173G 54G 77% / mnt

# this shows that the file was successfully mounted in the mnt directory

[root@client data] # cd / mnt/

[root@client mnt] # ls

CentOS-7-x86_64-DVD-1708.iso

# install KVM: ```bash [root @ client mnt] # yum list # self-test [root@client mnt] # yum groupinstall "GNOME Desktop"-y # Desktop Environment [root@client mnt] # yum install qemu-kvm- y # KVM Module [root@client mnt] # yum install qemu-kvm-tools-y # KVM debugging tool [root@client mnt] # yum install virt-install-y # build Virtual Simulated command tool [root@client mnt] # yum install qemu-img-y # qemu component Create disk Launch virtual machine [root@client mnt] # yum install bridge-utils-y # Network support tool [root@client mnt] # yum install libvirt-y # Virtual Machine Management tool [root@client mnt] # yum install virt-manager-y # Image Management Virtual Machine [root@client mnt] # egrep'(vmx | svm)'/ proc/cpuinfo # to see if virtualization [root@client mnt] # lsmod | grep kvm is supported # check whether KVM installs kvm_intel 170086 0kvm 566340 1 kvm_intelirqbypass 13503 1 kvm [root@client mnt] # systemctl start libvirtd [root@client mnt] # systemctl enable libvirtd # Boot configuration bridging instance: [root@client mnt] # cd / data/ [root@client data] # mkdir vdisk viso [root@client data] # lslost+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] # ifconfigens33: flags=4163 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 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. Omit multiple lines here [root@client network-scripts] # vim ifcfg-ens33# press o to go down at the last line to insert BRIDGE=br0# after the insertion is completed, press Esc to exit insert mode Input: wq save exit [root@client network-scripts] # vim ifcfg-br0TYPE= "bridge" # Ethernet to bridgePROXY_METHOD= "none" BROWSER_ONLY= "no" BOOTPROTO= "static" # dhcp to staticDEFROUTE= "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 to br0DEVICE= "br0" # ens33 to br0ONBOOT= "yes" IPADDR=192.168.18.145 # enter the IP address of ens33 NETMASK=255.255.255.0 # enter subnet mask GATEWAY=192.168.18.1 # enter gateway # modify exit insertion mode Enter: wq save exit [root@client network-scripts] # service network restart # restart network service Restarting network (via systemctl): [OK] [root@client network-scripts] # ifconfigbr0: flags=4163 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 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 0ens33: flags=4163 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. The following omits many lines # after bridging, the original ens33 network card IP goes back to the br0 and goes back to the graphical interface input: [root@client ~] # virt-manager will jump out of the virtual system manager interface at this time. We need to add storage pool custom pool name and click Browse directory, select directory / data/vdisk, find the folder directory where we mounted CentOS7, click finish, and then click add new volume to add mirror storage pool: iso, click forward. Select the path as / data/viso

After the creation is finished, you can click the file → in the upper left corner to close the file in the upper left corner of the virtual system manager and select the new virtual machine installation operating system to install locally, and click forward.

Use ISO image: click Browse, select iso storage pool, find the mirror, and click Select Volume

Click forward again, enter 2048 in memory, and then click forward

Select or create custom storage, click manage, select disk storage pool, click the previous volume, click select volume

Then click forward, and then click finish, which will take you to the Centos7 installation interface:

At this time, the KVM virtualization deployment experiment is successful!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report