Difference between revisions of "Vnx-tutorial-ubuntu"

From VNX
Jump to: navigation, search
(tutorial_ubuntu.xml scenario)
 
(34 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Title|VNX Tutorial Ubuntu}}
+
{{Title|VNX Tutorial (KVM version)}}
  
  
 
== Description ==
 
== Description ==
  
 +
VNX includes several example scenarios based on the [http://www.dit.upm.es/vnumlwiki/index.php/Tutorial VNUML tutorial scenario] but including all types of virtual machines supported by VNX (see tutorial_*.xml files in /usr/share/vnx/examples directory).
 +
 +
The scenario presented here is made of 6 Ubuntu virtual machines (4 hosts -h1, h2, h3 and h4- and 2 routers -r1 and r2-) connected through three virtual networks. The host participates in the scenario having a network interface in Net3. All systems but h1 use an Ubuntu server root filesystem; h1 uses an Ubuntu Desktop to allow starting a web navigator.
  
<center>
 
 
[[File:Tutorial_ubuntu-map.png|center|thumb|600px|<div align=center>
 
[[File:Tutorial_ubuntu-map.png|center|thumb|600px|<div align=center>
 
'''Figure 1: tutorial_ubuntu scenario topology'''</div>]]
 
'''Figure 1: tutorial_ubuntu scenario topology'''</div>]]
</center>
 
  
 
== Starting the scenario ==
 
== Starting the scenario ==
 +
 +
Start the scenario with:
 +
cd /usr/share/vnx/examples/
 +
sudo vnx -f tutorial_ubuntu.xml -v --create
 +
 +
You will see the six virtual machine consoles opening: a graphical one for h1, and textual consoles for the rest.
 +
 +
If you close the consoles, you can reopen the graphical console of h1 with:
 +
 +
sudo vnx -f tutorial_ubuntu.xml -v --console con0 -M h1
 +
 +
And the textual consoles of the rest with:
 +
 +
sudo vnx -f tutorial_ubuntu.xml -v --console con1 -M <vmname>
 +
 +
being <vmname> the name of the virtual machine.
 +
 +
You can also open the consoles manually with the commands shown at the end of vnx execution:
 +
 +
<pre>
 +
-----------------------------------------------------------------------------------------
 +
Scenario "tutorial_ubuntu" started
 +
 +
VM_NAME    | TYPE                | CONSOLE ACCESS COMMAND
 +
-----------------------------------------------------------------------------------------
 +
h1          | libvirt-kvm-linux  | con0:  'virt-viewer -c qemu:///system h1' or 'vncviewer :0'
 +
            |                    | con1:  'virsh -c qemu:///system console h1' or 'screen /dev/pts/0'
 +
-----------------------------------------------------------------------------------------
 +
h2          | libvirt-kvm-linux  | con0:  'virt-viewer -c qemu:///system h2' or 'vncviewer :6'
 +
            |                    | con1:  'virsh -c qemu:///system console h2' or 'screen /dev/pts/12'
 +
-----------------------------------------------------------------------------------------
 +
r1          | libvirt-kvm-linux  | con0:  'virt-viewer -c qemu:///system r1' or 'vncviewer :7'
 +
            |                    | con1:  'virsh -c qemu:///system console r1' or 'screen /dev/pts/13'
 +
-----------------------------------------------------------------------------------------
 +
r2          | libvirt-kvm-linux  | con0:  'virt-viewer -c qemu:///system r2' or 'vncviewer :8'
 +
            |                    | con1:  'virsh -c qemu:///system console r2' or 'screen /dev/pts/14'
 +
-----------------------------------------------------------------------------------------
 +
h3          | libvirt-kvm-linux  | con0:  'virt-viewer -c qemu:///system h3' or 'vncviewer :9'
 +
            |                    | con1:  'virsh -c qemu:///system console h3' or 'screen /dev/pts/22'
 +
-----------------------------------------------------------------------------------------
 +
h4          | libvirt-kvm-linux  | con0:  'virt-viewer -c qemu:///system h4' or 'vncviewer :10'
 +
            |                    | con1:  'virsh -c qemu:///system console h4' or 'screen /dev/pts/23'
 +
-----------------------------------------------------------------------------------------
 +
</pre>
 +
 +
You can show the previous table at any time with:
 +
sudo vnx -f tutorial_ubuntu.xml -v --console-info
 +
 +
See [[Vnx-console-mgmt|VNX Console Management]] for more details.
  
 
== Executing commands ==
 
== Executing commands ==
 +
 +
You can start the web servers in h3 and h4 with:
 +
sudo vnx -f tutorial_ubuntu.xml -v -x start-www -M h3,h4
 +
This command will execute on h3 and h4 the commands defined by means of <exec> and <filetree> tags and marked with seq="start-www".
 +
 +
For example, for h3 virtual machine:
 +
<!-- Copy the files under conf/tutorial_ubuntu/h3 to vm /var/www directory -->
 +
<filetree seq="start-www" root="/var/www">conf/tutorial_ubuntu/h3</filetree>
 +
<!-- Start/stop apache www server -->
 +
<exec seq="start-www" type="verbatim" ostype="system">chmod 644 /var/www/*</exec>
 +
<exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>
 +
 +
Once you have started the web servers, you can connect to them from the host or from h1 by opening a web navigator and loading http://10.0.2.2.
 +
 +
Additionally, you can start a firefox navigator in h1 automatically using vnx (login into h1 with vnx/xxxx or root/xxxx before executing the command):
 +
sudo vnx -f tutorial_ubuntu.xml -v -x www-h3
 +
And stop (kill) it with:
 +
sudo vnx -f tutorial_ubuntu.xml -v -x www-h3-off
 +
 +
Both commands are defined in the XML with:
 +
    <!-- Start firefox and connect to h3 web server -->
 +
    <exec seq="www-h3"    type="verbatim" ostype="xexec">firefox http://10.0.2.2</exec>
 +
    <exec seq="www-h3-off" type="verbatim" ostype="system">pkill firefox</exec>
 +
 +
<center>
 +
[[File:Tutorial ubuntu-screen-capture.png|center|thumb|500px|<div align=center>
 +
'''Figure 2: tutorial_ubuntu screen capture'''</div>]]
 +
</center>
  
 
== Stopping the scenario ==
 
== Stopping the scenario ==
 +
 +
To stop the scenario preserving the changes made inside virtual machines you have to use the "-d" or "--shutdown" option:
 +
sudo vnx -f tutorial_ubuntu.xml -v --shutdown
 +
You can later restart the scenario with:
 +
sudo vnx -f tutorial_ubuntu.xml -v --create
 +
 +
To stop the scenario discarding all the changes made in the virtual machine use the "-P" or "--destroy" option:
 +
sudo vnx -f tutorial_ubuntu.xml -v --destroy
  
 
== Other interesting options ==
 
== Other interesting options ==
 +
 +
You can restart the virtual machines individually with:
 +
sudo vnx -f tutorial_ubuntu.xml -v --shutdown -M h1
 +
sudo vnx -f tutorial_ubuntu.xml -v --create -M h1
 +
 +
You can suspend and restore a virtual machine with:
 +
sudo vnx -f tutorial_ubuntu.xml -v --suspend -M h1
 +
sudo vnx -f tutorial_ubuntu.xml -v --resume -M h1
 +
 +
You can see a graphical map of the virtual scenario using the --show-map option:
 +
 +
sudo vnx -f tutorial_ubuntu.xml -v --show-map
 +
 +
<center>
 +
[[File:Tutorial_ubuntu.png|center|thumb|500px|<div align=center>
 +
'''Figure 1: tutorial_ubuntu scenario topology'''</div>]]
 +
</center>
  
 
== tutorial_ubuntu.xml scenario ==
 
== tutorial_ubuntu.xml scenario ==
Line 85: Line 188:
 
     <!-- Start firefox and connect to h3 web server -->
 
     <!-- Start firefox and connect to h3 web server -->
 
     <exec seq="www-h3"    type="verbatim" ostype="xexec">firefox http://10.0.2.2</exec>
 
     <exec seq="www-h3"    type="verbatim" ostype="xexec">firefox http://10.0.2.2</exec>
     <exec seq="www-h3-off" type="verbatim" ostype="system">pkill firefox; rm /tmp/vnx.*</exec>
+
     <exec seq="www-h3-off" type="verbatim" ostype="system">pkill firefox</exec>
  
 
     <!-- Start calculator  -->
 
     <!-- Start calculator  -->
Line 170: Line 273:
 
</vnx>
 
</vnx>
 
</pre>
 
</pre>
 
== Mas cosas ==
 
 
sudo vnx -f simple_ubuntu-gui.xml -v --suspend -M ubuntu-gui
 
sudo vnx -f simple_ubuntu-gui.xml -v --resume -M ubuntu-gui
 
 
To start the web servers in h3 and h4:
 
sudo vnx -f tutorial_ubuntu.xml -v -x start-www
 
 
To start a firefox navigator and load main page of h3 web server:
 
sudo vnx -f tutorial_ubuntu.xml -v -x www-h3
 
 
 
<center>
 
[[File:Tutorial_ubuntu.png|center|thumb|500px|<div align=center>
 
'''Figure 1: tutorial_ubuntu scenario topology'''</div>]]
 
</center>
 
 
<center>
 
[[File:Tutorial ubuntu-screen-capture.png|center|thumb|500px|<div align=center>
 
'''Figure 1: tutorial_ubuntu screen capture'''</div>]]
 
</center>
 
Tutorial_ubuntu-screen-capture.png
 
 
<li> '''tutorial_root1-XXXX.xml''', which are virtual scenarios based on the [http://www.dit.upm.es/vnumlwiki/index.php/Tutorial VNUML tutorial scenario] but starting virtual machines using other operating systems.</li>
 
 
=== Tutorial scenarios (tutorial_root1_XXXX.xml) ===
 
 
<ul>
 
 
<li>To start the tutorial scenario with linux, FreeBSD, XP and Win7 virtual machines just type:</li>
 
sudo vnx -f tutorial_root1_all.xml -v --create
 
 
<li>Once the scenario has completely started (remenber that libvirt machines have to be restarted for the autoconfiguration to complete), you should see all the virtual machine consoles:</li>
 
<center>
 
[[Image:Vnx-tutorial_root1_all-s.png|400px]]
 
</center>
 
 
<li>You can test the network connectivity, for example, accesing '''h1''' machine and tracing to '''h4''':
 
traceroute -n 10.0.2.3
 
 
<li>To stop and restart a virtual machine without loosing the modifications you have made you can type::
 
  sudo vnx -f tutorial_root1_all.xml -v --shutdown -M uml4
 
  sudo vnx -f tutorial_root1_all.xml -v --create  -M uml4
 
 
<li>The same but loosing the changes made and returning to a fresh virtual machine state:
 
  sudo vnx -f tutorial_root1_all.xml -v --destroy -M uml4
 
  sudo vnx -f tutorial_root1_all.xml -v --create -M uml4
 
 
</ul>
 

Latest revision as of 01:04, 8 June 2014

VNX Tutorial (KVM version)


Description

VNX includes several example scenarios based on the VNUML tutorial scenario but including all types of virtual machines supported by VNX (see tutorial_*.xml files in /usr/share/vnx/examples directory).

The scenario presented here is made of 6 Ubuntu virtual machines (4 hosts -h1, h2, h3 and h4- and 2 routers -r1 and r2-) connected through three virtual networks. The host participates in the scenario having a network interface in Net3. All systems but h1 use an Ubuntu server root filesystem; h1 uses an Ubuntu Desktop to allow starting a web navigator.

Figure 1: tutorial_ubuntu scenario topology

Starting the scenario

Start the scenario with:

cd /usr/share/vnx/examples/
sudo vnx -f tutorial_ubuntu.xml -v --create

You will see the six virtual machine consoles opening: a graphical one for h1, and textual consoles for the rest.

If you close the consoles, you can reopen the graphical console of h1 with:

sudo vnx -f tutorial_ubuntu.xml -v --console con0 -M h1

And the textual consoles of the rest with:

sudo vnx -f tutorial_ubuntu.xml -v --console con1 -M <vmname>

being <vmname> the name of the virtual machine.

You can also open the consoles manually with the commands shown at the end of vnx execution:

-----------------------------------------------------------------------------------------
 Scenario "tutorial_ubuntu" started

 VM_NAME     | TYPE                | CONSOLE ACCESS COMMAND
-----------------------------------------------------------------------------------------
 h1          | libvirt-kvm-linux   | con0:  'virt-viewer -c qemu:///system h1' or 'vncviewer :0'
             |                     | con1:  'virsh -c qemu:///system console h1' or 'screen /dev/pts/0'
-----------------------------------------------------------------------------------------
 h2          | libvirt-kvm-linux   | con0:  'virt-viewer -c qemu:///system h2' or 'vncviewer :6'
             |                     | con1:  'virsh -c qemu:///system console h2' or 'screen /dev/pts/12'
-----------------------------------------------------------------------------------------
 r1          | libvirt-kvm-linux   | con0:  'virt-viewer -c qemu:///system r1' or 'vncviewer :7'
             |                     | con1:  'virsh -c qemu:///system console r1' or 'screen /dev/pts/13'
-----------------------------------------------------------------------------------------
 r2          | libvirt-kvm-linux   | con0:  'virt-viewer -c qemu:///system r2' or 'vncviewer :8'
             |                     | con1:  'virsh -c qemu:///system console r2' or 'screen /dev/pts/14'
-----------------------------------------------------------------------------------------
 h3          | libvirt-kvm-linux   | con0:  'virt-viewer -c qemu:///system h3' or 'vncviewer :9'
             |                     | con1:  'virsh -c qemu:///system console h3' or 'screen /dev/pts/22'
-----------------------------------------------------------------------------------------
 h4          | libvirt-kvm-linux   | con0:  'virt-viewer -c qemu:///system h4' or 'vncviewer :10'
             |                     | con1:  'virsh -c qemu:///system console h4' or 'screen /dev/pts/23'
-----------------------------------------------------------------------------------------

You can show the previous table at any time with:

sudo vnx -f tutorial_ubuntu.xml -v --console-info

See VNX Console Management for more details.

Executing commands

You can start the web servers in h3 and h4 with:

sudo vnx -f tutorial_ubuntu.xml -v -x start-www -M h3,h4

This command will execute on h3 and h4 the commands defined by means of <exec> and <filetree> tags and marked with seq="start-www".

For example, for h3 virtual machine:

<filetree seq="start-www" root="/var/www">conf/tutorial_ubuntu/h3</filetree>
<exec seq="start-www" type="verbatim" ostype="system">chmod 644 /var/www/*</exec>
<exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>

Once you have started the web servers, you can connect to them from the host or from h1 by opening a web navigator and loading http://10.0.2.2.

Additionally, you can start a firefox navigator in h1 automatically using vnx (login into h1 with vnx/xxxx or root/xxxx before executing the command):

sudo vnx -f tutorial_ubuntu.xml -v -x www-h3

And stop (kill) it with:

sudo vnx -f tutorial_ubuntu.xml -v -x www-h3-off

Both commands are defined in the XML with:

   <exec seq="www-h3"    type="verbatim" ostype="xexec">firefox http://10.0.2.2</exec>
   <exec seq="www-h3-off" type="verbatim" ostype="system">pkill firefox</exec>
Figure 2: tutorial_ubuntu screen capture

Stopping the scenario

To stop the scenario preserving the changes made inside virtual machines you have to use the "-d" or "--shutdown" option:

sudo vnx -f tutorial_ubuntu.xml -v --shutdown

You can later restart the scenario with:

sudo vnx -f tutorial_ubuntu.xml -v --create

To stop the scenario discarding all the changes made in the virtual machine use the "-P" or "--destroy" option:

sudo vnx -f tutorial_ubuntu.xml -v --destroy

Other interesting options

You can restart the virtual machines individually with:

sudo vnx -f tutorial_ubuntu.xml -v --shutdown -M h1
sudo vnx -f tutorial_ubuntu.xml -v --create -M h1

You can suspend and restore a virtual machine with:

sudo vnx -f tutorial_ubuntu.xml -v --suspend -M h1
sudo vnx -f tutorial_ubuntu.xml -v --resume -M h1

You can see a graphical map of the virtual scenario using the --show-map option:

sudo vnx -f tutorial_ubuntu.xml -v --show-map
Figure 1: tutorial_ubuntu scenario topology

tutorial_ubuntu.xml scenario

<?xml version="1.0" encoding="UTF-8"?>

<!--
~~~~~~~~~~~~~~~~~~~~
VNX Sample scenarios
~~~~~~~~~~~~~~~~~~~~

Name:        tutorial_ubuntu
Description: A simple tutorial scenario made of 6 Ubuntu virtual machines (4 hosts: h1, h2, h3 and h4; 
             and 2 routers: r1 and r2) connected through three virtual networks. The host participates 
             in the scenario having a network interface in Net3.     

This file is part of the Virtual Networks over LinuX (VNX) Project distribution. 
(www: http://www.dit.upm.es/vnx - e-mail: vnx@dit.upm.es) 

Departamento de Ingenieria de Sistemas Telematicos (DIT)
Universidad Politecnica de Madrid
SPAIN
-->

<vnx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="/usr/share/xml/vnx/vnx-2.00.xsd">
  <global>
    <version>2.0</version>
    <scenario_name>tutorial_ubuntu</scenario_name>
    <automac/>
    <vm_mgmt type="none" />
    <vm_defaults>
	    <console id="0" display="no"/>
	    <console id="1" display="yes"/>
    </vm_defaults>
  </global>

  <net name="Net0" mode="virtual_bridge" />
  <net name="Net1" mode="virtual_bridge" />
  <net name="Net2" mode="virtual_bridge" />
  <net name="Net3" mode="virtual_bridge" />

  <vm name="h1" type="libvirt" subtype="kvm" os="linux">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu-gui</filesystem>
    <mem>384M</mem>
    <console id="0" display="yes"/>
    <console id="1" display="no"/>
    <if id="1" net="Net0">
      <ipv4>10.0.0.2/24</ipv4>
    </if>
    <route type="ipv4" gw="10.0.0.1">default</route>
    
    <filetree seq="vnxtxt" root="/tmp">conf/txtfile</filetree>

    <!-- Start xeyes application -->
    <exec seq="xeyes"     type="verbatim" ostype="xexec">xeyes</exec>

    <!-- Start xeyes application and wait until it is closed -->
    <exec seq="xeyes2"    type="verbatim" ostype="xsystem">xeyes</exec>

    <!-- Start gedit, maximize the window and show a text file -->
    <exec seq="vnxtxt"    type="verbatim" ostype="system">chmod 666 /tmp/vnx.txt</exec>
    <exec seq="vnxtxt"    type="verbatim" ostype="xexec">gedit /tmp/vnx.txt</exec>
    <exec seq="vnxtxt"    type="verbatim" ostype="xexec">sleep 3; wmctrl -r vnx.txt -b add,maximized_vert,maximized_horz</exec>
    <exec seq="vnxtxtoff" type="verbatim" ostype="system">pkill gedit; rm /tmp/vnx.*</exec>

    <!-- Start firefox and connect to h3 web server -->
    <exec seq="www-h3"    type="verbatim" ostype="xexec">firefox http://10.0.2.2</exec>
    <exec seq="www-h3-off" type="verbatim" ostype="system">pkill firefox</exec>

    <!-- Start calculator  -->
    <exec seq="calc"      type="verbatim" ostype="xexec">gcalctool</exec>
    <exec seq="calcoff"   type="verbatim" ostype="system">pkill gcalctool</exec>
   
  </vm>

  <vm name="h2" type="libvirt" subtype="kvm" os="linux">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu</filesystem>
    <mem>128M</mem>
    <if id="1" net="Net0">
      <ipv4>10.0.0.3/24</ipv4>
    </if>
    <route type="ipv4" gw="10.0.0.1">default</route>
  </vm>

  <vm name="r1" type="libvirt" subtype="kvm" os="linux">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu</filesystem>
    <mem>128M</mem>
    <if id="1" net="Net0">
      <ipv4>10.0.0.1/24</ipv4>
    </if>
    <if id="2" net="Net1">
      <ipv4>10.0.1.1/24</ipv4>
    </if>
    <if id="3" net="Net3">
      <ipv4>10.0.3.1/24</ipv4>
    </if>
    <route type="ipv4" gw="10.0.1.2">10.0.2.0/24</route>
    <forwarding type="ip" />
  </vm>

  <vm name="r2" type="libvirt" subtype="kvm" os="linux">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu</filesystem>
    <mem>128M</mem>
    <if id="1" net="Net1" name="s1/0">
      <ipv4>10.0.1.2/24</ipv4>
    </if>
    <if id="2" net="Net2" name="e0/0">
      <ipv4>10.0.2.1/24</ipv4>
    </if>
    <route type="ipv4" gw="10.0.1.1">default</route>
    <forwarding type="ip" />
  </vm>

  <vm name="h3" type="libvirt" subtype="kvm" os="linux">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu</filesystem>
   <mem>128M</mem>
   <if id="1" net="Net2">
      <ipv4>10.0.2.2/24</ipv4>
    </if>
    <route type="ipv4" gw="10.0.2.1">default</route>
    <!-- Copy the files under conf/tutorial_ubuntu/h3 to vm /var/www directory -->
    <filetree seq="start-www" root="/var/www">conf/tutorial_ubuntu/h3</filetree>
    <!-- Start/stop apache www server -->
    <exec seq="start-www" type="verbatim" ostype="system">chmod 644 /var/www/*</exec>
    <exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>
    <exec seq="stop-www" type="verbatim"  ostype="system">service apache2 stop</exec>    
  </vm>
  
  <vm name="h4" type="libvirt" subtype="kvm" os="linux">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu</filesystem>
    <mem>128M</mem>
    <if id="1" net="Net2">
      <ipv4>10.0.2.3/24</ipv4>
    </if>
    <route type="ipv4" gw="10.0.2.1">default</route>    
    <!-- Copy the files under conf/tutorial_ubuntu/h4 to vm /var/www directory -->
    <filetree seq="start-www" root="/var/www">conf/tutorial_ubuntu/h4</filetree>
    <!-- Start/stop apache www server -->
    <exec seq="start-www" type="verbatim" ostype="system">chmod 644 /var/www/*</exec>
    <exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>
    <exec seq="stop-www" type="verbatim"  ostype="system">service apache2 stop</exec>    
  </vm>
  
  <host>
    <hostif net="Net3">
       <ipv4>10.0.3.2/24</ipv4>
    </hostif>
    <route type="ipv4" gw="10.0.3.1">10.0.0.0/16</route>
  </host>

</vnx>