Service Management in Networks - Leischner

Practice sheet 9 - WebApp (2 Point)

In the last practice sheet we created a web server with a simple web site using Docker. Now we want to develop an application in Docker that will be useful in our loadbalancer scenario.

We will use a LAMP stack as a basis for App development. If you wish, you can also use a different development environment. However, the sheet will refer to a LAMP environment.

 

Task 1 - Website

  1. In the last practice sheet we created the docker file for a web server that displays the website ./htmlphp/*. Write a docker-compose.yml file that starts this website as a service website at the local port 20961. Test your composite file.
    Hints:
    • As you are used to, create a subdirectory pr09a1 as the base folder for this task.
    • As you are used to, write an itempotent(!) script start-pr09a1.sh that starts and restarts your web server.
    • Use volumes: to mount directories and use container_name: to give your container a meaningful and useful name (e.g. pr09a1-Webserver)
  2. In which network does the service website run ?

 

Task 2 - Network

  1. The service website will now be provided with its own network frontend. For test purposes, a container toolbox is to be installed in frontend as an additional service. The only task of the container toolbox is to provide network tools. Adapt your compose file such that this scenario is realized.
  2. Control the bridge networks on dockhost by running brctl show at Unix level and docker network ls via docker. Can the results be correlated?
  3. Use docker network inspect pr09a2_frontend to explore the new network.
  4. Get a command line inside toolbox and answer the following question:
    • How can you ping the server with the service website from the toolbox? Which command do you use? Can you also ping the server running service website from task 1?
    • What addressing options are available to you?
    • What IP address does Docker Embedded DNS resolver have in the network frontend?
    •  With which command can you query this name service? Hint: Low-level command getent.
    • Additional question: What is behind the docker concept "named volumes" (not used by us)? What are typical use cases?

 

Task 3 - Database

  1. Extend your Docker Compose File with the official database service library/mariadb . Connect the database to the network frontend , set netlab as a password for the database and create an empty and unconfigured database bigdata.
  2. Go into the database container and connect to the MariaDB as root using the command mysql . Verify with show databases; that the database bigdata has been created.

Task 4 - Database Management Tool

  1. Extend your Docker Compose File with the official phpMyAdmin service phpmyadmin/phpmyadmin . Use environment variables to connect to the database service mariadb. Use the user root with the password netlab.
  2. Open the web interface of phpMyAdmin and check if the database bigdata exists.

 

Task 5 - Database Table

For the bigdata database, create a table activitylog  that persistently stores accesses to the website connected to the database. This table should have the following columns.

  • NumberAccess : Number of accesses to one of the web servers (associated with the database).
  • Timestamp : Time of access.
  • HostName : Name of the host that was accessed.
  • Color : Color of the host. This can be used to highlight the displayed table for analysis.
  • LocalIP : IP address of the server that was accessed.
  • RemoteIP : IP address of the client that accessed the website respectively the web server.

After you have created this table and tested it with a few records, export it to a startup file bigdata.sql .

 

Task 6 - App

So far we have created a website website and a - still isolated - database bigdata. Our database bigdata is containing a table activitylog which is intended for logging website access. Now we want to fill and show the table activitylog by our website using PHP or another programming language for that functionality.

The objective of this exercise is that every call of website generates a colored record in the table activitylog. If different websites access the database the records have different colors. In additon, the record contains the hostname and the remote client's IP.

 

 

Before starting with programming we have to prepare our environment:

  1. First, copy all files from directory pr09a4 (task 4) to a fresh working directory pr09a6. To be prepared for using PHP rename the file index.html (found in subdirectory htmlphp) to index.php. Start the docker scenario with docker-compose up and test it.
  2. Within our container website the the scripting language PHP is already installed. However, to access the mariadb we need an SQL-API for PHP. There are several options to do this. You can use standard MySQL, the improved MySQLi or the PDO (PHP Data Objects) extension. In the web you find a lot of discussions what is the best.

    1) Compare these three APIs, make a list of pros and cons, weigh up the p&c and choose one of them! (I have chosen BDO.) Please submit your list via LEA.

    2) Install the chosen extension on your PHP webserver (this means to augment the Dockerfile of the website and build a new image). Then, calling hallo.php you should find the extension in the field Additional .ini files parsed .

We can structure our task in several well-defined sub tasks. Every sub task should be programmed in separate php file. For testing and at the end of our work we include these files in the main index.php.

You can use the following body part for index.php .

<body><h3>Service Management in Networks 2018 (pr09a6)</h3>
      <?php 
      include ("parameters.php");
      include ("connectDB.php");
      include ("insertRecord.php");
      include ("printTable.php");
      include ("reduceTable.php");
      ?>    
</body>				

Remarks/hints for the include files:

  • parameters.php : Here you can collect parameters (variables, constants) for your program.
  • connectDB.php : Connecting to the database is a crucial part. Therefore, for efficient error handling use try ... catch blocks from PHP.
  • insertTable.php : Insert a new record in the table activitylog. The auto_increment key NumberAccess as well as the Timestamp is set automatically by the databaes. The Color you get by an environment variable. For the remote client's IP check different methods in Google. You can test this coding block using phpMyAdmin.
  • printTable.php : First, print the well-formated header line. Then, in a loop you can print the table records line by line. Selecting the records don't forget to order them by ORDER BY NumberAccess DESC.
  • reduceTable.php : So that the application does not become too slow and no database overflow occurs, it makes sense to delete the older data records. For example, the database only retains only the last 200 records. Think of a way to do this with PHP.

To test your program thoroughly, rename website to website1 and add additional services like website2 and website3 to the  compose-file. Associate the website services with different colors using environment variables.

After vagrant up the following addresses should work locally (assuming you use the ports 20961, 20962 and 20963):

To test the capture of the client's IP address, access the websites with different clients.

 

I, as your professor, programmed this task, too. For testing I have build three websites.

Check it!

 

 

 

Please, submit your answers of the questions as pdf and the git code vagrant.zip as a zip file to LEA - Lernen und Arbeiten online .

 

Impressum/a> | Datenschutz | leischner.inf.h-brs.de, last modification: 26.11.2018-18.21