KVM virtualization platform practical operation

KVM virtualization platform practical operation

Centos7 system deployment optimization and KVM environment preparation. After the
centos7 system is installed, you need to check the KVM virtualization function and select the NAT mode
Insert picture description here
for the network card. Set the mirror CD to be automatically mounted

[root@localhost ~]# vim /etc/fstab 
/dev/sr0 /mnt iso9660 defaults 0 0	#尾行添加

Optimize ssh

[root@localhost ~]# vim /etc/ssh/sshd_config 
UseDNS no	     #取消注释,并将yes改成no

yum local warehouse building

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv * bak
mv: 无法将目录"bak" 移动至自身的子目录"bak/bak" 下
[root@localhost yum.repos.d]# ls
bak
[root@localhost yum.repos.d]# vim abc.repo
输入以下信息
[abc]
name=test
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]# yum clean all	#清空yum仓库
[root@localhost yum.repos.d]# mount /dev/sr0 /mnt	# 因为没有重启,所以需要手动挂载一下光盘镜像
[root@localhost yum.repos.d]# yum makecache	#加载yum数据

Firewall optimization

[root@localhost yum.repos.d]# systemctl stop firewalld.service 
[root@localhost yum.repos.d]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost yum.repos.d]# setenforce 0
[root@localhost yum.repos.d]# vim /etc/selinux/config 
SELINUX=disabled       # 将enforcing修改为disabled

All deployment optimizations have been completed, restart the system

[root@localhost yum.repos.d]# init 6

Install KVM

Install yum source

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

Note: After installing the desktop with yum, some optimizations are needed

执行 ln -sf /lib/systemd/system/graphical.target
/etc/systemd/system/default.target 命 令 , 将 系 统 的 默 认 运 行 target 更 改 为graphical.targe。 重启后系统将进入图形化界面。

Do some checks

[root@localhost ~]# cat /proc/cpuinfo | grep vmx     #查看CPU是否支持虚拟化
[root@localhost ~]# lsmod | grep kvm   #查看KVM模块是否安装
kvm_intel             170086  0 
kvm                   566340  1 kvm_intel
irqbypass              13503  1 kvm
[root@localhost ~]#  systemctl start libvirtd       #开启libvirtd服务
[root@localhost ~]#  systemctl enable libvirtd   #开机启动libvirtd服务

Set the KVM network as a bridge
■ After installing the KVM on the host server, you must first set up the network. There are two ways to run the KVM network in libvirt:
NAT and Bridge. The default is NAT.
User mode, that is, NAT mode. This mode is the default network. Data packets are
transmitted through the host's interface by NAT mode . You can access the external network, but you cannot access the virtual machine network from the outside.
Bridge mode. 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 it needs network card support. Generally, wired network cards support.
Take Bridge as an example here.

Modify ens33 network card

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO=none	#原本的修改为none
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="ens33"
UUID="0739b616-18e4-49b1-9a09-f75cc793899b"
DEVICE="ens33"
ONBOOT="yes"
#IPADDR=192.168.15.10
#NETMASK=255.255.255.0
#GATEWAY=192.168.15.2
#DNS1=8.8.8.8
BRIDGE=br0	#注释掉原本的IP地址,添加此处

New bridged network card

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
OTPROTO=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.15.10
NETMASK=255.255.255.0
GATEWAY=192.168.15.2
#添加上述内容即可'
[root@localhost ~]# systemctl restart network	#重启网卡
[root@localhost ~]# ip a

Insert picture description here

KVM management

Create KVM storage and mirror folders, and upload mirrors

[root@localhost ~]# mkdir -p /data_kvm/iso   #上传镜像centos 7.6的镜像
[root@localhost ~]# mkdir -p /data_kvm/store    #虚拟机存储
[root@localhost ~]# mount.cifs //192.168.15.1/share /mnt
Password for root@//192.168.15.1/share:  
[root@localhost ~]# cd /abc/Linux/
[root@localhost Linux]# cp CentOS-7-x86_64-DVD-1810.iso /data_kvm/iso/
[root@localhost Linux]# ls /data_kvm/iso/
CentOS-7-x86_64-DVD-1810.iso
[root@localhost Linux]# 
[root@bdqn ~]# virt-manager     #图形界面敲,打开虚拟系统管理器

Create a storage pool
Double-click to open QEMU/KVM-storage-add (plus sign)-fill in the name-forward-browse-other locations-computer-data_kvm-store-open-finish, use the same method to create a mirrored storage pool, the selected folder is /data_kvm/iso
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description hereCreate a storage volume
Insert picture description here
Insert picture description here

Start creating a virtual machine

Open the virtual system manager-right-click QEMU/KVM-select new and
Insert picture description hereselect use ISO image-browse to select the image in the storage pool of the image just created-move forward
Insert picture description here
Configure memory and CPU-move forward
Insert picture description here
management-select the storage in the storage pool just created Volume-Forward
Insert picture description here
Click to customize the configuration before installation-Select network (bridge)-Finish
Insert picture description here
Click on boot option-Check to start the virtual machine when the host boots-Start the installation-a prompt appears, select Yes to
Insert picture description here
see the effect
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_50345054/article/details/112648581