Installation configuration and basic use of KVM virtual machine based on Linux command line

http://www.cnblogs.com/linuxprobe/p/5724546.htmlBackground Since

the server in the production environment does not have a desktop environment installed, the simple graphical installation is not suitable for batch deployment and installation.
Therefore, I still prefer to install and configure the KVM virtual machine under the command. Combined with some information and personal use, I have roughly listed some basic and common usage methods.
Installation and configuration
1. Environment introduction
Operating system: centos6.6 Kernel version: 2.6 IP address: 172.16.57.24
2. Check that the CPU
is different from Xen, KVM needs to have CPU support (Intel VT or AMD SVM), check before installing KVM Whether the CPU supports virtualization technology
egrep 'vmx|svm' /proc/cpuinfo
3. Install KVM
1. Install some virtualization components here
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/libvirtd.conf Here is mainly the setting of tcp connection Add the following at the
end :
listen_tls = 0
listen_tcp = 1 tcp_port
= " 16509"
listen_addr = "172.16.57.24"
unix_sock_ro_perms = "0777"
unix_sock_rw_perms = "0770"
auth_tcp = "none" max_clients
= 1024
min_workers = 100
max_workers = 200
max_requests = 20 max_client_requests =
50
Install through vnc-viewer
connection Add
vnc_listen = 0.0.0.0 at the end
vnc_password = "bigdata" #vnc connection password
remote_display_port_min = 5900 #vnc minimum port
remote_display_port_max = 65535 #vnc maximum port
3, confirm whether kvm is installed successfully:
/etc/ init. d/libvirtd restart
4. Check whether it is started:
ps -ef | grep libvirtd
5. Check whether the kvm module is loaded normally:
lsmod | grep kvm
4. Configure the bridge connection
1. Configure the bridge br0
vim /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED= yes BOOTPROTO
=static
IPADDR=172.16.57.24
NETMASK=255.255.255.0
GATEWAY=172.16.57.1
​​DNS1=202.96.209.133
vim / etc/sysconfig/network-scripts/ifcfg-em1
DEVICE=em1
TYPE=Ethernet
ONBOOT=yes
BRIDGE=br0
NM_CONTROLLED=yes
2. Restart the network
/etc/init.d/network restart
3. Check the network connection
brctl show
If the configuration is successful, There will be the following output:
bridge name bridge id STP enabled interfaces
br0 8000.14187745822e no em1
vnet0
vnet1
vnet2
vnet3
vnet4
vnet5
vnet6
virbr0 8000.5254005fcc0b yes virbr0-nic
4. Check if ip forwarding is enabled
cat /etc/sysctl.conf |grep ip_forward
net.ipv4.ip_forward = 1
If not:
vim /etc/sysctl.conf
modify net.ipv4. ip_forward = 1
/sbin/sysctl -p
Fifth, install the virtual machine
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 to explain the meaning of the main parameters:
--name give the virtual machine a name
--ram the memory allocated to the virtual machine, in MB
--vcpus the number of CPUs allocated to the virtual machine
--cdrom specifies the full path of the installation file
--disk specifies the virtual machine img file path. If the virtual machine uses the lvm partition, just point to the lvm partition.
  size The virtual machine file size, in GB
  bus The bus type used by the virtual machine disk , in order to make the virtual machine achieve good performance, here use
  the cache type of the virtio cache virtual machine disk
--network bridge to specify the bridge network card
   model network card mode, here is also the use of better performance virtio
--graphics graphics parameters
Here I installed the virtual machine The name is tomcat_01, and then check its vnc port:
ps aux | grep qemu | grep tomcat_01
At that time, we set the minimum vnc port to 5900, so it refers to the port 5902. Next, use vnc-viewer under Windows to connect to 172.16.57.24:5902 and enter the set password to install.
Common operations
1. The host manages the virtual machine. To manage the virtual machine, such as switching, it is necessary to install the acpid service on the virtual machine and start it. 2. Cloning a virtual machine Generally, a common virtual machine template is created, and this template can be cloned directly in the next installation.
virt-clone --connect qemu:///system --original=tomcat_01 --name=tomcat_02 --file=//var/lib/libvirt/images/tomcat_02.img
--original cloned virtual machine object
--name The name of the cloned new virtual machine
3. Adding a disk Generally, the disk structure of a virtual machine is a system disk plus a data disk. When the system fails, a system disk can be rebuilt, and the data disk will not be lost. Add disk operation:
cd /var/lib/libvirt/images/ Enter the disk storage directory
qemu-img create -f raw test_add.img 100G Create a 100G disk
virsh attach-disk tomcat_01 /var/lib/libvirt/images/test_add. img vdb --cache none Dynamically add disks
This method is to dynamically add disks, and the xml configuration file has not changed. In order to prevent the added disks from failing next startup, do the following:
virsh dumpxml tomcat_01 > tomcat_01.xml Put the latest The virtual machine configuration is redirected to its configuration file
virsh define tomcat_01.xml
so that the newly added disk will not be lost. 4. Some operations of the virsh command
Autostart Automatically start a domain
Create Create a domain
from an XML file Define Define (but not start) a domain from an XML file
edit Edit the XML of a domain Configure
shutdown Close a domain
start Start a (previously defined) inactive domain
reboot restarts a domain
suspend suspends a domain
resume resumes a domain
vncdisplay vnc display

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326407515&siteId=291194637