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 > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of CentOS7.2 how to deploy the KVM virtual machine, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to deploy the KVM virtual machine in CentOS7.2. Let's take a look at it.
Centos version: 64-bit 7.2 1511
First, install kvm
1. Verify that cpu supports kvm;. If the result contains the words vmx (intel) or svm (amd), it means that cpu supports it.
Egrep'(vmx | svm)'/ proc/cpuinfo
two。 Close selinux and change the selinux=enforcing in / etc/sysconfig/selinux to selinux=disabled
3. Minimum installation of centos installs some of the most basic packages (optional, because I just installed centos, so for the convenience of the following, install some necessary tools first)
Yum install epel-release net-tools vim unzip zip wget ftp-y
4. Install kvm and its dependencies
Yum install qemu-kvm libvirt virt-install bridge-utils-y
5. Verify the installation result. The following figure shows that the installation has been successfully completed.
Lsmod | grep kvm
6. Turn on the kvm service and set it to boot automatically
Systemctl start libvirtdsystemctl enable libvirtd
7. Check the status operation result, as shown in the following figure, which shows that the operation is in good condition.
Systemctl status libvirtdsystemctl is-enabled libvirtd
8. To configure the bridge mode, first back up a copy of the Nic configuration file under the / etc/sysconfig/network-scripts/ directory (do not keep it in the current directory and subdirectories, other directories are optional)
a. Create an ifcfg-br0 file as follows:
Bootproto=staticdevice=br0type=bridgenm_controlled=noipaddr=192.168.1.95netmask=255.255.255.0gateway=192.168.1.1dns1=61.177.7.1dns2=8.8.8.8
b. Remove the original ifcfg-enp0s25 and recreate the file as follows:
Bootproto=nonedevice=enp0s25nm_controlled=noonboot=yesbridge=br0
c. Restart network services
Systemctl restart network
Use ifconfig to verify the operation result, with an additional network card br0, now you can access think8848-srv02 using 192.168.1.95.
Second, install the virtual machine
1. Prepare the operating system installation image file. In this article, you will use the same centos7.2 as the host environment, and put the file in the / home/iso directory.
two。 Create a directory where virtual machine files are stored
Mkdir-p / home/kvm-bak
3. Create a virtual machine using virt-install
The copy code is as follows:
Virt-install-n think8848-kvmbase-r 2048-disk / home/kvm-bak/think8848-kvmbase.img,format=qcow2,size=20-network bridge=br0-os-type=linux-os-variant=rhel7.2-cdrom / home/iso/centos-7-x86_64-dvd-1511.iso-vnc-vncport=5910-vnclisten=0.0.0.0
The result of the operation shows:
Ignore the mistakes prompted in it and move on.
4. Open port 5910 on the firewall
Firewall-cmd-zone=public-add-port=5910/tcp-permanentfirewall-cmd-reload
5. Use vnc to connect to the virtual machine, install the virtual machine operating system, and download the latest version of vnc viewer directly to the vnc official website.
A. Vnc viewer
b. Create a new connection, providing the host ip, port number (specified during virt-install creation), and name
c. In the expert tab, change the value of colorlevel from the original pal8 to rgb222, and click the ok button to save
d. If, like me, you are still taking notes while operating, after you double-click the name of the connection, the installation interface is ready.
The next step is to install centos, with a slight process.
6. After installing centos, the system is required to restart. At this time, the virtual machine is not restarted (and I don't know what the problem is), and the vnc is not connected. First check the status of the virtual machine on the host machine and show that think8848-kvmbase is turned off.
Virsh list-all
7. Start the virtual machine manually
Virsh start think8848-kvmbase
Using the vnc connection again, I found that it was ready to connect.
3. Simply configure the kvm virtual machine
1. Bridge configuration, it is worth mentioning here that if you configure the appropriate grid parameters during the installation of centos in the virtual machine, then the network should be available in the virtual machine. If the default parameters of the system installation package are adopted at that time, and the network card is not enabled, then you need to start the network card of the virtual machine. First, take a look at the list of configuration files of the virtual machine network card, which seems to be no different from that of ordinary computers. The configuration file of the network card is ifcfg-eth0.
Then look at the ifcfg-eth0 configuration file, and ordinary computer installation is no different, according to the requirements, seems to be introduced in some articles, said that the need to add a line of configuration nm_controlled=no, I did not add and did not find any problem.
two。 Configure to log in to the virtual machine shell on the host side. Of course, it is also possible to log in through ssh on the host side, but logging in directly seems to be a good way. There are two main steps in this configuration:
a. Edit the / etc/default/grub file as follows:
Before editing:
After editing:
Text content:
Grub_distributor= "$(sed's, release. * $, g' / etc/system-release)" grub_default=savedgrub_disable_submenu=truegrub_terminal= "console serial" grub_serial_command= "serial-speed=115200-unit=0-word=8-parity=no-stop=1" grub_cmdline_linux= "rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb" grub_cmdline_linux_default= "console=tty1 console=ttys0,115200" grub_disable_recovery= "true"
b. Run the following line of code
Grub2-mkconfig-o / boot/grub2/grub.cfg
c. Restart virtual machine reboot
d. Enter the virtual machine console on the host and use the ctrl key +] (left bracket) to exit if you want to exit.
Virsh console think8848-kvmbase
Fourth, migrate virtual machines
After the virtual machine is built, the biggest advantage is that we are left to struggle without having to worry about the trouble of reinstalling the system. So be sure to know how the virtual machine replicates and migrates. There are two situations, one is local mirror replication, the other is migrating the local image to another server.
1. Native replication
a. Shut down the virtual machine first
Virsh shutdown think8848-kvmbase
b. Create a new folder / home/kvm-img under / home
Mkdir-p / home/kvm-img
c. Use virt-clone to clone think8848-kvmbase as a new virtual machine
The copy code is as follows:
Virt-clone-o think8848-kvmbase-n think8848-kvm01-f / home/kvm-img/think8848-kvm01.img
Cloning completed
Use virsh list-- all to view
d. Open think8848-kvm01, and then modify the ip address and hostname
After virsh start think8848-kvm01virsh console think8848-kvm01# and other virtual machines are started, log in to hostname think8848-kvm01# to edit / etc/hostname file with root, modify the hostname to think8848-kvm01vi / etc/hostname# edit / etc/sysconfig/network-scripts/ifcfg-eth0, and modify ipaddr
E. reboot restarts the virtual machine, and the modified content has already taken effect after the restart.
two。 Migrate the virtual machine image to another server
a. First put the configuration files and image files of the virtual machine in the appropriate location (I built a ftp server to facilitate all file transfers during testing, as shown in the following figure)
b. Now turn to the server to think8848-srv01 (ip:192.168.1.96), where the virtual machine was created on think8848-srv02 (ip:192.168.1.95). All of the following operations are done on think8848-srv01
c. Put the think8848-kvm01.img on ftp into the / home/kvm-img directory and the think8848-kvm01.xml into the / etc/libvirt/qemu directory
d. Edit think8848-kvm02.xml, replace all think8848-kvm01 in it with think8848-kvm02, and then replace uuid with new one (generate it directly using this online tool)
e. Define a new virtual machine
Virsh define / etc/libvirt/qemu/think8848-kvm02.xml
In the figure, think8848-kvm01 is the virtual machine I configured in the host, and the name happens to be the same as the previous one. I did not install the ftp client on think8848-kvm01. I installed ftp in the newly migrated virtual machine. I can use this package to verify that the virtual machine is correct.
Ok, there is no problem.
f. It is time to assign a new hostname and ip to the new virtual machine. It was our reboot that took effect just now. Let's not restart it this time. First, use systemctl restart network to make the new ip take effect, and then exit log out the user to make the hostname take effect.
Last but not least, if you want to use vnc connections after cloning or migration, you need to re-specify the port number of vnc and change the vnc port number in / etc/libvirt/qemu/think8848-kvm02.xml to the value you need.
This is the end of the article on "how CentOS7.2 deploys the KVM virtual machine". Thank you for reading! I believe you all have a certain understanding of "how to deploy KVM virtual machines in CentOS7.2". If you want to learn more, you are welcome to follow the industry information channel.
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.