Linux systems with scripts to install virtual machines and their management, snapshots and virtual machine resets

Source: Internet
Author: User
Tags first string

To quickly install multiple virtual machines, you can take a snapshot of the original virtual machine hard disk files and install multiple virtual speeds using quick find is fairly fast, then I'll show you how to create a snapshot and write a simple shell command to install a virtual machine.

First, install the virtual machine

(1) Install with Shell script (2) Get full-end management of a virtual machine and hard disk file (3) Create a virtual machine snapshot installation

  1. Shell Script Installation

    Switch to root user

    Edit Script vim/mnt/creatre_vm.sh, create_vm.sh is the name of the script, SH is the meaning of the script

    #!/bin/bash Command Run environment specified

    Virt-install \ Installing virtual machines

    --name \ Virtual machine name specified, which represents the first string of characters after the script

    --ram 1000 \ Memory

    --FILE/VAR/LIB/LIBVIRT/IMAGES/$1.IMG \ Hard Disk File

    --file-size 8 \ Hard disk File size

    --cdrom/var/ftp/pub/iso/rhel-server-7.1-x86_64-dvd.iso & Installation Source designation

    \ Wrap & put in the background, do not occupy the terminal

    650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/25/298447fc90589fee506dc3ea19e949e3.png-wh_500x0-wm_3 -wmp_4-s_2406131904.png "title=" 119.png "alt=" 298447fc90589fee506dc3ea19e949e3.png-wh_ "/>650) this.width=650;" Src= "https://s1.51cto.com/oss/201710/25/90472e0c13d398e5e9cabde1f4b96dce.png-wh_500x0-wm_3-wmp_4-s_1570528011. PNG "style=" Float:none; "title=" 120.png "alt=" 90472e0c13d398e5e9cabde1f4b96dce.png-wh_ "/>


650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/25/05cf2ffbbcc13c7c1e0112b0f22d30a1.png-wh_500x0-wm_3 -wmp_4-s_134006553.png "style=" Float:none; "title=" 121.png "alt=" 05cf2ffbbcc13c7c1e0112b0f22d30a1.png-wh_ "/>

Execute/MNT/CREATE_VM node2 Node2 is the name of the virtual machine created

Virtual Machine Node2 created successfully

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/6acf171fffa3c72cb6d0601ca39ef4fa.png-wh_500x0-wm_3 -wmp_4-s_2250388933.png "title=" 122.png "alt=" 6acf171fffa3c72cb6d0601ca39ef4fa.png-wh_ "/>

2. Get a front end file and a hard disk file to install

(1) Hard disk File:/var/lib/libvirt/images/under Vm.qcow (VM is the name of the virtual machine)

(2) Front-end management files:/etc/libvirt/qemu/under the Vm.xml

There are two files above to complete the virtual machine installation, the steps are as follows

(1) got the Node1.qcow,node1.xml

(2) Move the hard disk files to/var/lib/libvirt/images/, move the front-end management files to,/etc/libvirt/qemu/

(3) Display virtual machine

Temporary: Virsh Create Vm.xml

Permanent: Virsh define Vm.xml

3. The following

Second, virtual machine management

Virt-manager Opening the Graphics management tool

Virt-viewer vmname display virtual machine, Vmname represents the virtual machine name

Virsh List List of running VMS

Virsh list--all List all VMS

Virsh start Vmname Run the specified VM

Virsh shutdown vmname Normal shutdown of the specified VM

Virsh destroy Vmname forcibly ends the specified VM

Virsh Create vmname.xml Temporary restore specifies vm,vmname represents the front end management file

Virsh define Vmname.xml permanently recover VMS

Virsh undefine Vmname Delete the front-end management of the VM and does not delete the storage

1.virt List List of running VMS

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/3e8a6ae6df0a81c033cc0e177d8a4852.png-wh_500x0-wm_3 -wmp_4-s_4236333703.png "style=" Float:none; "title=" 123.png "alt=" 3e8a6ae6df0a81c033cc0e177d8a4852.png-wh_ "/>

2.virsh list--all List all VMS

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201710/25/830896076affaf744044654c9b1a61c8.png-wh_500x0-wm_3 -wmp_4-s_2696228830.png "style=" Float:none; "title=" 124.png "alt=" 830896076affaf744044654c9b1a61c8.png-wh_ "/>

