Installation configuration and basic use of KVM Virtual Machine Based on Linux Command Line

Source: Internet
Author: User
Tags svm

Installation configuration and basic use of KVM Virtual Machine Based on Linux Command Line
Background

Because the production environment server does not install the desktop environment, simple graphical installation is not suitable for batch deployment and installation. Therefore, I prefer to install and configure the KVM Virtual Machine under the command. Based on some materials and personal usage, I listed some basic and common usage methods.

Install configurationsI. Environment Introduction

Operating System: centos6.6

Kernel version: 2.6

IP Address: 172.16.57.24

Ii. Check CPU

Unlike Xen, KVM requires CPU support (Intel VT or amd svm). Check whether the CPU supports Virtual Technology before installing KVM.

egrep 'vmx|svm' /proc/cpuinfo
3. Install KVM

1. install some virtualization Components

yum -y install kvm python-virtinst libvirt  bridge-utils virt-manager qemu-kvm-tools  virt-viewer  virt-v2v libguestfs-tools-c

2. Configure kvm as follows:

Vim/etc/libvirt/lib1_d. conf Add the following content at the end of tcp connection settings:
listen_tls = 0listen_tcp = 1tcp_port = "16509"listen_addr = "172.16.57.24"unix_sock_ro_perms = "0777"unix_sock_rw_perms = "0770"auth_tcp = "none"max_clients = 1024min_workers = 100max_workers = 200max_requests = 20max_client_requests = 50
Vim qemu. conf is mainly used to set vnc. Later, you can use the vnc-viewer connection to add
Vnc_listen = 0.0.0.0vnc _ password = "bigdata" # vnc connection password remote_display_port_min = 5900 # vnc minimum port remote_display_port_max = 65535 # vnc maximum Port

3. Check whether kvm is successfully installed:

/etc/init.d/libvirtd restart

4. Check whether the instance is started:

ps -ef | grep libvirtd

5. Check whether the kvm module is properly loaded:

lsmod |grep kvm
4. configure a Bridge Connection

1. Configure the bridge br0

vim /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0TYPE=BridgeONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=staticIPADDR=172.16.57.24NETMASK=255.255.255.0GATEWAY=172.16.57.1DNS1=202.96.209.133
vim /etc/sysconfig/network-scripts/ifcfg-em1
DEVICE=em1TYPE=EthernetONBOOT=yesBRIDGE=br0NM_CONTROLLED=yes

2. Restart the network

/etc/init.d/network restart

3. View Network Connections

Brctl show: If the configuration is successful, the following output is displayed: bridge namebridge idSTP transport-nic

4. Check whether ip Forwarding is enabled.

Cat/etc/sysctl. conf | grep ip_forwardnet.ipv4.ip_forward = 1 if it is not enabled: vim/etc/sysctl. conf modify net. ipv4.ip _ forward = 1/sbin/sysctl-p
5. Install virtual machines
virt-install  --name=tomcat_01 --ram 8192 --vcpus=2 /--disk path=/var/lib/libvirt/images/tomcat_01.img,size=20,format=raw,bus=virtio /--cdrom /var/iso/CentOS-6.7-x86_64-minimal.iso --network bridge=br0,model=virtio /--vnc --accelerate --force  --autostart

Here we will explain the meanings of the main parameters:

-- Name indicates the Virtual Machine name -- Memory allocated to the Virtual Machine by ram, in MB -- number of CPUs allocated to the Virtual Machine by vcpus -- cdrom specifies the full path of the installation file -- disk specifies the imgfile path of the virtual machine, if the virtual machine uses the lvm partition, the size of the Virtual Machine file will be directed to the lvm partition here. The unit is the bus type used by the GB bus Virtual Machine disk. In order to make the Virtual Machine achieve good performance, here we use the cache type of the virtio cache Virtual Machine disk -- network bridge to specify the bridge Nic model Nic mode. Here we also use virtio -- graphics parameters with better performance.

Here, the name of the virtual machine I installed is tomcat_01. Next, check its vnc Port:

ps aux | grep qemu | grep tomcat_01

At that time, we set the minimum vnc port to 5900, Which is 5902.

Next, use vnc-viewer in windows to connect to 172.16.57.24: 5902, and enter the set password to install it.

Common Operations

1. Host Machine Management VM

To switch and manage a virtual machine, you need to install acpid service on the Virtual Machine and start it.

2. clone a VM

Generally, a common Virtual Machine template is created. you can clone the template directly next time you install the template.

Virt-clone -- connect qemu: /// system -- original = tomcat_01 -- name = tomcat_02 -- file = // var/lib/libvirt/images/tomcat_02.img -- virtual machine object cloned by original -- name new Virtual Machine name cloned by name

3. Add a disk

Generally, the disk structure of a virtual machine adds a data disk to the system disk. When the system fails, you can create a new system disk without losing the data disk.

Add disk operation:

Cd/var/lib/libvirt/images/enter the disk storage directory qemu-img create-f raw test_add.img 100G to create a G disk virsh attach-disk tomcat_01/var/lib/libvirt /images/test_add.img vdb -- cache none Dynamic Disk Addition

This method dynamically adds disks, but the xml configuration file does not change. To prevent the disk to be added from being invalid at the next startup, perform the following operations:

Virsh dumpxml tomcat_01> tomcat_01.xml redirects the latest virtual machine configuration to its configuration file virsh define tomcat_01.xml

In this way, the new disk will not be lost.

4. operations on the virsh command

Autostart automatically starts a domain Create to Create a domain Define from an XML file and defines it from an XML file (but does not start) edit a domain to edit the XML configuration of a domain shutdown to close the start of a domain (previously defined) inactive domain reboot restart a domain suspend a domain resume a domain vncdisplay vnc display

From: http://www.linuxeye.com/Linux/2897.html

Address: http://www.linuxprobe.com/linux-command-kvm.html


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.