One to solve the KVM virtualization platform deployment (detailed steps)

1. Virtual machine environment and configuration requirements before deployment

CPU Dual-core thread-cpu virtualization enabled
RAM 8G
hard disk 300G
Dual network card Single network card
operating system Centos 7.4

2. Virtual machine environment installation settings

2.1 Modify the host name

[root@kvm ~]# hostnamectl set-hostname kvm 

2.2 Mounting the CD image

[root@kvm ~]# vim /etc/fstab
/dev/cdrom /mnt iso9660 defaults 0 0
[root@kvm ~]# mount -a 
[root@kvm ~]# df -hT
/dev/sr0       iso9660   4.3G  4.3G     0  100% /mnt


2.3 Environmental optimization

设置DNS反向解析

#是否反解DNS,设置为NO可以让客户端连接服务器更快

[root@kvm ~]# vim /etc/ssh/sshd_config 

#取消DNS注释,改为NO

UseDNS no

2.4 Make a local YUM warehouse

cd /etc/yum.repos.d/  // yum目录
mkdir backup // 新建目录,名字为backup
mv C* backup // 把所有的yum源文件全部剪切到backup下做备份,防止误删除
cp backup/CentOS-BXXX.repo  local.repo // 拷贝模板,模板名称叫local.repo
vi local.repo //进入模板
 1[base]
      2 name=CentOS-$releasever - Base
      3 mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
      4 baseurl=file:///mnt
      5 gpgcheck=0
      6 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 // 将此行进行注释
      7 enable=1
[root@kvm yum.repos.d]# yum clean all 
[root@kvm yum.repos.d]# yum repolist

2.5 Turn off the firewall and core protection

systemctl stop firewalld //临时关闭防火墙 systemctl disable firewalld //永久关闭防火墙 setenforce 0 // 临时核心防护 vi /etc/selinux/config //永久核心防护 SELINUX=disabled

3. Install KVM

3.1 Install KVM basic components

# 安装 GNOME 桌面环境  如果装了图形界面可以不需要装
yum groupinstall -y "GNOME Desktop"
# KVM 模块
yum -y install qemu-kvm
# 安装KVM 调试工具,可不安装
yum -y install qemu-kvm-tools
# 构建虚拟机的命令行工具
yum -y install virt-install
# qemu 组件,创建磁盘、启动虚拟机等
yum -y install qemu-img
# 网络支持工具
yum -y install bridge-utils
# 虚拟机管理工具
yum -y install libvirt
# 图形界面管理虚拟机 
yum -y install virt-manager

3.2 Check whether the CPU supports virtualization

[root@localhost ~]# cat /proc/cpuinfo | grep vmx    
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr 
pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht 
syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl 
xtopology tsc_reliable nonstop_tsc 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 ssbd ibrs ibpb stibp tpr_shadow 
vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 
invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat 
spec_ctrl intel_stibp flush_l1d arch_capabilities

3.3 Check whether the KVM module is installed

Lsmod:显示已载入的系统模块

[root@kvm ~]# lsmod | grep kvm

kvm_intel             183621  0 

kvm                   586948  1 kvm_intel

irqbypass              13503  1 kvm


3.4 Set the display mode of the startup interface

[root@kvm ~]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target


4 Facilities KVM network

Description: Two modes of KVM network:

  • ① NAT: The default setting, data packets are carried out through the host interface by NAT

Transfer, you can access the external network, but cannot access the virtual machine network from the outside

  • ② Network bridge: This mode allows the virtual machine to have a network like an independent host. The external machine can directly access the inside of the virtual machine, but it needs network card support (generally wired network card supports)

4.1 Deploy using Bridge mode

[root@bdqn ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=aac61931-47a6-40e5-9511-68adf20e97c5
DEVICE=ens33
ONBOOT=yes
#IPADDR=20.0.0.60
#PREFIX=24
#GATEWAY=20.0.0.2
BRIDGE=br0              #删除原先地址,设置为网桥模式,关联br0网卡

4.2 Create and edit bridged network card

  • Create a br0 network card configuration file and configure the following:
vim /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=20.0.0.60
NETMASK=255.255.255.0
GATEWAY=20.0.0.2

5. KVM deployment and management

5.1 Create a directory for KVM storage and mirroring data, upload centos7 mirror


[root@kvm network-scripts]# mkdir -p /data_kvm/iso
[root@kvm network-scripts]# mkdir -p /data_kvm/store
[root@kvm abc]# cp -p CentOS-7-x86_64-DVD-1806.iso /data_kvm/iso/
#查看镜像

[root@kvm abc]# ll /data_kvm/iso/

总用量 4481024
-rwxr-xr-x. 1 root root 4588568576 2月  20 2019 CentOS-7-x86_64-DVD-1810.iso

5.2 Using Virtual System Manager to Manage Virtual Machines

Enter the graphical interface, if the above operation is in xshell, then the following command should be typed in the vm virtual machine

[root@kvm kvmdata]# virt-manager
  • After entering the interface, the selection operations are as follows:

Insert picture description here

Insert picture description here

  • ①Create storage pool (ISO, STORE)

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

  • ②Add storage volume

Insert picture description here

  • ③Create a virtual machine

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

After selecting, click to start the installation.

Guess you like

Origin blog.csdn.net/Lihuihui006/article/details/110877188