[Reserved] Linux command line-based installation and KVM virtual machines with the basic use

background

Due to the production environment servers will not install a desktop environment, graphical installation simple operation is not suitable for mass deployment installation. So, I still prefer to install the KVM virtual machine configured in the command. Combines a number of status information and personal use, I generally listed some basic and common use.

Installation configuration

First, the environment Introduction

Operating System: centos6.6 kernel version: 2.6 IP Address: 172.16.57.24

Second, check the CPU

And different Xen, KVM needs the support of the CPU (Intel VT or AMD SVM), check whether the CPU before installing KVM provides support for virtual technology

egrep 'vmx|svm' /proc/cpuinfo

Third, install the KVM

  1. Here 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. Kvm follows for the following:
    vim /etc/libvirt/libvirtd.conf
    

    This is mainly added to the end provided tcp connection as follows:

    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
    vim qemu.conf
    

    This is mainly set vnc, the moment to be added by the end of the installation connected vnc-viewer vnc_listen = 0.0.0.0 vnc_password = "bigdata" #vnc连接密码 remote_display_port_min = 5900 #vnc最小端口 remote_display_port_max = 65535 #vnc最大端口 

  3. Kvm confirm whether the installation was successful:
    /etc/init.d/libvirtd restart
    
  4. Check whether to activate:
    ps -ef | grep
    
  5. See if kvm module load properly:
    lsmod |grep kvm
    

Fourth, the bridge connection configuration

  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 Network
    /etc/init.d/network restart
    
  3. View Network Connections
    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 ip forwarding is turned on
    cat /etc/sysctl.conf |grep ip_forward
    net.ipv4.ip_forward = 1
    

    If you do not turn on:

    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 several major parameters: 
-name to the virtual machine a name
assigned -ram to the virtual machine's memory, the unit MB
-vcpus cpu number assigned to the virtual machine
-cdrom specify the full path to the installation files
-disk specified VM img file path, if a virtual machine using the lvm partitions, here point to lvm partition on the line
size VM file size, in GB
bus virtual bus type machine disk usage, in order to make the virtual machine to achieve good performance, where the use virtio
cache virtual machine disk cache type
-network bridge designated bridge card
model card mode, here is the use of better performance virtio
-graphics graphics parameters
here I installed virtual machine named tomcat_01, the next to see its vnc port:

ps aux | grep qemu | grep tomcat_01

At that time we set the minimum vnc port 5900, this refers to the 5902 port. Next, by using the windows vnc-viewer to connect 172.16.57.24:5902, and enter the password set can be installed.

Common Operations

  1. Host virtual machine management to manage virtual machine switches, etc., you need to install the acpid service on a virtual machine, and start it.
  2. Clone virtual machines generally used to make a virtual machine template, can be installed directly next to clone this template.
    virt-clone --connect qemu:///system --original=tomcat_01 --name=tomcat_02 --file=//var/lib/libvirt/images/tomcat_02.img
    --original克隆的虚拟机对象
    --name    克隆的新虚拟机名称
    
  3. Adding disks general virtual machine's disk structure plus data disk system disk when the system fails, you can rebuild a system disk, and the disk data will not be lost. Add disk operations:
    cd /var/lib/libvirt/images/ 进入磁盘存放目录
    qemu-img create -f raw test_add.img 100G 创建一块100G的磁盘
    virsh attach-disk tomcat_01 /var/lib/libvirt/images/test_add.img vdb --cache none 动态添加磁盘
    

    This method is dynamically add disks, but xml configuration file has not changed, in order to prevent the next startup disk failure added, proceed as follows:

    virsh dumpxml tomcat_01 > tomcat_01.xml 将最新的虚拟机配置重定向到其配置文件中
    virsh define tomcat_01.xml
    

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

  4. Some operations virsh command 
    Autostart automatically starts a domain 
    Create an XML file created from a domain 
    Define definitions from an XML file (but do not start) a domain 
    XML edit edit a configuration of the domain 
    shutdown shut down a domain 
    start to start a (previously defined ) inactive domain 
    reboot restart a domain 
    suspend suspend a domain resume to resume a domain 
    vncdisplay vnc display

Guess you like

Origin www.cnblogs.com/xuanbjut/p/10994608.html