Install and use CentOS 7 or RHEL 7 as KVM virtualization host


When thinking about virtualization,everybody immediately thinks about VMWare. And it must be said,the product they offer is very decent but also comes with a “decent” price. As an alternative,it’s worth looking into KVM for your virtualization. As with the VMWare product range,KVM offers full virtualization and it can compete with VMWare regarding stability and performance.

Virtualization-terminology

To prevent things getting confused I would first like to clear out some terminology used for virtualization. For somebody working on a daily basis in virtual environments,these might be clear but can be rather confusing for others.

Host: the machine that hosts other system,KVM will be installed on this machine
Guest: the system running on the host,also referred to as VM,Virtual Machine or domain.
Hypervisor: the piece of software that enables virtualization on the host. For example: KVM,ESXi,Xen,…

Part1: KVM installation and preparation

KVM hypervisor and VM-extensions

As mentioned earlier,KVM offers,as VMWare,full virtualization. This means that a full system,which looks like a real physical system to the guest-OS,will be offered. Besides full virtualization,there is also such a thing as paravirtualization,as Xen can offer. Paravirtualization givesyou higher performance but needs a modified guest-OS and is basically limited to *nix-systems. Full virtualization enables you to run unmodified guest-systems and thus also most proprietary systems as Windows. In order to be able to use full virtualization,you either need some virtualization-extensions on your CPU or use emulation.

First thing to do is to check if the host-machinesupports VM-extensions. On the x86 platofrom,those are either AMD-V or Intel’s VT-X. In order to check if the installed CPU’s support those extensions,we need to check if the vmx (for VT-X) or svm (for AMD-V) flag exists in the cpuinfo-output:

When the output is 0,meaning that neither vmx or svm is found in the flags,it probably means that yourCPU doesn’t support those extensions and there is little you can do. When the extensions are listed,be sure to check if they are enabled in the systems BIOS since that would cause problems later on. In case your CPU doesn’t support VM-extensions,you are limited to QEMU-emulation in combination with KVM,which delivers a much worse performance in comparison. For this tutorial,I’ll assume that the VM-extensions are supported and enabled in the BIOS of the host-system.

KVM installation

The first step in the KVM installation is installing the necessary packages. Package virt-manager,xauth and dejavu-lgc-sans-fonts are also needed if you want to manage KVM with the graphical interface in combination withX11 forwarding. (for more information,checkthis previous post about X11 forwarding)

To install the required packages

Networking

For the networking part,our KVM-host will act as a router for its guests and wewill need to create a bridge interface to allow the guest to communicate out of the host. Guests will use NAT on the host to connect to the real network. To allow such type of setup it’s neededto allow ip forwarding in the kernel parameters.

After allowing the host to do ip forwarding,we need to change the network configuration. Basically we will keep our original physical interface as it is but will assign its IP-address to the brige. In the example host-machinethere is one real interface called eno16777736 and the script in/etc/sysconfig/network-scripts/ifcfg-eno16777736 looks like this:

The first thing to change here,is to comment out everything that is IP-related and tell the interface which interface will be the bridge. Resulting in /etc/sysconfig/network-scripts/ifcfg-eno16777736 to look like this:

8
DEVICE "eno16777736"
ONBOOT =yes
#IPADDR "192.168.202.111"
#NETMASK "255.255.255.0"
#GATEWAY "192.168.202.2"
HWADDR "00:0c:29:32:d0:4c"
#DNS1 "192.168.202.2"
BRIDGE =virbr0

Next,we can create the config-script for the bridge interface virbr0 in/etc/sysconfig/network-scripts/ifcfg-virbr0. Most details can be copied from the original script foreno16777736:

DEVICE "virbr0"
TYPE =BRIDGE
ONBOOT =yes
BOOTPROTO =static
IPADDR "192.168.202.111"
NETMASK "255.255.255.0"
GATEWAY "192.168.202.2"
DNS1 Finish and check the KVM installation

Basically all components are now ok but before KVM can be used it’s a good idea to perform a reboot in order to load the kvm-modules and to relaod the new network settings.

After the reboot,we should check if the necessary kernel modules are loaded,which means that KVM successfully can handle the VM-extensions of our CPU:

Check if the bridge is installed and in an up-state:

Last thing to check is if we can connect to KVM by asking for a simple list of systems:

If it returns something else,then you should go trough the earlier steps to check where something went wrong.

Part 2: Using KVM with the CLI

After completing the KVM installation,it’s time to start using the host. First thing we need to do is to create a new domain or VM.

Adding a new VM

To create a new virtual machine using the CLI,we need to know which template we will use to install the system. To get a list of templates that are known in our KVM installation,you can do the following:

Virtual disk images for the KVM-guests can be placed in /var/lib/libvirt by default. In case you prefer to use another location to store the disk images,SELinux will,by default,prevent access and the security context of that location needs to be changed in order to use it for KVM. To change the SELinux context when storing the images in another location (/vm for example):

Now,to add a new VM,we can use virt-install.

Example to add a windows-guest:

Explanation of the arguments that were given to virt-install:

After launching the above command,you should be able to connect with VNC to the host and get on the console-display of the VM. The console displays what would normally,on a physical machine,appear on the attached monitor.

By default,VNC will use the first availablescreen on port 5900. To be sure which screen is used,we can use virsh to show the attached console-screens for VNC:

:0 means the first screen and real port 5900 as you can also see when checking with netstat which ports are currently listening:

From this point,we can complete the windows installation as if it would be a normal physical system:

After completing the installation with VNC,we end up with a Windows-VM that is running on our KVM-host:

As for the networking part,we use the earlier created bridge (virbr0) to do NAT. This means that the KVM-host NAT’s all our connections to the real network connected to the KVM-host. If DHCP is active on that network,it can be used in the VM. Otherwise you will have to configure a static IP in the same subnet.

Example to add a Linux-guest:

To add a Linux guest,next to the already added Windows-guest is quite similar:

As with the Windows-VM,after launching this command,you should be able to connect with VNC to the host and get on the console of the VM to complete theDebian installation.

To know which VNC-display number (and port) is used for a certain VM,the same command as used earlier should do:

Above command gives :1 as result,meaning that the guest vmdeb7 can be contacted with VNC on port 5901:

After finishing the installation,weend up with a Linux guest running on top of our KVM-host. Which Linux distro we are using doesn’t matter since we’re doing full virtualization.

Considering network,the same as with the Windows VM applies here. Our connections are NATted trough the KVM-host and we can use the DHCP-server of our real network.

More KVM actions

Besides creating VM’s,it’s a good thing to know some basic operations regarding VM-managent.

List the active virtual machines:

Get more information about a guest:

Stop a running guest:

To stop a running VM in a clean way (as you would press the power button to start the shutdown sequence):

This triggers a normal,clean,shutdown on the guest:

To force stop a running VM that doesn’t want to shutdown in a clean way:

Start aguest:

Delete aguest:

First we need to make sure that the guest is stopped before it can be deleted. In case you don’t want the virtual disk image anymore either,you’ll have to delete it manually after undefining the guest.

After removing a disk-image,it’s a good thing to refresh the storage pool of KVM:

Automatically let a guest start when the host starts

When rebooting your host,you probably want some or all the guests that are defined on thathost to start at the same time. By default,the guest are not automatically started.

Part 3: Using KVM with the virt-manager GUI

Starting the GUI

Managing KVM with the CLI is not so difficult and it can be very handy to script certain day-to-day tasks. Sometimes,you just need to keep an overview and require a little more user-friendliness. For that,you can use virt-manager,which is a graphical interface for libvirt and is mainly built for KVM. When you want to manage your guest with virt-manager,you can either do it on the host itself,by starting an X-server locally or use X11 forwarding on a headless server (more informationhere).

Make sure that you have enough permissions to use virt-manager and simply execute virt-manager from the command line:

If all goes well,you should be presented with the virt-manager GUI:

Basic actions

From the initial start-up screen,you can immediately see a list of configured guests on this host and take actions on them like: Run,Pause,Shutdown,Reboot,Force off,…

When selecting a guest,you can also click on Open to display the console as we did earlier using VNC:

Advanced actions

Other possibilities using the virt-manager interface:

Connect to another host-system to manage the VM’s running there,using File -> Add connection (like using the –connect on the CLI)

Migrate a VM to another KVM-host: right click on the VM and choose Migrate…

Clone a VM to the same or another KVM-host: right click on the VM and choose Clone…