3.virsh shutdown node2 normal shutdown node2

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201710/25/02052b13f6ec24d8f6352f48d6a02c05.png-wh_500x0-wm_3 -wmp_4-s_3132777684.png "style=" Float:none; "title=" 125.png "alt=" 02052b13f6ec24d8f6352f48d6a02c05.png-wh_ "/>

4.virsh Start Node2 running Node2

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/8fabd26a6f55863eb816fc40d3cb59fe.png-wh_500x0-wm_3 -wmp_4-s_2179358846.png "style=" Float:none; "title=" 126.png "alt=" 8fabd26a6f55863eb816fc40d3cb59fe.png-wh_ "/>

5.virsh destroy Node2 forcibly closed Node2

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/dde039e92f8f3d92552cebd89901f4a8.png-wh_500x0-wm_3 -wmp_4-s_2906499137.png "style=" Float:none; "title=" 127.png "alt=" Dde039e92f8f3d92552cebd89901f4a8.png-wh_ "/>

6.virsh Create node2 Temporary recovery Node2

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/2f85a3021472b1021ef7f61b616f74a2.png-wh_500x0-wm_3 -wmp_4-s_1347960504.png "style=" Float:none; "title=" 128.png "alt=" 2f85a3021472b1021ef7f61b616f74a2.png-wh_ "/>

7.virsh undefine node2 Remove front-end management

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/c4fcee9bd08c84d19f544d93a732f0fe.png-wh_500x0-wm_3 -wmp_4-s_1790847898.png "style=" Float:none; "title=" 129.png "alt=" C4fcee9bd08c84d19f544d93a732f0fe.png-wh_ "/>

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/f2c71facbd5f5daf167bf38bc5ce9894.png-wh_500x0-wm_3 -wmp_4-s_842977223.png "style=" Float:none; "title=" 130.png "alt=" F2c71facbd5f5daf167bf38bc5ce9894.png-wh_ "/>

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201710/25/a3b595705e54751c44e0f60fd59bfe93.png-wh_500x0-wm_3 -wmp_4-s_2893510182.png "style=" Float:none; "title=" 131.png "alt=" A3b595705e54751c44e0f60fd59bfe93.png-wh_ "/>

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/77e9cf432adc0ee52d30ce9a948f563f.png-wh_500x0-wm_3 -wmp_4-s_3401714071.png "style=" Float:none; "title=" 132.png "alt=" 77e9cf432adc0ee52d30ce9a948f563f.png-wh_ "/>

8.virsh Define Node2.xml Permanent recovery

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/632f1a4ece6f4d66d30634b629891114.png-wh_500x0-wm_3 -wmp_4-s_2639983624.png "style=" Float:none; "title=" 134.png "alt=" 632f1a4ece6f4d66d30634b629891114.png-wh_ "/>

Third, create a snapshot

    1. A snapshot is like copying a file, and all operations are done on the copied file without affecting the original file.

    2. Two important documents

      (1) Hard disk File:/var/lib/libvirt/images/

      (2) Front-end Management files:/etc/libvirt/qemu/(Recording virtual pre-segment graphics, data, information)

    3. Create a Snapshot

      (1) Developing a Snapshot object:/var/lib/libvirt/images/file

      (2) Input command: qemu-img create-f qcow2-b vm_storage.qcow2 node1-snap.qcow2

      Vm_storage.qcow2 refers to the source file name Node1-snap.qcow2 refers to the snapshot file name

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/25/9669305fdae431e97a509b9a99f1d3a0.png-wh_500x0-wm_3 -wmp_4-s_2329247819.png "title=" 142.png "alt=" 9669305fdae431e97a509b9a99f1d3a0.png-wh_ "/>

4. Installing a virtual machine with a snapshot

Snapshot files are small

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/9c94b30545c5bf347ccbb865bace625d.png-wh_500x0-wm_3 -wmp_4-s_1098331939.png "style=" Float:none; "title=" 143.png "alt=" 9c94b30545c5bf347ccbb865bace625d.png-wh_ "/>

