In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Blog outline:
First, install kvm virtualization; second, manually change the way of the configuration file, clone web01, generate a new virtual machine web02;; third, add web01 to boot self-boot, what are the similarities and differences with web02; fourth, two methods of remote connection to virtual machines; fifth, use the default NAT network type to enable web02 to ping the extranet. Install kvm Virtualization [root@localhost media] # yum-y groupinstall "GNOME Desktop" # install GNOME Desktop Environment [root@localhost media] # yum-y install qemu-kvm # KVM Module [root@localhost media] # yum-y install qemu-kvm-tools # KVM debugging tool Do not install [root@localhost media] # yum-y install virt-install # command line tool for building virtual machines [root@localhost media] # yum-y install qemu-img # qemu components Create a disk, Start virtual machines, etc. [root@localhost media] # yum-y install bridge-utils # Network support tools [root@localhost media] # yum-y install libvirt # Virtual Machine Management tools [root@localhost media] # yum-y install virt-manager # graphical interface management virtual machines [root@localhost media] # yum-y install libguestfs-tools # to manage virtual machines Disk format [root@localhost ~] # ls-sf / lib/systemd/system/graphical.target / etc/systemd/system/default.target# changes the default running target of the system to graphical.target If you do not execute the command, an error may be reported when you restart.
2. After installation, restart the system and execute the following command to check the system:
[root@localhost ~] # cat / proc/cpuinfo | grep vmx # check whether the CPU of Intel supports virtualization, if it is the CPU of AMD Need "cat / proc/cpuinfo | grep smv" [root@localhost ~] # lsmod | grep kvm # check whether the KVM module installs kvm_intel 170181 0 kvm 554609 1 kvm_intelirqbypass 13503 1 kvm [root@localhost ~] # systemctl start libvirtd # start the libvirtd service [root@localhost ~] # systemctl enable libvirtd # set this service to boot automatically
3. Create a virtual machine in command line mode (create a virtual machine graphically, please refer to the blog post: create a new virtual machine on a graphical desktop)
[root@kvm kk] # mkdir-p / kvm/ {iso,disk} # create the appropriate directory while storing the image and virtual machine disk # the / kvm directory created is best mounted on the LVS volume So that the volume space [root@kvm iso] # cp / media/CentOS-7.iso / kvm/iso/ # can be dynamically extended to prepare the virtual machine operating system file [root@kvm] # qemu-img create-f raw / kvm/disk/web01.raw 10G # to create a virtual machine disk [root@kvm ~] # virt-install-- os-variant centos7.0-- name web01-- ram 1024-- vcpus 1-- disk/ kvm/disk/web01.raw,format=raw Size=10-- location / kvm/iso/CentOS-7.iso-- network network=default-- graphics vnc,listen=0.0.0.0-- noautoconsole # create virtual machine web01 to start installation. Search for the file .treeinfo. | 354B 00:00 searches for files vmlinuz. 5.9 MB 00:00 search for files initrd.img. | 50 MB 00:00 domain installation is still in progress. You can reconnect to the console to complete the installation process. # Open the graphical console according to the above prompts [root@kvm ~] # virt-manager # Open the console
After entering the command to open the console, the following window pops up:
After clicking "Open", the following interface appears, which is the same as our own installation system (you can do it yourself):
At this point, the command line to create a virtual machine is complete, and then use the way to manually change the configuration file, clone web01, generate a new virtual machine web02 (in the link in the front of my blog post, there is a specific command tool for cloning, here is just to learn about the configuration file of the virtual machine)
Second, manually change the configuration file, clone web01 Generate a new virtual machine web02 [root@kvm iso] # virsh list-- all # ensure that the virtual machine to be cloned is in the Id name state of off-test01 Close-test02 close-web01 close # is to clone this [root@kvm] # cd / kvm/disk/ # switch to the virtual disk storage directory of the virtual machine [root@kvm disk] # cp web01.raw web02.raw # make a copy of the virtual machine disk to be cloned And change the name [root@kvm disk] # cd / etc/libvirt/qemu/ # to the directory of KVM virtual machine configuration files [root@kvm qemu] # ls # View the files in the current directory networks test01.xml test02.xml web01.xml [root@kvm qemu] # virsh dumpxml web01 >. / web02.xml # backup the configuration files of web01 to web02.xml [root@kvm qemu] # in the current directory with the dumpxml tool Ls # confirm backup successful networks test01.xml test02.xml web01.xml web02.xml [root@kvm qemu] # vim web02.xml # Edit the backed up file web02 # change the name here to web02 2d6f2a7c-9937-4afb-b8d6-8ef01ca61434 # Delete the UUID line configuration Prevent conflicts 1048576. # omit part # navigate to the line label / usr/libexec/qemu-kvm # change the path here to the web02.raw file you just copied using the cp command # after the change is completed Save exit [root@kvm qemu] # virsh define web02.xml # define this configuration document # (it can be understood as loading the virtual machine, at this time You need to pay attention to the current work path) define the domain web02 (from web02.xml) [root@kvm qemu] # virsh list-- all # to see if the Id name status has been cloned successfully Test01 off-test02 off-web01 off-web02 off # OK! When you see it, you can run web02 on your own to test whether it is working properly. [root@kvm qemu] # virsh start web02 # launch web02 domain web02 has started [root@kvm qemu] # virsh list-- all # OK, running! Id name status-3 web02 running. # omit part 3. Add web01 to boot What are the similarities and differences between web02 and [root@kvm qemu] # virsh dominfo web01 # this command can view the information of a specified virtual machine Id:-name: web01UUID: 2d6f2a7c-9937-4afb-b8d6-8ef01ca61434OS type: hvm status: off CPU: 1 maximum memory: 1048576 KiB memory used: 1048576 KiB persistent: automatic startup: Disable # default here to disable state management saving: no security mode: none security DOI: 0 [root@kvm qemu] # virsh autostart web01 # set web01 to boot domain web01 marked as auto start [root@kvm qemu] # virsh dominfo web01 # check whether it is set to boot Id:-name: web01UUID: 2d6f2a7c-9937-4afb- B8d6-8ef01ca61434OS type: hvm status: off CPU: 1 Max memory: 1048576 KiB memory used: 1048576 KiB persistent: automatic start: enable # OK! Managed save: no security mode: none security DOI: 0 [root@kvm qemu] # virsh dominfo web02 # check whether web02 is self-starting Id: 3 name: web02UUID: f554ad15-1b67-4f01-b203-a9d0c3abe192OS type: hvm status: runningCPU: 1CPU time: 21.4 s maximum memory: 1048576 KiB memory used: 1048576 KiB persistent: Auto start: disable # disable state management save: no security mode: none security DOI: restart the host at this time Then check the status of the virtual machine (you need to make sure that the status of the libvirtd service is self-booting, otherwise there will be problems) [root@kvm qemu] # init 6 # restart the host [root@kvm ~] # virsh list # after the restart is completed Check the Id name status of the running virtual machine-1 web01 running# at this time, only web01 is running because it is set to boot Under the premise of self-booting of the libvirtd service, # it will start with the startup of the host. 4. Two ways to remotely connect the virtual machine (1) use VNC software
The installation of VNC is relatively simple, so I won't write much here.
[root@kvm ~] # virsh vncdisplay web02: 0
Open vnc to connect (pay attention to firewall-related configuration):
To facilitate the next connection using console, you need to adjust the kernel parameters of the virtual machine (web02), as follows:
[root@localhost ~] # grubby-- update-kernel=ALL-- args= "console=ttyS0" # execute this command in the virtual machine [root@localhost ~] # init 6 # restart the virtual machine for the changes to take effect (2) Log in to web02 using console
Log in successfully by executing the following command on the KVM host (provided that the kernel parameters of web02 have been changed when logging in using vnc)
[root@kvm ~] # virsh console web02 # execute this command to connect to the domain web02 code exchange character ^] # hit the enter key CentOS Linux 7 (Core) Kernel 3.10.0-862.el7.x86_64 on an x86_64web02 login: root # enter the user name and password of web02 to log in. Password: Last login: Wed Oct 9 21:20:48 on tty1 [root@web02 ~] # 5. Use the default NAT network type to enable web02 to ping the extranet.
Here is the ping Baidu test, be sure to ensure that the KVM host can ping Baidu.
(1) check the relevant configuration
[root@kvm ~] # virsh net-list-- all name status automatically starts persistence-default activity is [root @ kvm ~] # ifconfig .virbr0: flags=4163 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 [root@kvm ~] # brctl showbridge name bridge id STP enabled interfacesvirbr0 8000.525400a8bf19 yes virbr0-nic Vnet0 [root@kvm ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.1.0 0.0.0.0 255.255.255.0 U 1000 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 virbr0
(2) next, start configuring the nat network.
[root@kvm ~] # virsh net-define / usr/share/libvirt/networks/default.xml # if you do not have the file specified above, you can use this command to define a virtual network or modify the file to create your own virtual network [root@kvm ~] # virsh net-autostart default # Network default marked to automatically start [root@kvm ~] # virsh net-start default # start the network, if it has been started An error will be reported here [root@kvm ~] # vim / etc/sysctl.conf # modify this configuration file. # omit part of the content net.ipv4.ip_forward=1 # add the line at the end of the file In order to allow IP to forward [root@kvm ~] # vim / etc/libvirt/qemu/web02.xml. # omit part of the content # locate the keyword "interface" and make sure there is the above content. # omit part of the content
(3) Connect to the virtual machine web02 and change the configuration of the network card:
[root@web02~] # vi / etc/sysconfig/network-scripts/ifcfg-eth0 # Edit the Nic configuration file
After changing the network card, save and exit.
[root@web02~] # systemctl restart network # restart the network service of the web02 virtual machine
Conduct a ping test:
To use static IP, the configuration file can be changed as follows (restart the Nic by yourself after the change is complete, and you can add the DNS configuration):
VI. KVM virtual machine management command summary [root@kvm ~] # virsh start virtual machine name # enable virtual machine [root@kvm ~] # virsh list # View only the list of running virtual machines [root@kvm ~] # virsh list-- all # View the list of all virtual machines [root@kvm ~] # virsh shutdown virtual machine name # normal shutdown virtual machine [root@kvm ~] # virsh destroy virtual machine name Say # forced shutdown of virtual machines (similar to unplugging) [root@kvm ~] # virsh dumpxml virtual machine name > / root/test01-dum.xml # virtual machine backup [root@kvm ~] # virsh undefine virtual machine name # delete virtual machine (note: after undefining Disk files need to be manually deleted) [root@kvm ~] # virsh define backed up .xml virtual machine file # restore virtual machine [root@kvm ~] # virsh edit virtual machine name # Edit the configuration file of the virtual machine [root@kvm ~] # virsh domrename the name to be changed # for example: ([root@kvm ~] # virsh domrename test01 test03) change the virtual machine name [root@kvm qemu] # virsh dominfo test02 # View the details of the virtual machine [root@kvm ~] # virsh autostart test02 # set the virtual machine to boot [root@kvm] # virsh autostart-- disable test02 # cancel boot self-boot [root@kvm ~] # virsh vncdisplay test02 # View the corresponding VNC connection port number The default first port number is: 5900 (denoted by ": 0") [root@kvm ~] # virsh suspend test02 # suspend virtual machine [root@kvm ~] # virsh resume test02 # cancel suspending virtual machine [root@kvm ~] # virsh console test02 # console login virtual machine [root@kvm ~] # qemu-img info / kvm/disk/test01.raw # View virtual machine disk information [root@kvm disk] # qemu-img create test.raw 2G # create disk for virtual machine [root@kvm disk] # qemu-img create-f qcow2 21.qcow2 2G # create virtual machine disk in qcow2 format [root@kvm disk] # qemu-img convert-f raw-O qcow2 test.raw test.qcow2 # convert test.raw disk format raw to qcow2 [root@kvm qemu] # virsh snapshot-create test02 # create Virtual machine snapshot [root@kvm disk] # virsh snapshot-list test02 # View virtual machine snapshot [root@kvm disk] # virsh snapshot-revert test02 1570692304 # restore snapshot [root@kvm disk] # virt-clone-auto-clone-o test01-n specify the name to be cloned (optional) # automatic clone virtual machine [root@kvm disk] # virt-clone-o test01-n test04-f / kvm/disk/test04 .qcow2 # Manual Clone # all of the above are full clones. [root@kvm disk] # qemu-img create-f qcow2-b test01.qcow2 lktest01.qcow2#-f: specify the disk format to be cloned; #-b: specify the source file and target file to be converted # the above command is to clone the disk file of the virtual machine
RAW: naked format. It takes up a lot of space and has good performance, but the snapshot function is not supported.
Qcow:copy on write (replication mechanism on write).
Qcow2: small footprint and poor performance compared to RAW, but it supports snapshots.
-this is the end of this article. Thank you for reading-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 256
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.