As you can see,the virt-manager interface is not very complicated and most of the basic tasks don’t need any explanation.

After completing all of the above steps,basic installation and using KVM shouldn’t have any secrets anymore for you. The next thing to do is experiment and test a little more with KVM and hopefully start to use it in your production environment.

url---http://jensd.be/207/linux/install-and-use-centos-7-as-kvm-virtualization-host

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


linux下开机自启: 在/etc/init.d目录下新建文件elasticsearch 并敲入shell脚本: 注意, 前两行必须填写,且要注释掉。 第一行为shell前行代码,目的告诉系统使用shell。 第二行分别代表运行级别、启动优先权、关闭优先权,且后面添加开机服务会用到。 shell脚本
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权 chmod +x /etc/rc.d/rc.local 2、赋予脚本可执行权限假设/usr/local/script/autostart.sh是你的脚本路径,给予执行权限 chmod +x /usr
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用ls -ll,会显示成字节大小,而ls- lh会以KB、MB等为单位进行显示,这样比较直观一些。 通过命令du -h –max-depth=1 *,可以查看当前目录下各文件、文件夹的大小,这个比较实用。 查询当前目录总大小可以使用d
ASP.NET Core应用程序发布linux在shell中运行是正常的。可一但shell关闭网站也就关闭了,所以要配置守护进程, 用的是Supervisor,本文主要记录配置的过程和过程遇到的问题 安装Supervisor 1 yum install python-setuptools
设置时区(CentOS 7) 先执行命令timedatectl status|grep 'Time zone'查看当前时区,如果不是时区(Asia/Shanghai),则需要先设置为中国时区,否则时区不同会存在时差。 #已经是Asia/Shanghai,则无需设置 [root@xia
vim /etc/sysconfig/network-scripts/ifcfg-eth0 BOOTPROTO="static" ONBOOT=yes IPADDR=192.168.8.106 NETMASK=255.255.252.0 GATEWAY=192.168.
一、安装gcc依赖 由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装 [root@localhost local]# yum install -y gcc 二、下载并解压安装包 [root@localhost local
第一步 On CentOS/RHEL 6.*: $ sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm On CentOS/RHEL 7: $
/// <summary> /// 取小写文件名后缀 /// </summary> /// <param name="name">文件名</param> /// <returns>返回小写后缀,不带“.”</ret
which nohup .bash_profile中并source加载 如果没有就安装吧 yum provides */nohup nohup npm run start & nohup ./kibana &
1.1 MySQL安装 1.1.1 下载wget命令 yum -y install wget 1.1.2 在线下载mysql安装包 wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 1.1.3 安装My
重启 reboot shutdown -r now init 6 关闭 init 0 shutdown -h now shutdown -h 20:25 #8点25关机查看内存 free CPU利用率 top 日期 date 设置时间 date 033017002015 #月日时间年 日历 cal
1、firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status firewalld 开机禁用 : systemctl disable firewalld 开机启用 :
1 下载并安装MySQL官方的 Yum Repository wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 使用上面的命令就直接下载了安装用的Yum Repository,大概
CentOS6.x CentOS6中转用Upstrat代替以前的init.d/rcX.d的线性启动方式。 一、相关命令 通过initctl help可以查看相关命令 [root@localhost ~]# initctl help Job commands: start Start job. sto
1、使用命令:df -lk 找到已满磁盘 2、使用命令:du --max-depth=1 -h 查找大文件,删除
ifconfig:查看网卡信息 网卡配置文件位置: /etc/sysconfig/network-scripts/文件夹 nmtui:配置网卡 netstat -tlunp:查看端口信息 端口信息存储位置: /etc/services文件 route:查看路由信息 wget:下载网路文件,例如 wg
ps -ef:查看所有进程, ps -ef |grap firewalld 查看与firewalld相关的进程 which :查看进程:which firewalld kill 进程id:杀掉进程 kill 640,强制杀:kill -9 640 man:查看帮助,例如 man ps 查看
useradd:添加用户 useradd abc,默认添加一个abc组 vipw:查看系统中用户 groupadd:添加组groupadd ccna vigr:查看系统中的组 gpasswd:将用户abc添加到ccna组 gpasswd -a abc ccna groups abc:查看用户abc属