Friends who play Linux often don't fret about creating a virtual machine environment, and then show how to create a virtual machine that can be used in 5 seconds.
Lab Environment:
Files Prepared:
Rh7_template.img and Rhel7.xml
If you do not have two files, you can use the following files directly.
Link: Https://pan.baidu.com/s/1ESlqw22wEY9HP2-kCFptpA Password: etyh
Link: Https://pan.baidu.com/s/1rm-sVkd3R7GtdVEyaFqeSQ Password: myh3
Place the downloaded file in the/var/lib/libvirt/images/and save it as a. Start file name
[[email protected] ~]# mv rh7_template.img /var/lib/libvirt/images/.rh7_template.img[[email protected] ~]# mv rhel7.xml /var/lib/libvirt/images/.rhel7.xml
Build a virtual Environment:
[[email protected] ~]# yum -y groups install 虚拟化平台 虚拟化主机 虚拟化客户端 // 真机是中文环境,如果是英文环境就安装 “Virtualization Platform” “Virtualization Host” “Virtualization Client” 每个部分之间要有空格隔开[[email protected] ~]# virt-manager //调出虚拟系统管理器,如
Go to edit-connect details--virtual network, such as
Add four virtual networks, respectively
Private1,private2,public1,public2
Click the left bottom plus sign to appear: (Take private1 as an example)
Complete.
PRIVATE1, the configured IP network segment is: 192.168.1.0/24
PRIVATE2, the configured IP network segment is: 192.168.2.0/24
PUBLIC1, the configured IP network segment is: 100.0.1.0/24
PUBLIC2, the configured IP network segment is: 100.0.1.0/24
Create a script for a virtual machine
The following connections can be downloaded directly using:
Link: https://pan.baidu.com/s/1lx_murPn7U09hywyuWSFyw Password: 4xq6
[Email protected] ~]# vim CLONE-VM7
#! /usr/bin/bash# Defining Variables img_dir=/var/lib/libvirt/imagesbasevm=rh7_templatenum= ' TR-DC ' 0-9a-f ' </dev/urandom |head-c 2 ' # Enter the number to create the virtual machine read-p "Enter VM No.:" vmnum# determine the input number if [-Z "${vmnum}"]; Then echo "You must input a number." Exit 1elif [$ (echo ${vmnum}*1 | BC) = 0]; Then echo "You must input a number." Exit 2elif [${vmnum}-lt 1-o ${vmnum}-gt 99]; Then Echo ' Input out of range ' exit 3fi# generate a new variable and determine if the file exists newvm=rh7_node${vmnum}if [-e $IMG _dir/${newvm}.img]; Then echo "File exists." Exit 4fi# Create the img file for the new virtual machine Echo-en "Creating virtual machines disk image......\t" Qemu-img create-f qcow2-b $IMG _DIR/.${BASEVM }.img $IMG _dir/${newvm}.img &>/dev/nullecho-e "\e[32;1m[ok]\e[0m" # Modify the XML file cat/var/lib/libvirt/images/for the new virtual machine. Rhel7.xml >/tmp/myvm.xml# Modify the host name and Uuidsed-i "/<name>${basevm}/s/${basevm}/${newvm}/" of the new virtual machine/tmp/myvm.xmlsed- I "/uuid/s/<uuid>.*<\/uuid>/<uuid>$ (uuidgen) <\/uuid>/"/tmp/myvm.xml# Modify the IMG path used by the new virtual machine sed- I "/${basevm}\.img/s/${basevm}/${newvm}/"/tmp/myvm.xml# template to 4 network cards, modify the MAC address of each network card sed-i"/mac/s/a1/${num}/"/tmp/ Myvm.xmlsed-i "/mac/s/a2/${num}/"/tmp/myvm.xmlsed-i "/mac/s/a3/${vmnum}/"/tmp/myvm.xmlsed-i "/mac/s/b1/${num}/"/t Mp/myvm.xmlsed-i "/mac/s/b2/${num}/"/tmp/myvm.xmlsed-i "/mac/s/b3/${vmnum}/"/tmp/myvm.xmlsed-i "/mac/s/c1/${num}/ "/tmp/myvm.xmlsed-i"/mac/s/c2/${num}/"/tmp/myvm.xmlsed-i"/mac/s/c3/${vmnum}/"/tmp/myvm.xmlsed-i"/mac/s/d1/${nu m}/"/tmp/myvm.xmlsed-i"/mac/s/d2/${num}/"/tmp/myvm.xmlsed-i"/mac/s/d3/${vmnum}/"/tmp/myvm.xml# import virtual machine configuration Echo-en" D efining new Virtual machine......\t\t "Virsh define/tmp/myvm.xml &>/dev/nullecho-e" \e[32;1m[ok]\e[0m "
Create a virtual machine
[Email protected] ~]#./clone-vm7
Enter VM number:1
Creating Virtual Machine disk image ... [OK]
Defining New Virtual machine ... [OK]
Note: The user name is the root password: 123456. The landing results are as follows:
Enter init 5 directly on the command line to enter the graphical interface mode
Note: Run level
Init 0 shutting down the host
Init 3 Multi-user command-line mode
Init 5 Graphical interface mode
Init 6 reboot Host
Init 1 and 2 are single-user and multi-user (no NFS)
CENTOS7 Settings command:
Systemctl Isolate Multi-user.target
Systemctl Isolate Graphical.target
Systemctl Set-default Target Level
Principle
Simply put:
The composition of a normal KVM virtual machine:
Host box and external device-------> Profile XML file (name,uuid,disk location, Nic Mac, etc.)
Disk------> virtual machine image file img file
Export and import operations for a virtual machine's configuration
Virsh dumpxml Virtual machine name > file name. xml (Print profile)
Virsh define file name. XML (Assembly Machine)
KVM-related commands
Virt-manager//Open Virtual System Manager
Virsh list--all//list all virtual machines
Virsh Start Virtual machine name//virtual machine boot
Virsh Destroy virtual machine name//forced power off shutdown
Virsh autostart Virtual machine name//virtual machine boot--disable cancel power-on self-booting
Virsh NodeInfo//View CPU information for virtual machine servers
Virsh dominfo Virtual machine name//view virtual machine configuration
Virsh Edit Virtual machine name//modify virtual Machine amount configuration
Encouragement: I hear and I forget. I see and I remember. I do and I understand!
Linux Next 5 Seconds create rhel7 virtual machine