Input Virt-manager

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/654a02062c4be138ff7fe1ffed26851e.png-wh_500x0-wm_3 -wmp_4-s_624931613.png "style=" Float:none; "title=" 144.png "alt=" 654a02062c4be138ff7fe1ffed26851e.png-wh_ "/>

Click on the top left small TV, select the last entry, Forward

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201710/25/a120857946931b17fc385662b4bd287b.png-wh_500x0-wm_3 -wmp_4-s_326051615.png "style=" Float:none; "title=" 145.png "alt=" A120857946931b17fc385662b4bd287b.png-wh_ "/>

Click Browse,forward

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/25/6ffd73fe1554ba86a37d2c9b27501d56.png-wh_500x0-wm_3 -wmp_4-s_2636089173.png "style=" Float:none; "title=" 146.png "alt=" 6ffd73fe1554ba86a37d2c9b27501d56.png-wh_ "/>

Select default, the snapshot file you just created, click chose Volume

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/19946457bbbffd6c8e1f413a94c929bb.png-wh_500x0-wm_3 -wmp_4-s_2494414492.png "title=" 147.png "alt=" 19946457bbbffd6c8e1f413a94c929bb.png-wh_ "/>

Click Forward

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201710/25/99c4e8bae57880d0ebda15576167de5f.png-wh_500x0-wm_3 -wmp_4-s_1884630728.png "style=" Float:none; "title=" 148.png "alt=" 99c4e8bae57880d0ebda15576167de5f.png-wh_ "/>

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/c1b7325b08f0be85853832d39037db6c.png-wh_500x0-wm_3 -wmp_4-s_663789761.png "title=" 149.png "alt=" C1b7325b08f0be85853832d39037db6c.png-wh_ "/>

Finish

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/25/cc4eb04cebc37c439d76b0cece8c495a.png-wh_500x0-wm_3 -wmp_4-s_3655998271.png "style=" Float:none; "title=" 150.png "alt=" Cc4eb04cebc37c439d76b0cece8c495a.png-wh_ "/>

Node2 Installation Success

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/213e333233f29315a7596a640b9fa1e8.png-wh_500x0-wm_3 -wmp_4-s_930420516.png "title=" 151.png "alt=" 213e333233f29315a7596a640b9fa1e8.png-wh_ "/>

Installing virtual machines with snapshots is fast

