In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
First, 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, but do not install [root@localhost media] # yum-y install virt-install # command line tool for building a virtual machine [root@localhost media] # yum-y install qemu-img # qemu component Create a disk, Start the virtual machine, [root@localhost media] # yum-y install bridge-utils # Network support tool [root@localhost media] # yum-y install libvirt # Virtual Machine Management tool [root@localhost media] # yum-y install virt-manager # graphical interface management virtual machine [root@localhost media] # yum-y install libguestfs-tools # used to manage virtual machine 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 libvirtd Services [root@localhost ~] # systemctl enable libvirtd # set this service to boot automatically
3. Create a virtual machine in command line mode
[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, and 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 status when it is off-test01 off-test02 off- Web01 shutdown # is to clone the [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] # ls in the current directory with the dumpxml tool # confirm that the backup is 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 configuration of the UUID line Prevent conflict 1048576. # omit part of the content # navigate to the line label / usr/libexec/qemu-kvm # change the path here to the web02.raw file you just copied with the cp command # after the change is complete, save and exit [root@kvm qemu] # virsh define web02.xml # define this configuration document # (it can be understood as loading the virtual machine, at this time Need to pay attention to the current work path) define the domain web02 (from web02.xml) [root@kvm qemu] # virsh list-- all # to see whether the Id name status has been cloned successfully-test01 pass Close-test02 close-web01 close-web02 close # 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 of the content
Third, add web01 to boot, what are the similarities and differences with web02?
[root@kvm qemu] # virsh dominfo web01 # this command can view the information of the specified virtual machine Id:-name: web01UUID: 2d6f2a7c-9937-4afb-b8d6-8ef01ca61434OS type: hvm status: turn off CPU: 1 maximum memory: 1048576 KiB used memory: 1048576 KiB persistent: is automatic start: disable # save of state management is disabled here: no security Universal mode: none security DOI: 0 [root@kvm qemu] # virsh autostart web01 # set web01 to boot domain web01 marked to start automatically [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 maximum memory: memory used by 1048576 KiB: 1048576 KiB persistence: auto 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.4s maximum memory: 1048576 KiB memory used: 1048576 KiB persistent: auto start: disabled # is disabled state management save: no security mode: none security DOI: "you can 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 automatically, under the premise that the libvirtd service boots automatically # it will start with the start of the host
4. Two methods of connecting virtual machines remotely
(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 this virtual machine for the changes to take effect
(2) use console to log in to web02
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 100 00 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 0 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):
6. Summary of KVM virtual machine management commands
[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 # normally shut down the virtual machine [root@kvm ~] # virtual machine name # force shut down the virtual machine (similar to unplugging Power) [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 virtual machine disk for use [root@kvm disk] # qemu-img create-f qcow2 21.qcow2 2G # create qcow2 format virtual machine disk [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 # these are all 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 in the disk file RAW: naked format of the clone virtual machine. 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.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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: 0
*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.