当前位置:网站首页>Quickly build KVM virtual machine on # yyds dry goods inventory # physical machine
Quickly build KVM virtual machine on # yyds dry goods inventory # physical machine
2022-06-24 23:27:00 【Feng, crazy】
1. Download the virtual machine image file
Find the image file by yourself (cdsn Downloading usually requires points ), Or contact me ( I use it centos Mirror image , The kernel version is 2015 Years old , You need to upgrade later )
wget filepath // Download the file
- 1.

2. Enable virtualization configuration for physical machine
grep vmx /proc/cpuinfo
- 1.
If there is vmx Information output , It means that we support VT; If there is no output , Explain your cpu不 Support , Will not be available KVM virtual machine
lsmod | grep kvm
- 1.
If there is no output information, you need to load kvm

// Unloading module
modprobe -r kvm_intel // You don't have to execute
// Reload module
modprobe kvm
modprobe kvm_intel // Reload module
lsmod | grep kvm
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.

3. Nested virtualization ( If not, please skip )
cat /sys/module/kvm_intel/parameters/nested
Y
modprobe kvm-intel nested=1
- 1.
- 2.
- 3.
4. to update yum The warehouse is Alibaba cloud
Easy to install packages are the latest
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
&&
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
- 1.
- 2.
- 3.
5. loading virsh Required plug-ins
yum install -y qemu-kvm qemu-kvm-tools
&&yum install -y libvirt
&&yum install -y virt-install
&&yum install -y python-urllib3
&& yum install libguestfs-tools
//libguestfs-tool yes virt Related packages
// View the virtual machine installation log
cat /var/log/libvirt/qemu/centos7_15.log
virsh list --all // Error, please restart libvirtd
systemctl status libvirtd
// View the service status
systemctl start libvirtd
// Start the service
systemctl enable libvirtd
// Boot up
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
6. Set up virtual machine network
brctl addbr br0
//192.168.66.254 It's the gateway , The network segment can be selected by itself 192.168.66.0/24
ifconfig br0 192.168.66.254/24(yum install net-tools)
// Visit the Internet enp24s0f1 It is a physical network card
iptables -t nat -A POSTROUTING -s 192.168.66.0/24 -o enp24s0f1 -j MASQUERADE
//192.168.103.50 It's a physical machine ip, The following is remote forwarding 192.168.66.1 Is the first virtual machine
iptables -t nat -A PREROUTING -d 192.168.103.50 -p tcp --dport 53301 -j DNAT --to-destination 192.168.66.1:22
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
7. establish kvm
frequently-used kvm The format is raw Follow qcow2
qemu-img create -f qcow2 /home/vm/vm1.qcow2 200G
virt-install \
--virt-type kvm \
--name vm1 \
--vcpus 16 \
--memory 32768 \
--cdrom=/home/vm/CentOS-7-x86_64-Minimal-1511.iso \
--disk path=/home/vm/vm1.qcow2 \
--network bridge=br0 \
--graphics vnc,listen=0.0.0.0 \
--os-type=linux \
--os-variant=rhel7
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
installation is complete
virsh list // View virtual machine
virsh vncdisplay vm1 // see vnc port vnc Log in to use VNC Server Fill in this column ip:port
- 1.
- 2.

Need to download one vnc Client to connect vm1 Deploy the operating system ( The first installation requires vnc The latter is used directly virt-clone machine )
Just follow VMware The same steps as installing the virtual machine , But faster , Because there is no graphical interface


frequently-used virsh command :
virsh list
virsh start vm1
virsh shutdown vm1
virsh edit vm1 // Profile can be modified
virsh vncdisplay vm1
virsh undefine vm1 // Delete with then rm -rf vm1.qcow2
virsh destroy vm1 // closed
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
8. Network card configuration
eth0 Is the name of the network card
vi /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
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
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.66.1
NETMASK=255.255.255.0
GATEWAY=192.168.66.254
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
9. Kernel upgrade
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-ml -y
vi /etc/default/grub
# Set up GRUB_DEFAULT=0, intend GRUB The first kernel of the initialization page will be the default kernel
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot // Reselect the first one to boot the kernel
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
10. Clone virtual machine
virt-clone -o vm1 -n vm2 -f /home/vm/vm2.qcow2
- 1.
After cloning, you can directly use ssh Sign in , The premise is to shut down the clone machine , Otherwise ip Conflict
qemu-img convert -f raw -O qcow2 /home/vm/vm1.raw /home/vm/vm1.qcow2
// Two kinds of kvm format conversion qcow2 Fast raw Good storage performance
- 1.
- 2.
11. Possible network problems
iptables Command Reference :
iptables -t nat --line-number -nvL
iptables -t nat -D PREROUTING 1
// Visit the Internet
iptables -t nat -A POSTROUTING -s 192.168.55.0/24 -o enp24s0f1 -j MASQUERADE
//ip route add default via 192.168.63.1
iptables -t nat -A PREROUTING -d 192.168.103.50 -p tcp --dport 53301 -j DNAT --to-destination 192.168.44.1:22
//vnc to open up vnc Access port
iptables -I INPUT -p tcp --dport 5900:5920 -j ACCEPT
// Firewall problem
iptables -I FORWARD -s 192.168.66.0/24 -j ACCEPT//dns Unavailability issues
iptables -I FORWARD -d 192.168.66.0/24 -j ACCEPT// This machine 533 Port login
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
边栏推荐
- 02_ Springboot starter case
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the AIC function to compare the AIC values of the two models (simpl
- R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
- Laravel study notes
- File contains vulnerability issues
- 376. Tâches mécaniques
- Construction equipment [6]
- Main cause of EMI - mold current
- Websocket long link pressure test
- Tech talk activity review kubernetes skills of cloud native Devops
猜你喜欢

【js】-【树】-学习笔记

Jetpack Compose 最新进展

Still using simpledateformat for time formatting? Be careful of project collapse

Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine

EMI的主要原因-工模电流

From client to server

22map introduction and API

Case analysis: using "measurement" to improve enterprise R & D efficiency | ones talk
![[JS] - [array application] - learning notes](/img/8a/808fde0cc86e0ec5e1f5558ba196b4.png)
[JS] - [array application] - learning notes
Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!
随机推荐
Dig deep into MySQL - resolve the clustered index / secondary index / federated index of InnoDB storage engine
Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
golang map clear
Listen to the markdown file and hot update next JS page
Collation of Digital IC design experience (II)
What good smart home brands in China support homekit?
Selection (028) - what is the output of the following code?
SimpleDateFormat 格式化和解析日期的具体类
数字IC设计经验整理(二)
Binary lookup array subscript
R语言使用epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、自定义FUN参数为多个统计量函数名称的列表计算多个统计量
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the AIC function to compare the AIC values of the two models (simpl
golang convert map to json string
Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!
How to add Google maps to a project
idea创建模块提示已存在
Ganglia 的安装与部署
记录一下MySql update会锁定哪些范围的数据
R语言dplyr包select函数将dataframe数据中的指定数据列移动到dataframe数据列中的第一列(首列)
OpenSSL SSL_ read: Connection was reset, errno 10054