LAB NO 1: Set up on a local server with , create an admin account, upload files, and configure user permissions for read-only and read-write access. Verify file accessibility by logging in as a different user.
STEPS:
Step 1: Download and Install Apache Web Server via XAMPP and start the server via XAMPP control panel.
Step 2: Create an Admin Account
Open Control Panel > User Accounts > Manage another account.
Click Add a new user in PC settings and follow instruction.
Sign out and log in as adminuser to initialize the account.
Grant Administrator Privileges by changing account type to Administrator.
Step 3: Upload Files to the Server
Locate the Web Root Directory:
The default XAMPP web root is C:\xampp\htdocs. Open File Explorer and navigate to C:\xampp\htdocs.
Create Test Files:
Create a folder named Test_filesforCC:
Create two file fileno1.txt and fileno2.txt
Step 4: Configure User Permissions
Create two users (testUser1 and testUser2):
Go to Control Panel > User Accounts > Manage another account > Add a new user in PC settings.
Add testUser1 and testUser2 as standard users (not administrators).
Navigate to C:\xampp\htdocs\ Test_filesforCCin File Explorer.
Right-click, select Properties > Security > Edit.
Click Add, type readwriteuser, and click Check Names > OK.
Grant readwriteuser Modify permissions (includes read, write, execute).
Ensure adminuser and SYSTEM retain Full control.
Also make the sub directory readOnlyfolder with read only permission.
Step 5: Verify File Accessibility
Test as testUser1 for read/write Permission: Log out and log in as testUser1.
Test as testUser2 for read permission only: Log out and log in as testUser2.
Test as adminuser:
Log out and log in as adminuser.
Test Web Access:
Ensure Apache is running in the XAMPP Control Panel. Open a browser and navigate to: http://localhost/Test_filesforCC/fileno1.txt
http://localhost/Test_filesforCC/readOnlyfolder/fileno1.txt
Conclusion
This setup establishes a local Apache server on Windows using XAMPP, with an admin account, uploaded files, and user permissions for read-only and read-write access.
LAB NO 2: Install on a VM, configure networking, launch a virtual instance, and deploy a static website using . Access the webpage via a browser and confirm its availability.
STEPS:
Download and install Oracle VirtualBox.
Open virtualbox and Create a New VM:
Download and mount the Ubuntu ISO file.
Start the VM and Install Ubuntu:
Select Minimal Installation, enable SSH, and set:
Username: user
Password: password.
Configure Networking
In VirtualBox, go to Settings > Network.
Set Adapter 1 to Bridged Adapter for network access on your local network.
Verify Network Connectivity:
Open a terminal in the VM
ping -c 4 google.com
Deploy a Static Website
Install Apache:
sudo apt update
sudo apt install apache2 -y
Create a simple webpage file :
sudo nano /var/www/html/index.html
Start Apache:
sudo systemctl start apache2 sudo systemctl enable apache2
Access the Website
Find your VM's IP address .
Open a web browser on your host machine.
Type http://<VM_IP> (e.g., http://192.168.1.100).
LAB NO 3: Install , create an with 2GB RAM and 1 CPU, increase RAM to 4GB, and observe performance changes. Then, take a snapshot, modify settings, and restore it to verify functionality.
STEPS:
Download and install Oracle VirtualBox.
Open virtualbox and Create a New VM:
Download and mount the Ubuntu ISO file.
Start the VM and Install Ubuntu:
Select Minimal Installation, enable SSH, and set:
Username: user
Password: password.
Allocate:
Memory (RAM): 2GB (2048MB)
Processor (CPU): 1 CPU Hard disk size: 20GB
Take a Snapshot
Shut down the VM.
In VirtualBox, click Snapshots.
Click Take Snapshot and name it Snapshot_2GBRAM.
Increase RAM to 4GB
Shut down the VM.
In VirtualBox:
Select the VM, click Settings > System > Motherboard. Increase Base Memory to 4GB (4096MB).
Increase CPU to 2
Go to Settings > System > Processor: Increase CPUs to 2.
Final State after changes
Restore the Snapshot
Shut down the VM.
Go to Snapshots in VirtualBox.
Select Snapshot_2GB_RAM and click Restore.
Start the VM to verify it has reverted to 2GB RAM and 1 CPU.
LAB No 4: Simulate MapReduce to count word frequencies from a large text file and display the top 10 words.
Source code:
import re import time import os
file = r"C:\College Doc\Last sem (Lokesh)\cloud computing\Cloud-computing-C5Notes.txt" def count_words_in_chunk(text, word_counts):
"""Processes a text chunk and updates the word count dictionary.""" words = re.findall(r'\w+', text.lower())
for word in words:
word_counts[word] = word_counts.get(word, 0) + 1 def process_file(file):
try:
if not os.path.exists(file):
raise FileNotFoundError(f"File {file} not found.") start = time.time()
chunk_size = 10000 word_counts = {}
with open(file, "r", encoding="utf-8") as f:
while True:
chunk = f.read(chunk_size) if not chunk:
break
count_words_in_chunk(chunk, word_counts)
top_10 = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)[:10] end = time.time()
print(f"Processing Time: {end - start:.4f} seconds") return top_10
except FileNotFoundError as e: print(f"Error: {e}")
return []
except Exception as e:
print(f"Error: {e}") return []
print("Top 10 Words from Cloud-computing-C5Notes:") results = process_file(file)
if results:
for word, count in results: print(f"{word:<20} {count:>10}") print("-" * 40)
else:
print("No results to show.")
Output:
LAB No 5: Use multithreading to calculate the sum of 10 million random numbers and compare it with a single-threaded approach.
Source code:
import random import threading import time
from queue import Queue NUM_COUNT = 10_000_000 NUM_THREADS = 4
print(f"Generating {NUM_COUNT} random numbers...")
nums = [random.randint(1, 100) for _ in range(NUM_COUNT)] # Single-threaded sum
def single_threaded_sum(numbers):
start_time = time.time() total = sum(numbers) end_time = time.time()
return total, end_time - start_time
def part_sum(numbers_part, result_queue): result_queue.put(sum(numbers_part))
# Multithreaded sum
def multithreaded_sum(numbers, num_threads=NUM_THREADS): start_time = time.time()
part_size = len(numbers) // num_threads threads = []
result_queue = Queue()
# Divide the list into parts and create threads for i in range(num_threads):
start_index = i * part_size
end_index = start_index + part_size if i < num_threads - 1 else len(numbers) part = numbers[start_index:end_index]
thread = threading.Thread(target=part_sum, args=(part, result_queue)) threads.append(thread)
thread.start()
for thread in threads:
thread.join()
total = sum(result_queue.get() for _ in range(num_threads)) end_time = time.time()
return total, end_time - start_time # Run single-threaded sum
print("\nRunning single-threaded sum...")
single_total, single_time = single_threaded_sum(nums) print(f"Single-threaded Sum: {single_total}")
# Run multithreaded sum print("\nRunning multithreaded sum...")
multi_total, multi_time = multithreaded_sum(nums)
print(f"Multithreaded Sum: {multi_total}") # Comparison
print("\nComparison of Results:") print(f"{'Approach':<25} {'Time (seconds)':>15}") print(f"{'Single-threaded':<25} {single_time:>10.5f}") print(f"{'Multithreaded':<25} {multi_time:>10.5f}")
speedup = single_time / multi_time if multi_time > 0 else float('inf') print(f"Speedup Factor: {speedup:.2f}x")
Output:
Conclusion: The single-thread method was much faster, finishing the task almost twice as quickly. This shows that the extra work of handling threads was more trouble than the speedup from splitting the task.
LAB NO 6:
Implement basic cloud security measures:
Configure a firewall (UFW/Windows) to control access (e.g., allow SSH on port 22).
Encrypt and decrypt a file using OpenSSL.
Set up an SSH server and test a secure connection.
Configure the firewall with appropriate rules.
Use OpenSSL to encrypt and decrypt a file.
Install and test an SSH server connection.
Task 1: Configure a Firewall Linux (UFW)
Install UFW; sudo apt update
sudo apt install ufw
Enable UFW: sudo ufw enable
Allow SSH (port 22): sudo ufw allow 22/tcp
Check UFW status: sudo ufw status
Configuring Windows Firewall
Open Windows Firewall Settings:Search for "Windows Defender Firewall with Advanced Security" in the Start menu.
Create an Inbound Rule for SSH:
Navigate to Inbound Rules > New Rule.
Select Port and click Next.
Choose TCP, specify port 22, and click Next.
Allow the connection and click Next.
Specify the profiles (Domain, Private, Public) and click Next.
Name the rule (e.g., "Allow SSH") and finish.
Task 2: . Set up an SSH server and test a secure connection.
Install OpenSSL for Windows:
Download OpenSSL installer.
Install it (e.g., to C:\Program Files\OpenSSL-Win64).
Add OpenSSL to the system PATH: Under System Variables, edit Path, add C:\Program Files\OpenSSL-Win64\bin.
Create a Test File:
echo "COUD COMPUTIONG data" > data.txt
Encrypt the File (AES-256-CBC):
openssl enc -aes-256-cbc -salt -in data.txt -out data.txt.enc -k securepassword
Verify Encryption:
type data.txt.enc
Decrypt the File:
openssl enc -aes-256-cbc -d -in data.txt.enc -out decrypted_data.txt -k securepassword
Verify Decryption:
type decrypted_data.txt
Test an SSH Server Connection
Install OpenSSH Server in Powershell:
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' | Add- WindowsCapability -Online
Start and Configure SSH Service: Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
Verify SSH Service: Get-Service sshd
LAB NO: 7
Task 1: Create and Test a Simple RESTful Web Service and explain how this service could be deployed to a cloud platform.
Setting Up the Django Project
Install Django and Django REST Framework: pip install django djangorestframework
Create a Django Project and app
django-admin startproject restful_service python manage.py startapp api
Add Required Apps: INSTALLED_APPS = [
'rest_framework',
'api',
]
Define the REST API
Create a Serializer (api/serializers.py):
Create the API View (api/views.py):
Set Up the URL urlpatterns = [
path('api/', include('api.urls')),
]
Run and Test Locally python manage.py runserver
Deploy to Cloud:
Use platforms like Heroku, AWS Elastic Beanstalk, or Google Cloud Run to host.
Google App Engine:
Package your PHP app with a app.yaml file. Use the Google Cloud SDK to deploy it.
Heroku:
Use a Procfile to specify the web server and deploy it with Git.
AWS Elastic Beanstalk:
Package your app and use the Elastic Beanstalk CLI for deployment.
For Heroku:
Install the Heroku CLI.
Set DEBUG = False in settings.py and add your domain to ALLOWED_HOSTS Initialize a Git repository and deploy:
git init heroku create git add .
git commit -m "Initial commit" git push heroku master
and Access the live API on the Heroku-provided URL
Task 2:create and run a basic web application (HTML + PHP) on your local server and show how this local web app mimics a cloud-hosted service.
Set Up Local Server
Download and Use to run PHP applications locally.
Create a Simple PHP Web Application
Create index.php in the server root directory (htdocs in XAMPP)
Run the Local Server:
Start XAMPP .
Access the app via http://localhost/index.php
This local web app mimics a cloud-hosted service in these ways
Static Content Delivery:
Local servers like Apache deliver static assets (HTML, CSS, JS) to users' browsers. This process replicates how cloud-hosted services or CDNs distribute content globally. Developers can test website layouts, styling, and responsiveness locally before deployment to a live environment.
Like using the browser's developer tools (Network tab) to show how these files are served by the local server, which is like how a CDN or cloud server delivers content.
Here, the Network tab demonstrates how files are served by the local server in real-time. this behavior of serving static and dynamic content mimics cloud services because:
Static content (HTML/CSS) is fetched and rendered.
Dynamic requests (form submission) are processed, and the response is updated.s
Dynamic Content Handling:
PHP scripts on local servers process user inputs (e.g., form submissions), query databases, and dynamically generate HTML responses. This mirrors server-side rendering in the cloud, allowing developers to debug and refine backend logic without incurring hosting costs.
Testing API Endpoints:
Local servers respond to HTTP methods like GET, POST, PUT, and DELETE, allowing developers to test API functionality, handle errors, and ensure integration with frontend applications.