KVM virtualization platform deployment
Article Directory
Experiment preparation
1. Virtual machine preparation
Virtual machine hardware resources
Memory: 8G
CPU: dual-core dual-thread-------CPU virtualization turned on
Hard disk: 300G
Operating system: Centos 7.6 (1810)
Network card: NAT (enter system changes)
and then select Install CentOS7 to enter the following interface
After clicking Finish, click "Accept Changes", jump back to the installation information summary and click "Start Installation".
If the prompt is too simple, you can click twice to complete the root password, and the setting will be successful, and then wait for the virtual machine to slowly install successfully.
There is also a direct forward in the middle.
Skip and enter this interface. After setting the user name, click forward
and then you can use CentOS. The entered page is directly closed.
Enter the user name "root" and its password to log in to CentOS, and then start the following operating
2. Preparation in the system
(1) Modify the host name
Right-click to open the terminal
hostnamectl set-hostname kvm
su
(2) Set the mirrored disc to auto/permanently mount
vim /etc/fstab
/dev/cdrom /mnt iso9660 defaults 0 0
mount -a
df -hT
(3) Environmental optimization
Set DNS reverse resolution
Whether to reverse DNS resolution , set to NO can make the client connect to the server faster
vim /etc/ssh/sshd_config
#115行;取消DNS注释,改为NO
UseDNS no
(4) Make a local YUM warehouse
cd /etc/yum.repos.d/
mkdir repos.bak
mv CentOS-* repos.bak
vim kvm.repo
[kvm]
name=kvm
baseurl=file:///mnt
gpgcheck=0
enabled=1
yum clean all && yum repolist
(5) Turn off the firewall and security mechanism
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
Start experiment
1. Install KVM
(1) Install KVM basic components
Use yum to install it, there are a lot of pictures here, no more pictures.
yum groupinstall -y "GNOME Desktop"
yum -y install qemu-kvm
yum -y install qemu-kvm-tools
yum -y install virt-install
yum -y install qemu-img
yum -y install bridge-utils
yum -y install libvirt
yum -y install virt-manager
#----------------------命令解释---------------------
# 安装 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
Check whether the CPU supports virtualization
cat /proc/cpuinfo | grep vmx
# 查看CPU是否支持虚拟化
Check whether the KVM module is installed
Lsmod: display the loaded system module
lsmod | grep kvm
(2) Set the display mode of the startup interface
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
2. Set up the KVM network
Two modes of KVM network:
- NAT: The default setting, data packets are transmitted through the host's interface by NAT, which can access the external network, but cannot access the virtual machine network from the outside
- Bridge: This mode allows the virtual machine to have a network like an independent host. External machines can directly access the inside of the virtual machine, but need network card support (generally wired network cards support)
use Bridge bridge mode for deployment
vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=none
IPV6INIT=no
ONBOOT=yes
BRIDGE=br0 #删除原先地址,设置为网桥模式,关联br0网卡
Create and edit bridged network cards
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=192.168.2.200
NETMASK=255.255.255.0
GATEWAY=192.168.2.2
systemctl restart network.service
3. KVM deployment and management
For other configurations of window sharing files to centos, please refer to my other blog: How to share files on windows to Linux
Create a directory for KVM storage and mirroring data, upload a centos7 mirror
mkdir -p /data_kvm/iso
mkdir -p /data_kvm/store
mount.cifs //192.168.2.1/iso /mnt/
cd /mnt
cp -p CentOS-7-x86_64-DVD-1810-7.6.iso /data_kvm/iso/
ll /data_kvm/iso/
4. Use virtual system manager to manage virtual machines
Create ideas:
1) Create storage pool (ISO, STORE)
2) Add storage volume
3) Create virtual machine
virt-manager
(1) Create a storage pool
(2) Create a storage volume
(3) Create a virtual machine
Then the following operation is actually to install centos7 normally, no more details, there may be stuck, because the allocated configuration is not too high