Here’s an outline for a project showcasing Azure VM with Azure Storage Account integration. The project demonstrates how to use Azure Storage (Blob or File Share) to store and manage files for an application running on an Azure VM.
- Objective: Deploy an application on Azure VM that uses Azure Storage Account to handle data (e.g., file uploads, backups, or logs).
- Components:
- Azure Virtual Machine (VM)
- Azure Storage Account (Blob Storage or File Share)
- Application accessing the storage
- In the Azure Portal:
- Navigate to Virtual Machines > Create > Azure Virtual Machine.
- Select OS (e.g., Ubuntu 20.04 or Windows Server).
- Configure networking to allow SSH/RDP and HTTP traffic.
- Connect to the VM using SSH or RDP.
- Navigate to Storage Accounts in the Azure Portal.
- Click + Create:
- Select the same region as the VM for lower latency.
- Choose a unique name and storage options (e.g., Standard or Premium).
- Enable Blob Storage and/or File Shares based on your use case:
- Blob Storage: For unstructured data (e.g., images, videos, logs).
- File Share: For shared access to files.
-
Option 1: Azure Blob Storage
- Install the Azure CLI:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
- Authenticate with Azure:
az login
- Create a container:
az storage container create --account-name <storage_account_name> --name <container_name> --auth-mode login
- Upload/download files using Azure CLI:
az storage blob upload --account-name <storage_account_name> --container-name <container_name> --file <local_file_path> --name <blob_name> az storage blob download --account-name <storage_account_name> --container-name <container_name> --name <blob_name> --file <local_file_path>
- Install the Azure CLI:
-
Option 2: Azure File Share
- Create a file share in the storage account.
- Mount the share on the VM:
- For Linux:
sudo apt-get install cifs-utils sudo mount -t cifs //<storage_account_name>.file.core.windows.net/<share_name> /mnt/storage \ -o vers=3.0,username=<storage_account_name>,password=<storage_account_key>,dir_mode=0777,file_mode=0777,sec=ntlmssp
- For Windows:
Use the
net use
command:net use Z: \\<storage_account_name>.file.core.windows.net\<share_name> /user:<storage_account_name> <storage_account_key>
- For Linux:
- Install a web server (e.g., Apache or Nginx).
sudo apt update sudo apt install apache2 -y
- Deploy a sample application that integrates storage (e.g., file upload/download to/from Blob or File Share).
-
Modify the application code to use the Azure SDK for accessing Blob Storage.
pip install azure-storage-blob # For Python
-
Example Code for Blob Upload (Python):
from azure.storage.blob import BlobServiceClient connection_string = "<your_connection_string>" blob_service_client = BlobServiceClient.from_connection_string(connection_string) container_name = "<container_name>" blob_name = "example.txt" file_path = "/path/to/local/example.txt" blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name) with open(file_path, "rb") as data: blob_client.upload_blob(data) print("File uploaded successfully!")
-
- Verify the application is running on the VM using its public IP address.
curl http://<VM_Public_IP>
- Test the storage integration by uploading or retrieving files.
Let me know if you need more specific code examples or deployment guidance!