2017年3月5日 星期日

[Linux 文章收集] Install KVM Hypervisor on CentOS 7.x and RHEL 7.x

Source From Here 
Introduction 
KVM is an open source hardware virtualization software through which we can create and run multiple Linux based and windows based virtual machines simultaneously. KVM is known as Kernel based Virtual Machine because when we install KVM package then KVM module is loaded into the current kernel and turns our Linux machine into a hypervisor. 

In this post first we will demonstrate how we can install KVM hypervisor on CentOS 7.x and RHEL 7.x and then we will try to install virtual machines. Before proceeding KVM installation, let’s check whether your system’s CPU supports Hardware Virtualization. Run the beneath command from the console. 
# grep -E '(vmx|svm)' /proc/cpuinfo

We should get the word either vmx or svm in the output, otherwise CPU doesn’t support virtualization. 

Step:1 Install KVM and its associate packages 
Run the following yum command to install KVM and its associated packages. 
# yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils

Start and enable the libvirtd service: 
# systemctl start libvirtd
# systemctl enable libvirtd

Run the beneath command to check whether KVM module is loaded or not: 
# lsmod | grep kvm
kvm_intel 162153 0
kvm 525259 1 kvm_intel

In Case you have Minimal CentOS 7 and RHEL 7 installation , then virt-manger will not start for that you need to install x-window package. 
# yum install "@X Window System" xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils -y

Reboot the Server and then try to start virt manager. 

Step:2 Start the Virt Manager 
Virt Manager is a graphical tool through which we can install and manage virtual machines. To start the virt manager type the ‘virt-manager‘ command from the terminal. 
# virt-manager

Step:3 Configure Bridge Interface 
Before Start creating VMs , let’s first create the bridge interface. Bridge interface is required if you want to access virtual machines from outside of your hypervisor network. 
# cd /etc/sysconfig/network-scripts/
# vi ifcfg-eno49
  1. TYPE=Ethernet  
  2. BOOTPROTO=static  
  3. DEVICE=eno49  
  4. ONBOOT=yes  
  5. BRIDGE=br0  
# vi ifcfg-br0
  1. TYPE=Bridge  
  2. BOOTPROTO=static  
  3. DEVICE=br0  
  4. ONBOOT=yes  
  5. IPADDR=192.168.10.21  
  6. NETMASK=255.255.255.0  
  7. GATEWAY=192.168.10.1  
  8. DNS1=192.168.10.11  

Replace the IP address and DNS server details as per your setup. Restart the network Service to enable the bridge interface. 
# systemctl restart network

Check the Bridge interface using below command : 
# ip addr show br0

Step:4 Start Creating Virtual Machines. 
Now Create Virtual Machine either from the command line using ‘virt-install‘ command or from GUI (virt-manager). Let’s Create a virtual machine of “Windows Server 2012 R2” using virt-manager
1. Start the “virt-manager” and go to the File Option, click on “New Virtual Machine” 

2. We will be using ISO file as installation media. In the next step Specify the path of ISO file. 
Click on Forward. 

3. Specify the Compute Resources : RAM and CPU as per your setup. 
 Click on Forward to proceed further. 

4. Specify the storage Size of Virtual Machine, In my case I am using 25G. 

5. In the Next step Specify the Name of Virtual Machine and select network as ‘ Bridge bro’ 

Click on Finish to start the installation. 

Creating a virtual Machine from Command Line: 
Virtual Machines can be created from the console as well using ‘virt-install’ command. In the following example i going to virtual machine of Ubuntu 16.04 LTS. 
# virt-install --name=Ubuntu-16-04 --file=/var/lib/libvirt/images/ubuntu16-04.dsk --file-size=20 --nonsparse --graphics spice --vcpus=2 --ram=2048 --cdrom=ubuntu-16.04-server-amd64.iso --network bridge=br0 --os-type=linux --os-variant=generic
Starting install...
Allocating 'ubuntu16-04.dsk'
...

Follow the instruction now and complete the installation. In the above ‘virt-install’ command we have used following options : 
–name = 
–file = 
–file-size = < Size of the Virtual Machine, in my case it is 20GB >
–nonsparse = < Allocate the whole storage while creating>
–graphics = < Specify the graphical tool for interactive installation, in above example I am using spice >
–vcpu = < Number of virtual CPU for the Machine >
–ram = < RAM size for the virtual Machine >
–cdrom = < Virtual CD ROM which specify the installation media like ISO file >
–network = < it is used to specify which network we will use for the virtual machine, in this example I am bridge interface>
–os-type = < Operating system type like linux and window>
–os-variant= 

Once the Installation is completed we can access the Virtual Machine console from ‘virt-manager‘ as shown below. 

That’s it, basic installation and configuration of KVM hypervisor is completed.

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...