In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Through blog deployment and graphical management KVM has been able to manage the virtual machine of the KVM platform graphically. This blog mainly introduces how to manage the virtual machine of the KVM platform through the command line.
Blog outline:
I. Environmental requirements
2. Installation mode
Third, the method of connecting KVM virtual machine remotely.
4. Use the default method to enable the KVM virtual machine to access the Internet.
Fifth, KVM common commands
I. Environmental requirements
If it is a real server, then you need to enable the virtualization feature (Virtualization Technology) in BIOS, the general physical server, this feature is turned on by default. As shown in the figure:
If the lab environment uses VMware Workstation, you need to turn on this feature before turning it on. As shown in the figure:
2. Installation mode
The easiest way to install: install the virtualization feature when you install the system. As shown in the figure:
If the system has been installed and installed to a minimum, you need to do the following:
(1) install dependency package: [root@localhost ~] # yum groupinstall-y "GNOME Desktop" / / install GNOME desktop environment [root@localhost ~] # yum-y install qemu-kvm// install KVM module [root@localhost ~] # yum-y install qemu-kvm-tools// install KVM debugging tools (may not be installed) [root@localhost ~] # yum-y install virt-install// install command line tools for building virtual machines [root@localhost ~ ] # yum-y install qemu-img// install qemu components Create a disk, [root@localhost ~] # yum-y install bridge-utils// install network support tools [root@localhost ~] # yum-y install libvirt// install virtual machine management tools [root@localhost ~] # yum-y install virt-manager// install graphical interface management virtual machine if the system minimizes installation, execute this command [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) verify whether CPU supports virtualization [root@localhost ~] # cat / proc/cpuinfo | grep vmx//Intel server uses this command to verify (output means virtualization is supported) [root@localhost ~] # cat / proc/cpuinfo | grep smv//AMD server uses this command to verify (3) check whether the KVM module is installed [root@localhost ~] # lsmod | grep kvm// indicates that kvm has been installed _ intel 170181 0 kvm 554609 1 kvm_intelirqbypass 13503 1 kvm (4) start the libvirtd service Enable the corresponding support [root@localhost ~] # systemctl start libvirtd [root@localhost ~] # systemctl enable libvirtd// to start the libvirtd service, and set it to boot automatically (5) create a virtual machine with the command
You can refer to the blog post to install the virtual machine graphically.
[root@localhost ~] # mkdir-p / kvm/ {iso,disk} / / create a directory to store images and virtual machine disks [root@localhost ~] # cp / mnt/CentOS-7.iso / kvm/iso/// ready to install virtual machines [root@localhost ~] # qemu-img create-f raw / kvm/disk/web01.raw 10G// create virtual disks, and use "- f" to specify the disk type The size is 10g [root@localhost ~] # virt-install-- os-type=linxu-- 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 / / to create a virtual machine. Since the command configuration item is clear at a glance, there is no more introduction to start the installation. Search for the file .treeinfo. | 354B 00:00:00 searches for files vmlinuz. 5.9 MB 00:00:00 search for files initrd.img. | 50 MB 00:00:00 domain installation is still in progress. You can reconnect to the console to complete the installation process. [root@localhost ~] # virt-manager / / Open the Image Management console
[root@localhost ~] # after the installation of virsh start web01// is completed, start the web01 virtual machine. III. The method of remotely connecting the KVM virtual machine (1) using VNC software to connect the KVM virtual machine
Download VNC software
[root@localhost ~] # virsh vncdisplay web01 / / View the listening port of web01: 0 means port 5900 is listening, 1 means port 5901 is listening, and so on!
Experimental environment, I will directly turn off the firewall, do not want to close the firewall, then execute the following command!
[root@localhost ~] # firewall-cmd-- add-port=5900/tcp-- permanent [root@localhost ~] # firewall-cmd-- reload// opens port 5900 to facilitate VNC operation
Open VNC:
If you connect, the following occurs:
It means that in the KVM host, the virtual machine has opened a terminal and can be closed!
After the VNC connection is successful, we can adjust its kernel parameters, connect to the KVM virtual machine using console, and execute the following command in the KVM virtual machine:
[root@localhost ~] # grubby-- update-kernel=ALL-- args= "console=ttyS0" / / modify its kernel parameters so that it allocates a terminal [root@localhost ~] # reboot / / to console mode to restart this virtual machine, so that the change will take effect (2) use console mode to connect to the KVM virtual machine [root@localhost ~] # virsh console web01// log in to the web01 virtual machine using console mode
Login successful!
4. Use the default method to enable the KVM virtual machine to access the Internet.
[root@localhost ~] # ls / usr/share/libvirt/networks/default.xml [root@localhost ~] # virsh net-define / usr/share/libvirt/networks/default.xml / / confirm the existence of the above file. If not, you can use the above command to generate [root@localhost ~] # virsh net-autostart default / / Network default marked as automatically start [root@localhost ~] # virsh net-start default / / start the network, if it has been started. There will be an error [root@localhost ~] # echo "net.ipv4.ip_forward=1" > > / etc/sysctl.conf [root@localhost ~] # sysctl-pnet.ipv4.ip_forward = 1 sysctl / enable route forwarding [root@localhost ~] # vim / etc/libvirt/qemu/web02.xml. / / omit part of the content / / locate the "interface" keyword Make sure there is the above content.
Verify the KVM virtual machine:
Access to the Internet was successful!
5. KVM common command [root@localhost ~] # virsh start virtual machine name / / enable virtual machine [root@localhost ~] # virsh list / / View only the list of running virtual machines [root@localhost ~] # virtual machine-- all / / View all virtual machines Virtual machine list [root@localhost~] # virsh shutdown virtual machine name / / normally shut down virtual machine [root@localhost~] # virsh destroy virtual machine name / / force shutdown of virtual machine (similar to unplugging) [root@localhost~] # virsh dumpxml virtual machine name > / root/test01-dum.xml / / virtual machine backup [root@localhost~] # virsh Undefine virtual machine name / / Delete virtual machine (note: after undefining Disk files need to be manually deleted) [root@localhost ~] # virsh define backed up .xml virtual machine file / / generate virtual machine [root@localhost ~] # virsh edit virtual machine name / / edit the configuration file of the virtual machine [root@localhost ~] # the name of the virsh domrename to be changed # for example: ( [root@localhost~] # virsh domrename test01 test03) change the name of the virtual machine [root@localhost qemu] # virsh dominfo test02 / / View the details of the virtual machine [root@localhost~] # virsh autostart test02 / / set the virtual machine to boot [root@localhost~] # virsh autostart-- disable test02 / / cancel boot since Start [root@localhost~] # virsh vncdisplay test02 / / to view the corresponding VNC connection port number The default first port number is: 5900 (denoted by ": 0") [root@localhost ~] # virsh suspend test02 / / suspend virtual machine [root@localhost ~] # virsh resume test02 / / cancel suspending virtual machine [root@localhost ~] # virsh console test02 / / console to log in to the virtual machine [root@localhost ~] # qemu-img info / kvm/disk/test01.raw / / View disk information of a virtual machine [root@localhost disk] # qemu-img create test.raw 2G / / create a disk used by a virtual machine [root@localhost disk] # qemu-img create-f qcow2 123.qcow2 2G / / create a virtual machine disk in qcow2 format [root@localhost disk] # qemu-img convert-f raw-O qcow2 test.raw Test.qcow2 / / convert test.raw disk format raw to qcow2 [root@localhost qemu] # virsh snapshot-create test02 / / create a virtual machine snapshot [root@localhost disk] # virsh snapshot-list test02 / / View a virtual machine snapshot [root@localhost disk] # virsh snapshot-revert test02 1570692304 / / restore a snapshot [root@localhost disk] # virsh snapshot-delete test02 1570692304 / / restore a snapshot [root@localhost disk] # virt-clone-- auto-clone-o test01-n specifies the name to be cloned (optional) / automatic cloning virtual machine [root@localhost disk] # virt-clone-o test01-n test04-f / kvm/disk/test04.qcow2 / / Manual cloning # all of the above are full clones. [root@localhost 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
-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: 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.