School of Information Technology and Electrical Engineering
INFS3208 – Cloud Computing Programming Assignment Task II (10 Marks)
Background:
With your docker file in the first assignment, you can develop a simple PHP-based website and swiftly deploy the lightweight website to the customer’s machine without worrying about environment issues (e.g., software and hardware compatibility issues). Now, your manager decides to adopt micro-services architecture in this project which is shown in Figure 1:
Copyright By PowCoder代写 加微信 powcoder
1. Micro-service A (Nginx) is a web server with load balancing to respond to client requests.
2. Micro-service B (order.php) is accepting all online order requests. To handle massive orders in a short period, MS-B pushes all the order requests onto a message queue and only confirms the
products that have been ordered.
3. Micro-service C (Redis) is used as a simple message queue (FIFO) storing all the messages sent
by Micro-service A in a queue.
4. Micro-service D (process.php) will periodically process the orders in the queue in MS-C. For each
order popped out from the message queue in MS-C, MS-D will check the product availability by
sending queries to the main product database.
5. Micro-service E (MariaDB) is the main product database that stores the information of all the
products (stock, price, etc.).
6. Micro-service F (phpMyAdmin) is one of the most popular PHP-based MySQL administration
tools, which supports a wide range of operations like managing databases, relations, tables, columns, indexes, permissions, users, etc. via a graphical user interface.
Figure 1: Micro-service architecture.
Task Description:
In this project, you are asked to write a docker-compose.yml file to orchestrate FIVE containers (Nginx, PHP-FPM, phpMyAdmin, Redis, and MariaDB). You should be able to upload your PHP websites to the remote directory in the container and immediately test the web development without any problems. There are some technical requirements for your docker-compose file as follows:
1. First, you need to use git to download the setting files and test web pages. In your docker- compose file, you should copy the given setting files for Nginx and PHP-FPM to the corresponding places inside of the docker containers by using docker-compose instructions.
2. Apart from the setting files, you will be given four web pages (index.html, index.php, order.php, and process.php). They are used to test whether the deployed containers work properly. The expected results of the testing web pages are shown in Figures 2 – 7.
3. For each container, you can choose to either pull an existing official image from the docker hub or create a customised image.
4. In your docker-compose file, you need to define a network with the bridge driver named as “mynet” to enable communications among all containers. The dependencies among the containers should also be defined (refer to Figure 8 in the Appendix).
5. For the MariaDB container,
a. Name the container as “mysql”.
b. Define the environment variables for the database as follows:
i. MYSQL_ROOT_PASSWORD=MyDBRoot123 ii. MYSQL_DATABASE=cloud_computing
iii. MYSQL_USER=php
iv. MYSQL_PASSWORD =php
c. Connect the MariaDB container to the predefined network “mynet”.
6. For the Redis container,
a. Name the container as “myredis”.
b. Connect the Redis container to the predefined network “mynet”.
7. For the PHP-FPM container,
a. Name the container as “myphp” and expose port 9000.
b. Mount the directory of the web pages (i.e., cca2/src) to the root directory of the
website in the container (i.e., /var/www/html)
c. As PHP-FPM needs to communicate with MariaDB and Redis, this container (“myphp”)
needs to depend on “mysql” and “myredis”.
d. As the official PHP-FPM does not include the extensions (e.g., Redis and MySQL), the
test pages order.php and process.php would not work without the extensions installed. Ensure the required extensions (i.e., redis and mysqli) are installed so that order.php and process.php can work properly.
e. Connect the PHP-FPM container to the predefined network “mynet”.
8. For the Nginx container,
a. Name the container as “mynginx” and map the external port 8080 to internal port 80.
b. Copy the prepared setting files to the correct locations in this container.
i. Copy nginx.ini to /etc/nginx/conf.d/default.conf
c. Mount the directory of the web pages (i.e., cca2/src) to the root directory of the
website in the container (i.e., /var/www/html).
d. This container (“mynginx”) needs to depend on “myphp”.
e. Connect the Nginx container to the predefined network “mynet”.
9. For the phpMyAdmin container,
a. Name the container as “phpMyAdmin” and map the external port 8082 to the internal
b. Specify a MySQL host in the phpMyAdmin container using the hostname of “mysql”.
The details of the database “cloud_computing” created in the “mysql” container can be
viewed on the phpMyAdmin page.
c. Connect the phpMyAdmin container to the predefined network “mynet”.
10. The installation steps of Nginx, PHP-FPM, Redis, and MariaDB on a VM will be described in Appendix. You can practise installing the entire framework on your VM first. Afterwards, you need to convert those installation steps into a docker-compose file with the correct instructions. Notice that the installation steps of phpMyAdmin will NOT be described. You need to investigate how to run a phpMyAdmin docker container by yourself.
Preparation:
In this individual coding assignment, you will apply your knowledge of docker-compose instructions (in Lecture 5) and the related fields.
• Firstly, you should read Background and Task Description to understand the background, motivations, the task, and the technical requirements.
• Secondly, you should practise docker commands, and Linux commands to manually orchestrate the five containers.
• Lastly, you need to write a docker-compose.yml by converting the docker commands and Linux commands into the docker compose instructions. All technical requirements need to be fully met to achieve full marks.
You can practise either on the GCP’s VM or your local machine with Oracle VirtualBox if you are unable to access GCP.
Assignment Submission:
§ You need to compress the docker-compose.yml file and the supporting files (if they exist). § The name of the compressed file should be named “FirstName_LastName_StudentNo.zip”. § You must make an online submission to Blackboard before 1:00 PM on Friday, 16/09/2022. § Only one extension application could be approved due to medical conditions.
Main Steps:
Log in to your VM and change to your home directory
git clone https://github.com/csenw/cca2.git && cd cca2
Run this command to download the required configuration files and testing webpages.
In this folder (cca2), please write your docker-compose.yml.
Run all the containers: docker-compose up -d
Test the containers on your VM.
Static webpage test: http://external_ip:8080/index.html
Figure 2: A Nginx test page.
http://external_ip:8080/index.php
Figure 3: A PHP-FPM test page. http://external_ip:8080/order.php (test the connection between PHP-FPM and Redis)
Figure 4: A Redis test page. http://external_ip:8080/process.php (test the connection between PHP and MariaDB)
Figure 5: MariaDB test page. phpMyAdmin test: http://external_ip:8082
Figure 6: A phpMyAdmin login page.
The created database “cloud_computing” can be viewed in the sidebar after logging in.
Figure 7: A phpMyAdmin test page.
MariaDB [1] is a community-developed, commercially supported fork of the MySQL relational database management system (RDBMS), intended to remain free and open-source software under the GNU General Public License. Development is led by some of the original developers of MySQL, who forked it due to concerns over its acquisition by Oracle Corporation in 2009. MariaDB intended to maintain high compatibility with MySQL, ensuring a drop-in replacement capability with library binary parity and exact matching with MySQL APIs and commands. However, new features diverge more. It includes new storage engines like Aria, ColumnStore, and MyRocks. You can regard MariaDB as an alternative to MySQL and feel free to interchangeably use these free relational databases in your project.
Redis (Remote Dictionary Server) [2] is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes. The project is mainly developed by and as of 2019 is sponsored by Redis Labs. It is open-source software released under a BSD 3-clause license.
phpMyAdmin [3] is a free and open-source administration tool for MySQL and MariaDB. As a portable web application written primarily in PHP, it has become one of the most popular MySQL administration tools, especially for web hosting services.
For information about Nginx, PHP, and PHP-PFM, please refer to Appendix in Assignment I.
Figure 8. The dependencies among five containers: Nginx + PHP + MariaDB + phpMyAdmin + Redis.
phpMyAdmin
Installation steps on a Linux VM:
§ OS: Ubuntu 18.04,
§ Network: using dynamical IP and Port 8080 § PHP & PHP-FPM version: 7.4
§ MariaDB and Redis version: latest
Step 1. Open a new port 8080
Step 2: Pull required docker images from the docker hub.
docker pull nginx
Pull Nginx image from docker hub.
docker pull php:7.4-fpm
Pull php7.4 and php-fpm from docker hub.
docker pull mariadb:latest
Pull MariaDB from docker hub.
docker pull redis:latest
Pull Redis from docker hub.
docker images
Check pulled images
Step 3: Run four images in dependency order and link them.
docker run \
–name mysql \
-e MYSQL_ROOT_PASSWORD=MyDBRoot123 \ -e MYSQL_DATABASE=cloud_computing \ -e MYSQL_USER=php \
-e MYSQL_PASSWORD=php \
-d mariadb:latest
Run MariaDB image.
docker run –name myredis -d redis:latest
Run Redis image.
sudo service php7.4-fpm stop
[OPTIONAL]: if you have installed php7.4-fpm on your VM, then port 9000 is being taken by PHP- FPM. You can stop the service and make port 9000 available with the above commands.
Run php:7.4-fpm image.
docker run –name myphp -p 9000:9000 -v $HOME/cca2/src:/var/www/html –link
mysql:mysql –link myredis:myredis -d php:7.4-fpm
docker run \
–name mynginx \
-p 8080:80 \
-v $HOME/cca2/src:/var/www/html \
-v $HOME/cca2/src/nginx.ini:/etc/nginx/conf.d/default.conf \ –link myphp:myphp \
-d nginx:latest
Run Nginx image.
Test the static webpage and PHP webpage with the address (your GCP external IP):
§ http://external_ip/index.html § http://external_ip/index.php
All done, you have completed this installation and can run any HTML/PHP pages on your VM.
You should find information about MariaDB (MySQL) and Redis in Environment!
Reference:
[1] MariaDB, https://en.wikipedia.org/wiki/MariaDB
[2] Redis, https://en.wikipedia.org/wiki/PHP
[3] phpMyAdmin, https://en.wikipedia.org/wiki/PhpMyAdmin
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com