Open main menu

CDOT Wiki β

Changes

OPS235 Lab 2 - CentOS7

507 bytes removed, 12:17, 29 March 2015
no edit summary
# Open a web-browser, and open the OPS235 Lab #2 WIKI.
# Install the virtualization software by issuing the command:<br><b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python \<br>python-virtinst libvirt-client virt-install virt-viewer</span></code></b> <br><br>
::This will install many applications (including):
:::* A graphical tool for managing virtual machines ('''virt-manager''') and the '''virsh''' command-line tool.<br>
<ol>
<li value="3">Start the virtualization service: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">service libvirtd start</span></code></b></li> <li>The firewall configuration is altered by the addition of the virtualization software. Restart the firewall so that these changes become active: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">service iptables restart</span></code></b></li>
</ol>
<ol>
<li value="5">Start the graphical tool by selecting the menu options '''Applications'''>'''System Tools'''>'''Virtual Machine Manager''' or by typing the command <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virt-manager</span></code></b></li>
</ol>
<ol>
<li value="15">Enable SSH access to your virtual machine with these commands (semi-colon allows commands to be run in sequence):<br /> <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">service sshd start; chkconfig sshd on</span></code></b></li> <li>Find out the IP address of your virtual machine: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">ifconfig eth0</span></code></b> </li> <li>Enter the following command on your virtual machine to create a firewall exception to allow ssh traffic into the machine:<br /> <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">iptables -I INPUT -p tcp -s0/0 -d0/0 --dport 22 -j ACCEPT</span></code></b></li> <li>Confirm that you can ssh to your virtual machine from the host (your main CentOS installation): <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">ssh c7host_IPaddress</span></code></b> (where c7host_IPaddress is the dotted-quad address of your c7host machine).</li>
</ol>
# In each VM, run this command: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">yum update</span></code></b>
# Record the answers to these questions in your log book:
#* How long did it take to run on each VM? How many packages were updated?
# Switch to the c7host machine, and open a shell terminal.
# Enter these commands into your c7host machine and note the result:
#* <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virsh list</span></code></b>#* <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virsh list --all</span></code></b>#* <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virsh list --inactive</span></code></b>
# Now, shut-down your centos1 VM normally, and close the centos1 VM window.
# Switch to your terminal and issue the command: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virsh start centos1</span></code></b>
# Using the appropriate command check to see if your centos1 VM is now running.
# There are other commands that can be used (such as '''suspend''', or '''shutdown'''). The "shutdown" command may not always work since it relies on the guest handling a particular ACPI event. Why do you think it is useful to have commands to manipulate VMs?
# Shut down all of the virtual machines.
# Change to the directory <code>/var/lib/libvirt/images/</code>. Note the size of the files in this directory. What do these files contain?
# Make a compressed backup of the <code>centos3.img</code> file to your home directory with this command: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">gzip < centos3.img > ~YourUserId/centos3.img.backup.gz</span></code></b><br />(Note: Make certain to use the redirection signs "<" and ">" properly in the command!)
{{Admon/caution| Make sure the backup is successful!|If there are any error messages, '''DO NOT''' proceed past this point. You're going to destroy your centos3 virtual machine and restore it using the backup you have created -- if there are any problems with the backup, you will not have a working virtual machine, and will have to re-install it.}}
<ol>
<li>Start the '''''centos3''''' VM.</li>
<li>'''Make certain that you are in your VM and <u>not</u> in your main system!'''</li>
<li>Wreck <u>only</u> your centos3 system! Try this command inside the centos3 virtual machine: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">rm -rf /*</span></code></b></li>
<li>Shut down the VM. If you tried to start the centos3 VM, it would not boot since all system files have been removed!</li>
<li>Restore the original image from the backup in your home directory by typing this command: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">gunzip < ~YourUserId/centos3.img.backup.gz > centos3.img'''</span></code></b></li>
<li>Restart the VM. Is it working normally?</li>
<li>Create compressed backups of your other virtual machines.</li>
<ol>
<li value="12">You should make a copy of the xml configuration file in case you "wipe" and re-install the host machine, and want to add a restored VM backups to the virtual machine manager list. We will demonstrate using the centos3 xml configuration file, and prove that a "clone" can be added to your list.Please perform the following step:<ol type="a">
<li>Execute the following command: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virsh dumpxml centos3 >centos3.xml</span></code></b></li> <li>Examine the file <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">centos3.xml</span></code></b>. What does it contain? What format is it in?</li> <li>Make a copy of <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">centos3.xml</span></code></b> called <code>centos3a.xml</code>.</li> <li>Edit the file <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">centos3a.xml</span></code></b>, making the following changes:</li>
</ol>
::* Change the name (in the file, not the file name) to '''centos3a'''
::* Change at least one of the hexadecimal characters in the UUID. Do not change the length of the UUID. Valid hexadecimal characters are 0-9 and a-f.
<ol type="a" >
<li value="6">Issue this command: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virsh define centos3a.xml</span></code></b> <li>Issue the command <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virsh list --all</span></code></b> and record any changes. <li>Issue the command: <b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">virsh undefine centos3a</span></code></b>
<li>List all of the virtual machines again, and note any changes. </li></ol>
<li>For the remainder of these labs, it is assumed that you will backup <u>'''both'''</u> the images and xml configuration files for <u>'''all'''</u> Virtual machines, when asked to backup your virtual machines. It is also highly recommended to backup these files to an external storage device (eg. USB key) in case the host machine gets "wiped" and you need to rebuild your HOST machine and then restore your Virtual Machines...</li>
13,420
edits