Iv. using snapshots, scripting to install virtual machines

    1. Writing a file

      650) this.width=650; "Src=" Https://s5.51cto.com/oss/201710/25/efd5d32ff81b057edf6a0bba0bf2cb94.png-wh_500x0-wm_3 -wmp_4-s_2463593519.png "style=" Float:none; "title=" 153.png "alt=" Efd5d32ff81b057edf6a0bba0bf2cb94.png-wh_ "/>

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/b67f84a0dd2463acdaa42986251b7aa0.png-wh_500x0-wm_3 -wmp_4-s_556690252.png "style=" Float:none; "title=" 154.png "alt=" B67f84a0dd2463acdaa42986251b7aa0.png-wh_ "/>

  1. Node1.qcow is the snapshot name

    2.chmod +x cratevm.sh Add executable permissions to the file

    650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/695bcdce5df1f50a9682a6fed5b3fae0.png-wh_500x0-wm_3 -wmp_4-s_2034107533.png "style=" Float:none; "title=" 155.png "alt=" 695bcdce5df1f50a9682a6fed5b3fae0.png-wh_ "/>

    3. Installation

    650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/de7937d44f7a04084b9f93c60a41ea2f.png-wh_500x0-wm_3 -wmp_4-s_705877428.png "style=" Float:none; "title=" 156.1.png "alt=" De7937d44f7a04084b9f93c60a41ea2f.png-wh_ "/>

    650) this.width=650; "Src=" Https://s5.51cto.com/oss/201710/25/57c1c94be9e2945c4abcbdd5bf72b6c8.png-wh_500x0-wm_3 -wmp_4-s_1253176255.png "style=" Float:none; "title=" 156.2.png "alt=" 57c1c94be9e2945c4abcbdd5bf72b6c8.png-wh_ "/ >

    Installation Successful

    650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/25/545a835751c9d0bec0af8060de9eceb9.png-wh_500x0-wm_3 -wmp_4-s_2678188209.png "style=" Float:none; "title=" 156.3.png "alt=" 545a835751c9d0bec0af8060de9eceb9.png-wh_ "/ >

    V. Resetting a virtual machine snapshot

    When a virtual machine snapshot is corrupted, you can call the script reset

    1. Edit the script file vim resetvm.sh

    & background run, \ line break

    650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/c8913ca25302ca0f7be16972da4db365.png-wh_500x0-wm_3 -wmp_4-s_1636499320.png "style=" Float:none; "title=" 157.1.png "alt=" C8913ca25302ca0f7be16972da4db365.png-wh_ "/ >

    650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/7a297c91a8efdb970bcc6e0fe45d7483.png-wh_500x0-wm_3 -wmp_4-s_1949760173.png "style=" Float:none; "title=" 157.2.png "alt=" 7a297c91a8efdb970bcc6e0fe45d7483.png-wh_ "/ >

    650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/d6d4ddb23c9d610e6d89d57d86a623db.png-wh_500x0-wm_3 -wmp_4-s_3167354197.png "style=" Float:none; "title=" 157.3.png "alt=" D6d4ddb23c9d610e6d89d57d86a623db.png-wh_ "/ >

  2. chmod +x/mnt/resetvm.sh gives file executable capability

    650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/e9d4d114c988aef2e4b96506ebae2159.png-wh_500x0-wm_3 -wmp_4-s_143925275.png "style=" Float:none; "title=" 157.4.png "alt=" E9d4d114c988aef2e4b96506ebae2159.png-wh_ "/>

  3. Installation

    650) this.width=650; "Src=" Https://s2.51cto.com/oss/201710/25/8db872a964ed63222c4f248a493584a7.png-wh_500x0-wm_3 -wmp_4-s_3716512195.png "style=" Float:none; "title=" 158.1.png "alt=" 8db872a964ed63222c4f248a493584a7.png-wh_ "/ >

  4. Installation Successful

    650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/25/4e002a8f0c419c8a694fe78a8d8ee8dd.png-wh_500x0-wm_3 -wmp_4-s_527597132.png "style=" Float:none; "title=" 158.2.png "alt=" 4e002a8f0c419c8a694fe78a8d8ee8dd.png-wh_ "/>

  5. Continue editing this file &>/dev/null does not display information about the installation process

    650) this.width=650; "Src=" Https://s3.51cto.com/oss/201710/25/90ba9c219932056c8d793bdb6f99410f.png-wh_500x0-wm_3 -wmp_4-s_1570285205.png "style=" Float:none; "title=" 159.1.png "alt=" 90ba9c219932056c8d793bdb6f99410f.png-wh_ "/ >

    650) this.width=650; "Src=" Https://s5.51cto.com/oss/201710/25/b60b8d225aa92b11d9609d8a5a4b3602.png-wh_500x0-wm_3 -wmp_4-s_3508482753.png "style=" Float:none; "title=" 159.2.png "alt=" B60b8d225aa92b11d9609d8a5a4b3602.png-wh_ "/ >

    Perform

    650) this.width=650; "Src=" Https://s5.51cto.com/oss/201710/25/0e33c087be7f68d26dcb1ad4ca673adc.png-wh_500x0-wm_3 -wmp_4-s_4216463162.png "style=" Float:none; "title=" 159.3.png "alt=" 0e33c087be7f68d26dcb1ad4ca673adc.png-wh_ "/ >

    Installation Successful

    650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/25/5c9c1490ed60fc9bc62a70451bf462ca.png-wh_500x0-wm_3 -wmp_4-s_115464913.png "style=" Float:none; "title=" 159.4.png "alt=" 5c9c1490ed60fc9bc62a70451bf462ca.png-wh_ "/>

6.sh-x resetvm.sh shows if the installation process is normal, + normal

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201710/25/eaa738052cba107da3ad505ac878f09d.png-wh_500x0-wm_3 -wmp_4-s_3790598388.png "style=" Float:none; "title=" 159.5.png "alt=" Eaa738052cba107da3ad505ac878f09d.png-wh_ "/ >






Linux systems with scripts to install virtual machines and their management, snapshots and virtual machine resets

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.