One: KVM Installation
Two servers
192.168.115.18192.168.115.19
0. Modify the physical server time zone
Cp/usr/share/zoneinfo/asia/shanghai/etc/localtimeyum Install Ntpdate-yecho "*/5 * * * * * root ntpdate cn.pool. ntp.org ">>/etc/crontab && cat/etc/crontabservice crond stop && service Crond start
1. Modify Host Name
echo "192.168.1.154 kvm-node154.com kvm-node154" >>/etc/hostsecho "192.168.1.155 kvm-node155.com kvm-node15 5 ">>/etc/hostscat/etc/hosts
2. Modify kernel mode (compatible kernel)
Sed-i "s/default=0/default=1/g"/boot/grub/grub.conf && cat/boot/grub/grub.conf
3. Turn off SELinux
Sed-i "s/selinux=enforcing/selinux=disabled/g"/etc/selinux/config && cat/etc/selinux/config
4. Turn off the firewall and NetworkManager
Chkconfig iptables offchkconfig ip6tables offchkconfig NetworkManager off
5. Restart
Yum Update-yreboot
6. When the reboot is complete, check whether virtualization is supported
Cat/proc/cpuinfo | Grep-e "VMX|SVM"--color=always
7. The modules and tools required to install KVM virtualization
Yum Install KVM python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v libguest Fs-tools-y
8. Configure remote connection aliases commonly used by the Libvirt client service
vi/etc/libvirt/libvirt.confuri_aliases = ["Kvm154=qemu+ssh://[email protected]/system", "KVM155=QEMU+SSH: [Email Protected]/system,]
9. Start the LIBVIRTD daemon for client logon testing
Service LIBVIRTD startvirsh-c kvm154virsh-c kvm155
10. Configure the LIBVIRTD server, close the TLS installation connection, open the TCP connection, set the TCP listening port, the TCP connection does not apply the way of authentication authorization, set the socket save location.
cp/etc/libvirt/libvirtd.conf/etc/libvirt/libvirtd.conf_$ (Date +%f)
Cat >>/etc/libvirt/libvirtd.conf << eoflisten_tls = 0listen_tcp = 1tcp_port = "16666" Unix_sock_dir = "/va R/run/libvirt "auth_tcp =" None "EOF
Service LIBVIRTD Stop && service LIBVIRTD start
11. Enable LIBVIRTD to turn off TLS and turn on TCP features in two ways
Method One: Sed-i ' s/#LIBVIRTD_ARGS = "--listen"/libvirtd_args= "--listen"/g '/ETC/SYSCONFIG/LIBVIRTD/ETC/INIT.D/LIBVIRTD Restart NETSTAT-TULNP | grep 16666
Method Two: Libvirtd--listen-d or Libvirtd-l-D
12. Configure the VNC listener address, the default is 127.0.0.1, change to 0.0.0.0, and this is done to create VM virtual machines. You don't need to specify--vnclisten 0.0.0.0
Sed-i ' s/#vnc_listen = "0.0.0.0"/vnc_listen = "0.0.0.0"/g '/etc/libvirt/qemu.conf cat/etc/libvirt/qemu.conf | More
13. Check if the KVM module is loading properly
Lsmod | grep KVM
14. View version
Virsh-version/usr/libexec/qemu-kvm-version
15. Close the NetworkManager network Management Server
Chkconfig NetworkManager offservice NetworkManager stopservice NetworkManager Status
16. Configure the BR0 NIC
CD/ETC/SYSCONFIG/NETWORK-SCRIPTS/CP Ifcfg-eth0 Ifcfg-br0
The eth0 configuration is as follows:
[email protected] network-scripts]# cat Ifcfg-eth0 device=eth0hwaddr=00:0c:29:57:87:7ftype=ethernetbridge=br0uuid= 14fbc589-a209-4b37-acd5-60ef51214cdbonboot=yesnm_controlled=yesbootproto=none
The BR0 configuration is as follows:
[email protected] network-scripts]# cat ifcfg-br0 device=br0hwaddr=00:0c:29:57:87:7ftype=bridgeuuid= 14fbc589-a209-4b37-acd5-60ef51214cdbonboot=yesnm_controlled=yesbootproto=noneipaddr=192.168.1.154netmask= 255.255.255.0gateway=192.168.1.1
17. View Network Bridge
Brctl Show
Two: KVM Create virtual machine
1. Using the Virt-install tool to create a virtual machine, it calls QEMU-KVM
Specific parameters:
--name virtual machine name--ram allocate memory, take value without units, Directly for the numeric value, the default unit mb--vcpus allocates the number of CPUs, cannot check the physical server total core number--disk virtual machine disk location, followed by path=dirpath: The location of the disk image storage. device: type , Cdrom ,disk,floppybus: Disk type: ide,scsi,usb,virtio,xenperms: Access: Rw,ro,sh ( Shared read-write), default rwsize: Disk size, Unit gbformat: Disk format. Sparse: Disk uses sparse format, that is, does not immediately allocate space for the specified size--network Using Bridging Mode bridge: Connect to the specified bridge adapter model: Network card device model. E1000,RTL8139,VIRTIOMAC: Fixed MAC address. In either way. For KVM, the first three paragraphs must be 54:52:00--cdrom Specify the location of the ISO image--vnc specify an open port that enables the VNC service--VNCPORT&NBSP;VNC service for remote connection use--vnclisten The default is 127.0.0.1, which only runs its own access, typically to 0.0.0.0--os-type linux or Windows or unix--os-variant system models. including win7|vista|winxp64|winxp|win2k8|win2k3|freebsd8|generic|debiansqueeze|debianlenny|fedora16|fedora15| fedora14|rhel6|rhel5.4|rhel4|sles11|sles10|--accelerate Acceleration
2. Upload the ISO image to the specified directory to create a mirrored storage location
Mkdir/isomkdir/vm
3. Create a QCOW2-formatted disk, you must create a disk image before creating the virtual machine
Qemu-img create-f qcow2/vm/api1-qcow2.img 8G virt-install--name api1--ram 1--vcpus , SIZE=8,DEVICE=DISK,FORMAT=QCOW2,BUS=VIRTIO,PERMS=RW--network bridge=br0,model=virtio--cdrom/iso/centos-6.6-x86 _64-minimal.iso--vnc--vncport 5911--vnclisten=0.0.0.0--os-type=linux--os-variant=rhel6--accelerate
4.TIGERVNC Connection
ip:5911, installation process, complete installation. Restart the Guestos, after the reboot is complete, you must manually open the Guestos client with the Virsh start name command.
5. Create a disk for the raw (virtual machine default disk format). You can create it directly, and you do not need to create a disk image first.
Virt-install--name api2--ram512--vcpus 1--DISK/VM/API2-RAW.IMG,SIZE=8,DEVICE=DISK,FORMAT=RAW,BUS=VIRTIO,PERMS=RW --network bridge=br0,model=virtio--cdrom/iso/centos-6.6-x86_64-minimal.iso--vnc--vncport=5912--vnclisten=0.0.0. 0--os-tyep=linux--os-variant=rhel6--acclerate
6.TIGERVNC Connection
ip:5912, installation process, complete installation. Restart Guestos. You must manually open the Guestos client with the Virsh start name command.
7. After the virtual machine is installed, you cannot use the Virsh shutdown Name and need to install the Acpid service in the virtual machine
Tigervnc Log on to the virtual machine, configure the IP address of the eth0, make sure you can access the extranet, and then
Yum install-y acpid chkconfig acpid on chkconfig--list | grep acpidreboot
8. After the virtual machine system is installed, configure the virtual machine console login configuration to log in by Virsh console name
(1)
echo "ttyS0" >>/etc/securetty && Cat/etc/securetty
(2) vi/etc/grub.conf
RHGB quiet added after: console=ttys0
(3)
echo "So:12345:respawn:/sbin/agetty ttyS0 115200" >>/etc/inittab cat/etc/inittab
(4)
Virsh shutdown name Sleep && Virsh start name
(5)
Virsh Console Name Note that after the virtual machine starts, the normal boot information is displayed in 10s. Don't be nervous.
9. Configure VM Time
Cp/usr/share/zoneinfo/asia/shanghai/etc/localtime
Vi/etc/libvirt/qemu/api2.xml<clock offset= ' UTC ' > ===> <clock offset= ' localtime ' >
Yum install ntpdate-y ntpdate cn.pool.ntp.org echo "*/5 * * * * root ntpdate cn.pool.ntp.org" >>/et C/crontabservice Crond Restart
Three: KVM virtual machine native clone
It is important to note that the state of the source client must be shut down or paused. Native clones are performed using the Virt-clone command. image files and XML configuration files are generated automatically.
1. Native Clone case:
Physical Machine IP Address: 192.168.1.154 virtual machine Name: API1 virtual machine Image:/vm/api1-qcow2.img
(1) Stop Api1virsh shutdown api1 && sleep && exit 0 (2) Start cloning: Virt-clone-o api1-n api2-f/ Vm/api2-qcow2.img (3) Start Api2, modify host name and IP address Virsh console api2vi/etc/sysconfig/networkhostname=vm-api2gateway= 192.168.1.1
(4) Network card error:
Bringing up interface Eth0:device eth0 does no seem to be present, delaying initialization. [FAILED]
(5) Resolve, edit 70-persistent-net.rules
cd/etc/udev/rules.d/&& VI 70-persisten-net.rules
The information of the Eth0 network card is commented, the eth1 card name is changed to Eth0. Record the Mac information for eth1. Then paste the MAC address of the eth1 into the MAC address in the Ifcfg-eth0.
:
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/79/85/wKiom1aTcEOBMa8yAARoJ5MpkLo224.jpg "style=" float: none; "title=" 1111111111111111111.jpg "alt=" Wkiom1atceobma8yaaroj5mpklo224.jpg "/>
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/79/83/wKioL1aTcHOBV_mxAAI84HeDbik828.jpg "style=" float: none; "title=" 22222222222.jpg "alt=" Wkiol1atchobv_mxaai84hedbik828.jpg "/>
(5) Editing the XML configuration file for Api2
Virsh Edit Api2.xml Change the port of VNC port= "5912"
Quad: KVM Virtual machine Disk Snapshot
Attention:
Disk snapshots and disk dynamic scaling are supported only for disks with a disk format of Qcow2.
1. Basic commands
Snapshot-list domainsnapshot-create-as domain shotnamesnapshot-revert domain shotnamesnapshot-delete Domai N Shotname
2. Note
Creating a snapshot must ensure that the virtual machine is turned on. Recovering a snapshot must ensure that the virtual machine is powered off.
3. Example
Domain name:api2shutdown api2snapshot-create-as api2 api2_httpdsnapshot-list api2snapshot-revert api2 api2_ht Tpdsnapshot_delete Api2 api2_httpd
This article from the "Do not ask for the best, only better" blog, please be sure to keep this source http://yujianglei.blog.51cto.com/7215578/1733863
KVM Summary Document One (CentOS-6.5)