Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

HAProxy EP 9: Load Balancing with Weighted Round Robin

11 September 2024 at 14:39

Load balancing helps distribute client requests across multiple servers to ensure high availability, performance, and reliability. Weighted Round Robin Load Balancing is an extension of the round-robin algorithm, where each server is assigned a weight based on its capacity or performance capabilities. This approach ensures that more powerful servers handle more traffic, resulting in a more efficient distribution of the load.

What is Weighted Round Robin Load Balancing?

Weighted Round Robin Load Balancing assigns a weight to each server. The weight determines how many requests each server should handle relative to the others. Servers with higher weights receive more requests compared to those with lower weights. This method is useful when backend servers have different processing capabilities or resources.

Step-by-Step Implementation with Docker

Step 1: Create Dockerfiles for Each Flask Application

We’ll use the same three Flask applications (app1.py, app2.py, and app3.py) as in previous examples.

  • Flask App 1 (app1.py):

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello from Flask App 1!"

@app.route("/data")
def data():
    return "Data from Flask App 1!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5001)

  • Flask App 2 (app2.py):

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello from Flask App 2!"

@app.route("/data")
def data():
    return "Data from Flask App 2!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5002)

  • Flask App 3 (app3.py):

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello from Flask App 3!"

@app.route("/data")
def data():
    return "Data from Flask App 3!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5003)

Step 2: Create Dockerfiles for Each Flask Application

Create Dockerfiles for each of the Flask applications:

  • Dockerfile for Flask App 1 (Dockerfile.app1):

# Use the official Python image from Docker Hub
FROM python:3.9-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the application file into the container
COPY app1.py .

# Install Flask inside the container
RUN pip install Flask

# Expose the port the app runs on
EXPOSE 5001

# Run the application
CMD ["python", "app1.py"]

  • Dockerfile for Flask App 2 (Dockerfile.app2):

FROM python:3.9-slim
WORKDIR /app
COPY app2.py .
RUN pip install Flask
EXPOSE 5002
CMD ["python", "app2.py"]

  • Dockerfile for Flask App 3 (Dockerfile.app3):

FROM python:3.9-slim
WORKDIR /app
COPY app3.py .
RUN pip install Flask
EXPOSE 5003
CMD ["python", "app3.py"]

Step 3: Create the HAProxy Configuration File

Create an HAProxy configuration file (haproxy.cfg) to implement Weighted Round Robin Load Balancing


global
    log stdout format raw local0
    daemon

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    timeout connect 5000ms
    timeout client  50000ms
    timeout server  50000ms

frontend http_front
    bind *:80
    default_backend servers

backend servers
    balance roundrobin
    server server1 app1:5001 weight 2 check
    server server2 app2:5002 weight 1 check
    server server3 app3:5003 weight 3 check

Explanation:

  • The balance roundrobin directive tells HAProxy to use the Round Robin load balancing algorithm.
  • The weight option for each server specifies the weight associated with each server:
    • server1 (App 1) has a weight of 2.
    • server2 (App 2) has a weight of 1.
    • server3 (App 3) has a weight of 3.
  • Requests will be distributed based on these weights: App 3 will receive the most requests, App 2 the least, and App 1 will be in between.

Step 4: Create a Dockerfile for HAProxy

Create a Dockerfile for HAProxy (Dockerfile.haproxy):


# Use the official HAProxy image from Docker Hub
FROM haproxy:latest

# Copy the custom HAProxy configuration file into the container
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

# Expose the port for HAProxy
EXPOSE 80

Step 5: Create a docker-compose.yml File

To manage all the containers together, create a docker-compose.yml file

version: '3'

services:
  app1:
    build:
      context: .
      dockerfile: Dockerfile.app1
    container_name: flask_app1
    ports:
      - "5001:5001"

  app2:
    build:
      context: .
      dockerfile: Dockerfile.app2
    container_name: flask_app2
    ports:
      - "5002:5002"

  app3:
    build:
      context: .
      dockerfile: Dockerfile.app3
    container_name: flask_app3
    ports:
      - "5003:5003"

  haproxy:
    build:
      context: .
      dockerfile: Dockerfile.haproxy
    container_name: haproxy
    ports:
      - "80:80"
    depends_on:
      - app1
      - app2
      - app3


Explanation:

  • The docker-compose.yml file defines the services (app1, app2, app3, and haproxy) and their respective configurations.
  • HAProxy depends on the three Flask applications to be up and running before it starts.

Step 6: Build and Run the Docker Containers

Run the following command to build and start all the containers


docker-compose up --build

This command builds Docker images for all three Flask apps and HAProxy, then starts them.

Step 7: Test the Load Balancer

Open your browser or use curl to make requests to the HAProxy server


curl http://localhost/
curl http://localhost/data

Observation:

  • With Weighted Round Robin Load Balancing, you should see that requests are distributed according to the weights specified in the HAProxy configuration.
  • For example, App 3 should receive three times more requests than App 2, and App 1 should receive twice as many as App 2.

Conclusion

By implementing Weighted Round Robin Load Balancing with HAProxy, you can distribute traffic more effectively according to the capacity or performance of each backend server. This approach helps optimize resource utilization and ensures a balanced load across servers.

HAProxy Ep 6: Load Balancing With Least Connection

11 September 2024 at 13:32

Load balancing is crucial for distributing incoming network traffic across multiple servers, ensuring optimal resource utilization and improving application performance. One of the simplest and most popular load balancing algorithms is Round Robin. In this blog, we’ll explore how to implement Least Connection load balancing using Flask as our backend application and HAProxy as our load balancer.

What is Least Connection Load Balancing?

Least Connection Load Balancing is a dynamic algorithm that distributes requests to the server with the fewest active connections at any given time. This method ensures that servers with lighter loads receive more requests, preventing any single server from becoming a bottleneck.

Step-by-Step Implementation with Docker

Step 1: Create Dockerfiles for Each Flask Application

We’ll create three separate Dockerfiles, one for each Flask app.

Flask App 1 (app1.py) – Introduced Slowness by adding sleep

from flask import Flask
import time

app = Flask(__name__)

@app.route("/")
def hello():
    time.sleep(5)
    return "Hello from Flask App 1!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5001)


Flask App 2 (app2.py)

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello from Flask App 2!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5002)


Flask App 3 (app3.py) – Introduced Slowness by adding sleep.

from flask import Flask
import time

app = Flask(__name__)

@app.route("/")
def hello():
    time.sleep(5)
    return "Hello from Flask App 3!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5003)

Each Flask app listens on a different port (5001, 5002, 5003).

Step 2: Dockerfiles for each flask application

Dockerfile for Flask App 1 (Dockerfile.app1)

# Use the official Python image from the Docker Hub
FROM python:3.9-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY app1.py .

# Install Flask inside the container
RUN pip install Flask

# Expose the port the app runs on
EXPOSE 5001

# Run the application
CMD ["python", "app1.py"]

Dockerfile for Flask App 2 (Dockerfile.app2)

FROM python:3.9-slim
WORKDIR /app
COPY app2.py .
RUN pip install Flask
EXPOSE 5002
CMD ["python", "app2.py"]

Dockerfile for Flask App 3 (Dockerfile.app3)

FROM python:3.9-slim
WORKDIR /app
COPY app3.py .
RUN pip install Flask
EXPOSE 5003
CMD ["python", "app3.py"]

Step 3: Create a configuration for HAProxy

global
    log stdout format raw local0
    daemon

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    timeout connect 5000ms
    timeout client  50000ms
    timeout server  50000ms

frontend http_front
    bind *:80
    default_backend servers

backend servers
    balance leastconn
    server server1 app1:5001 check
    server server2 app2:5002 check
    server server3 app3:5003 check

Explanation:

  • frontend http_front: Defines the entry point for incoming traffic. It listens on port 80.
  • backend servers: Specifies the servers HAProxy will distribute traffic evenly the three Flask apps (app1, app2, app3). The balance leastconn directive sets the Least Connection for load balancing.
  • server directives: Lists the backend servers with their IP addresses and ports. The check option allows HAProxy to monitor the health of each server.

Step 4: Create a Dockerfile for HAProxy

Create a Dockerfile for HAProxy (Dockerfile.haproxy)

# Use the official HAProxy image from Docker Hub
FROM haproxy:latest

# Copy the custom HAProxy configuration file into the container
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

# Expose the port for HAProxy
EXPOSE 80

Step 5: Create a Dockercompose file

To manage all the containers together, create a docker-compose.yml file

version: '3'

services:
  app1:
    build:
      context: .
      dockerfile: Dockerfile.app1
    container_name: flask_app1
    ports:
      - "5001:5001"

  app2:
    build:
      context: .
      dockerfile: Dockerfile.app2
    container_name: flask_app2
    ports:
      - "5002:5002"

  app3:
    build:
      context: .
      dockerfile: Dockerfile.app3
    container_name: flask_app3
    ports:
      - "5003:5003"

  haproxy:
    build:
      context: .
      dockerfile: Dockerfile.haproxy
    container_name: haproxy
    ports:
      - "80:80"
    depends_on:
      - app1
      - app2
      - app3

Explanation:

  • The docker-compose.yml file defines four services: app1, app2, app3, and haproxy.
  • Each Flask app is built from its respective Dockerfile and runs on its port.
  • HAProxy is configured to wait (depends_on) for all three Flask apps to be up and running.

Step 6: Build and Run the Docker Containers

Run the following commands to build and start all the containers:

# Build and run the containers
docker-compose up --build

This command will build Docker images for all three Flask apps and HAProxy and start them up in the background.

You should see the responses alternating between “Hello from Flask App 1!”, “Hello from Flask App 2!”, and “Hello from Flask App 3!” as HAProxy uses the Round Robin algorithm to distribute requests.

Step 7: Test the Load Balancer

Open your browser or use a tool like curl to make requests to the HAProxy server:

curl http://localhost

You should see responses cycling between “Hello from Flask App 1!”, “Hello from Flask App 2!”, and “Hello from Flask App 3!” according to the Least Connection strategy.

HAProxy EP 1: Traffic Police for Web

9 September 2024 at 16:59

In the world of web applications, imagine you’re running a very popular pizza place. Every evening, customers line up for a delicious slice of pizza. But if your single cashier can’t handle all the orders at once, customers might get frustrated and leave.

What if you could have a system that ensures every customer gets served quickly and efficiently? Enter HAProxy, a tool that helps manage and balance the flow of web traffic so that no single server gets overwhelmed.

Here’s a straightforward guide to understanding HAProxy, installing it, and setting it up to make your web application run smoothly.

What is HAProxy?

HAProxy stands for High Availability Proxy. It’s like a traffic director for your web traffic. It takes incoming requests (like people walking into your pizza place) and decides which server (or pizza station) should handle each request. This way, no single server gets too busy, and everything runs more efficiently.

Why Use HAProxy?

  • Handles More Traffic: Distributes incoming traffic across multiple servers so no single one gets overloaded.
  • Increases Reliability: If one server fails, HAProxy directs traffic to the remaining servers.
  • Improves Performance: Ensures that users get faster responses because the load is spread out.

Installing HAProxy

Here’s how you can install HAProxy on a Linux system:

  1. Open a Terminal: You’ll need to access your command line interface to install HAProxy.
  2. Install HAProxy: Type the following command and hit enter

sudo apt-get update
sudo apt-get install haproxy

3. Check Installation: Once installed, you can verify that HAProxy is running by typing


sudo systemctl status haproxy

This command shows you the current status of HAProxy, ensuring it’s up and running.

Configuring HAProxy

HAProxy’s configuration file is where you set up how it should handle incoming traffic. This file is usually located at /etc/haproxy/haproxy.cfg. Let’s break down the main parts of this configuration file,

1. The global Section

The global section is like setting the rules for the entire pizza place. It defines general settings for HAProxy itself, such as how it should operate, what kind of logging it should use, and what resources it needs. Here’s an example of what you might see in the global section


global
    log /dev/log local0
    log /dev/log local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660
    user haproxy
    group haproxy
    daemon

Let’s break it down line by line:

  • log /dev/log local0: This line tells HAProxy to send log messages to the system log at /dev/log and to use the local0 logging facility. Logs help you keep track of what’s happening with HAProxy.
  • log /dev/log local1 notice: Similar to the previous line, but it uses the local1 logging facility and sets the log level to notice, which is a type of log message indicating important events.
  • chroot /var/lib/haproxy: This line tells HAProxy to run in a restricted area of the file system (/var/lib/haproxy). It’s a security measure to limit access to the rest of the system.
  • stats socket /run/haproxy/admin.sock mode 660: This sets up a special socket (a kind of communication endpoint) for administrative commands. The mode 660 part defines the permissions for this socket, allowing specific users to manage HAProxy.
  • user haproxy: Specifies that HAProxy should run as the user haproxy. Running as a specific user helps with security.
  • group haproxy: Similar to the user directive, this specifies that HAProxy should run under the haproxy group.
  • daemon: This tells HAProxy to run as a background service, rather than tying up a terminal window.

2. The defaults Section

The defaults section sets up default settings for HAProxy’s operation and is like defining standard procedures for the pizza place. It applies default configurations to both the frontend and backend sections unless overridden. Here’s an example of a defaults section


defaults
    log     global
    option  httplog
    option  dontlognull
    timeout connect 5000ms
    timeout client  50000ms
    timeout server  50000ms

Here’s what each line means:

  • log global: Tells HAProxy to use the logging settings defined in the global section for logging.
  • option httplog: Enables HTTP-specific logging. This means HAProxy will log details about HTTP requests and responses, which helps with troubleshooting and monitoring.
  • option dontlognull: Prevents logging of connections that don’t generate any data (null connections). This keeps the logs cleaner and more relevant.
  • timeout connect 5000ms: Sets the maximum time HAProxy will wait when trying to connect to a backend server to 5000 milliseconds (5 seconds). If the connection takes longer, it will be aborted.
  • timeout client 50000ms: Defines the maximum time HAProxy will wait for data from the client to 50000 milliseconds (50 seconds). If the client doesn’t send data within this time, the connection will be closed.
  • timeout server 50000ms: Similar to timeout client, but it sets the maximum time to wait for data from the server to 50000 milliseconds (50 seconds).

3. Frontend Section

The frontend section defines how HAProxy listens for incoming requests. Think of it as the entrance to your pizza place.


frontend http_front
    bind *:80
    default_backend http_back
  • frontend http_front: This is a name for your frontend configuration.
  • bind *:80: Tells HAProxy to listen for traffic on port 80 (the standard port for web traffic).
  • default_backend http_back: Specifies where the traffic should be sent (to the backend section).

4. Backend Section

The backend section describes where the traffic should be directed. Think of it as the different pizza stations where orders are processed.


backend http_back
    balance roundrobin
    server app1 192.168.1.2:5000 check
    server app2 192.168.1.3:5000 check
    server app3 192.168.1.4:5000 check
  • backend http_back: This is a name for your backend configuration.
  • balance roundrobin: Distributes traffic evenly across servers.
  • server app1 192.168.1.2:5000 check: Specifies a server (app1) at IP address 192.168.1.2 on port 5000. The check option ensures HAProxy checks if the server is healthy before sending traffic to it.
  • server app2 and server app3: Additional servers to handle traffic.

Testing Your Configuration

After setting up your configuration, you’ll need to restart HAProxy to apply the changes:


sudo systemctl restart haproxy

To check if everything is working, you can use a web browser or a tool like curl to send requests to HAProxy and see if it correctly distributes them across your servers.

The Search for the Perfect Media Server: A Journey of Discovery

2 September 2024 at 04:11

Dinesh, an avid movie collector and music lover, had a growing problem. His laptop was bursting at the seams with countless movies, albums, and family photos. Every time he wanted to watch a movie or listen to her carefully curated playlists, he had to sit around his laptop. And if he wanted to share something with his friends, it meant copying with USB drives or spending hours transferring files.

One Saturday evening, after yet another struggle to connect his laptop to his smart TV via a mess of cables, Dinesh decided it was time for a change. He needed a solution that would let his access all his media from any device in his house – phone, tablet, and TV. He needed a media server.

Dinesh fired up his browser and began his search: “How to stream media to all my devices.” He gone through the results – Plex, Jellyfin, Emby… Each option seemed promising but felt too complex, requiring subscriptions or heavy installations.

Frustrated, Dinesh thought, “There must be something simpler. I don’t need all the bells and whistles; I just want to access my files from anywhere in my house.” He refined her search: “lightweight media server for Linux.”

There it was – MiniDLNA. Described as a simple, lightweight DLNA server that was easy to set up and perfect for home use, MiniDLNA (also known as ReadyMedia) seemed to be exactly what Dinesh needed.

MiniDLNA (also known as ReadyMedia) is a lightweight, simple server for streaming media (like videos, music, and pictures) to devices on your network. It is compatible with various DLNA/UPnP (Digital Living Network Alliance/Universal Plug and Play) devices such as smart TVs, media players, gaming consoles, etc.

How to Use MiniDLNA

Here’s a step-by-step guide to setting up and using MiniDLNA on a Linux based system.

1. Install MiniDLNA

To get started, you need to install MiniDLNA. The installation steps can vary slightly depending on your operating system.

For Debian/Ubuntu-based systems:

sudo apt update
sudo apt install minidlna

For Red Hat/CentOS-based systems:

First, enable the EPEL repository,

sudo yum install epel-release

Then, install MiniDLNA,

sudo yum install minidlna

2. Configure MiniDLNA

Once installed, you need to configure MiniDLNA to tell it where to find your media files.

a. Open the MiniDLNA configuration file in a text editor

sudo nano /etc/minidlna.conf

b. Configure the following parameters:

  • media_dir: Set this to the directories where your media files (music, pictures, and videos) are stored. You can specify different media types for each directory.
media_dir=A,/path/to/music  # 'A' is for audio
media_dir=V,/path/to/videos # 'V' is for video
media_dir=P,/path/to/photos # 'P' is for pictures
  • db_dir=: The directory where the database and cache files are stored.
db_dir=/var/cache/minidlna
  • log_dir=: The directory where log files are stored.
log_dir=/var/log/minidlna
  • friendly_name=: The name of your media server. This will appear on your DLNA devices.
friendly_name=Laptop SJ
  • notify_interval=: The interval in seconds that MiniDLNA will notify clients of its presence. The default is 900 (15 minutes).
notify_interval=900

c. Save and close the file (Ctrl + X, Y, Enter in Nano).

3. Start the MiniDLNA Service

After configuration, start the MiniDLNA service

sudo systemctl start minidlna

To enable it to start at boot,

sudo systemctl enable minidlna

4. Rescan Media Files

To make MiniDLNA scan your media files and add them to its database, you can force a rescan with

sudo minidlnad -R

5. Access Your Media on DLNA/UPnP Devices

Now, your MiniDLNA server should be up and running. You can access your media from any DLNA-compliant device on your network:

  • On your Smart TV, look for the “Media Server” or “DLNA” option in the input/source menu.
  • On a Windows PC, go to This PC or Network and find your DLNA server under “Media Devices.”
  • On Android, use a media player app like VLC or BubbleUPnP to find your server.

6. Check Logs and Troubleshoot

If you encounter any issues, you can check the logs for more information

sudo tail -f /var/log/minidlna/minidlna.log

To setup for a single user

Disable the global daemon

sudo service minidlna stop
sudo update-rc.d minidlna disable

Create the necessary local files and directories as regular user and edit the configuration

mkdir -p ~/.minidlna/cache
cd ~/.minidlna
cp /etc/minidlna.conf .
$EDITOR minidlna.conf

Configure as you would globally above but these definitions need to be defined locally

db_dir=/home/$USER/.minidlna/cache
log_dir=/home/$USER/.minidlna 

To start the daemon locally

minidlnad -f /home/$USER/.minidlna/minidlna.conf -P /home/$USER/.minidlna/minidlna.pid

To stop the local daemon

xargs kill </home/$USER/.minidlna/minidlna.pid

To rebuild the database,

minidlnad -f /home/$USER/.minidlna/minidlna.conf -R

For more info: https://help.ubuntu.com/community/MiniDLNA

Additional Tips

  • Firewall Rules: Ensure that your firewall settings allow traffic on the MiniDLNA port (8200 by default) and UPnP (typically port 1900 for UDP).
  • Update Media Files: Whenever you add or remove files from your media directory, run minidlnad -R to update the database.
  • Multiple Media Directories: You can have multiple media_dir lines in your configuration if your media is spread across different folders.

To set up MiniDLNA with VLC Media Player so you can stream content from your MiniDLNA server, follow these steps:

Let’s see how to use this in VLC

On Machine

1. Install VLC Media Player

Make sure you have VLC Media Player installed on your device. If not, you can download it from the official VLC website.

2. Open VLC Media Player

Launch VLC Media Player on your computer.

3. Open the UPnP/DLNA Network Stream

  1. Go to the “View” Menu:
    • On the VLC menu bar, click on View and then Playlist or press Ctrl + L (Windows/Linux) or Cmd + Shift + P (Mac).
  2. Locate Your DLNA Server:
    • In the left sidebar, you will see an option for Local Network.
    • Click on Universal Plug'n'Play or UPnP.
    • VLC will search for available DLNA/UPnP servers on your network.
  3. Select Your MiniDLNA Server:
    • After a few moments, your MiniDLNA server should appear under the UPnP section.
    • Click on your server name (e.g., My DLNA Server).
  4. Browse and Play Media:
    • You will see the folders you configured (e.g., Music, Videos, Pictures).
    • Navigate through the folders and double-click on a media file to start streaming.

4. Alternative Method: Open Network Stream

If you know the IP address of your MiniDLNA server, you can connect directly:

  1. Open Network Stream:
    • Click on Media in the menu bar and select Open Network Stream... or press Ctrl + N (Windows/Linux) or Cmd + N (Mac).
  2. Enter the URL:
    • Enter the URL of your MiniDLNA server in the format http://[Server IP]:8200.
    • Example: http://192.168.1.100:8200.
  3. Click “Play”:
    • Click on the Play button to start streaming from your MiniDLNA server.

5. Tips for Better Streaming Experience

  • Ensure the Server is Running: Make sure the MiniDLNA server is running and the media files are correctly indexed.
  • Network Stability: A stable local network connection is necessary for smooth streaming. Use a wired connection if possible or ensure a strong Wi-Fi signal.
  • Firewall Settings: Ensure that the firewall on your server allows traffic on port 8200 (or the port specified in your MiniDLNA configuration).

On Android

To set up and stream content from MiniDLNA using an Android app, you will need a DLNA/UPnP client app that can discover and stream media from DLNA servers. Several apps are available for this purpose, such as VLC for Android, BubbleUPnP, Kodi, and others. Here’s how to use VLC for Android and BubbleUPnP, two popular choices

Using VLC for Android

  1. Install VLC for Android:
  2. Open VLC for Android:
    • Launch the VLC app on your Android device.
  3. Access the Local Network:
    • Tap on the menu button (three horizontal lines) in the upper-left corner of the screen.
    • Select Local Network from the sidebar menu.
  4. Find Your MiniDLNA Server:
    • VLC will automatically search for DLNA/UPnP servers on your local network. After a few moments, your MiniDLNA server should appear in the list.
    • Tap on the name of your MiniDLNA server (e.g., My DLNA Server).
  5. Browse and Play Media:
    • You will see your media folders (e.g., Music, Videos, Pictures) as configured in your MiniDLNA setup.
    • Navigate to the desired folder and tap on any media file to start streaming.

Additional Tips

  • Ensure MiniDLNA is Running: Make sure your MiniDLNA server is properly configured and running on your local network.
  • Check Network Connection: Ensure your Android device is connected to the same local network (Wi-Fi) as the MiniDLNA server.
  • Firewall Settings: If you are not seeing the MiniDLNA server in your app, ensure that the server’s firewall settings allow DLNA/UPnP traffic.

Some Problems That you may face

  1. minidlna.service: Main process exited, code=exited, status=255/EXCEPTION - check the logs. Mostly its due to an instance already running on port 8200. Kill that and reload the db. lsof -i :8200 will give PID. and `kill -9 <PID>` will kill the process.
  2. If the media files is not refreshing, then try minidlnad -f /home/$USER/.minidlna/minidlna.conf -R or `sudo minidlnad -R`

Docker Ep 3 : Virtual Machines VS Containers

12 August 2024 at 08:40
SNo.Virtual Machines(VM)Containers
1VM is a piece of software that allows you to install other software inside of it so you control it virtually as opposed to installing the software directly on the computer.While a container is software that allows different functionalities of an application independently.
2.Applications running on a VM system, or hypervisor, can run different OS.While applications running in a container environment share a single OS.
3.VM virtualizes the computer system, meaning its hardware.While containers virtualize the operating system, or the software only.
4.VM size is very large, generally in gigabytes.While the size of the container is very light, generally a few hundred megabytes, though it may vary as per use.
5.VM takes longer to run than containers, the exact time depending on the underlying hardware.While containers take far less time to run.
6.VM uses a lot of system memory.While containers require very less memory.
7.VM is more secure, as the underlying hardware isn’t shared between processes.While containers are less secure, as the virtualization is software-based, and memory is shared.
8.VMs are useful when we require all of the OS resources to run various applications.While containers are useful when we are required to maximize the running applications using minimal servers.
9.Examples of Type 1 hypervisors are KVM, Xen, and VMware. Virtualbox is a Type 2 hypervisorExamples of containers are RancherOS, PhotonOS, and Containers by Docker.

Interface types in Java

12 August 2024 at 02:49
java programming language an interface is a reference type, similar to a class, that can contain only constants, method declaration(method signature, nobody), default methods, static methods and nested types inside its body. Nested type simply means it can contain another interface or class inside it. variables declared in an interface are public, static & final […]

Python - Fundamentals

By: ABYS
16 July 2024 at 14:00

In here, I'm gonna tell you how to use variables in python. We shall see how to name a variable and assign values to them.

How to name a Variable ?

Firstly a variable is nothing but a reference to an object or value throughout the program. They act as reference to a memory where the value is stored.

There are certain rules to name them.

  • Must begin with a letter (a-z, A-Z) or an underscore (_).
  • After the first character, letters, digits (0-9), or underscores can be followed.
  • Variable names are case-sensitive. For ex, myName and myname are entirely different variables.
  • Should not use Python reserved words as variable names For ex: class, def, for, while.

So, in python the operator = is used for assigning values to variables.

# Assigning integer value
age = 18
print(age)

18

# Assigning string value
name = "Arif"
print(name)

Arif

# Assigning float value (float means decimal value)
height = 2.5
print(height)

2.5

# Assigning boolean value (rfrs to true/false)
is_student = True
print(is_student)

True

Varible Types

Python is a typed lang, we needn't declare the type of a variable when assigning a value to it. The type is inferred by its own.

name = "Abys"
print(name)
print(type(name))

Abys
<class 'str'>

or we can also define the type by,

name = "Abys"
type(name)

str

age = 18
type(age)

int

That's the basic.

I've been asked to complete some questions on my own, lemme discuss those with you guys.
It's much easier to learn right...?

1. Create a variable named name and assign your name to it. Then print the value of the variable.

name = "Abys"
print(name)
print(type(name))

Abys
<class 'str'>

2. Create a variable age and assign your age to it. Later, reassign the variable with a new value and print the new value.

age=17
print("Present age:",age)
age= 18
print(age)

Present age: 17
18

and here if we want the type;

print(type(age))
<class 'int'>

3. Assign the values 5, 10, and 15 to three variables a, b, and c in a single line. Print their values.

a,b,c = 5,10,15
print(a,b,c)

5 10 15

if we wanna add them we get,

print(a+b+c)

30

4. Swap the values of two variables x and y without using a third variable. Print their values before and after swapping.

x,y = 5,25
print(x,y)
print(x-y)
x,y = 25,5
print(x,y)
print(x-y)

5 25
-20
25 5
20

they've asked just to print the swapped values, it's me who did extra stuffs.

Before the next qn we ought to know what is constants...

What are Constants ?

In Python, constants are those values that are not meant to change. By convention, they are typically written in capital letters with underscores separating the words.
However, in python constants can also be changed.

5. Define constants PI with appropriate values and print them.

PI=3.14159
print(f"{PI:.3f}")

3.142

6. Write a program that calculates the area of a circle using the constant PI and a variable radius. Print the area.

PI=3.14
radius=7
r=radius
area=PI*r**2 # r**2 refers to r pow 2
print("Area of circle is",area)

Area of circle is 153.86

7. Define constants for the length and width of a rectangle. Calculate and print the area.

L,B = 5,15
area = L*B
print("Area of rect is ",area)

Area of rect is  75

These were the qns I worked on. Hope it is clear.
Sorry, if I'm ain't clear enough.., as I've just started blogging I may make mistakes.
Definitely will improve myself.
Thank you, All...

Working with Tamil Content in Computing Environments (27 July 2024)

27 July 2024 at 04:33

https://tamil.digital.utsc.utoronto.ca/working-with-tamil-content-in-computing-environments-27-july-2024

Unicode is an international standard extensively adopted across the industry and the Internet to represent Tamil and other languages.  Yet, we still face several legacy issues and ongoing challenges. 

The content from government documents cannot be easily extracted. The conversion of documents from one font to another presents problems due to inconsistencies. There exist various, slightly different standards for phonetic transcription of Tamil into latin scripts.  There are varied keyboard layouts and input styles for desktop and mobile.

Researchers, developers and practitioners continue to evolve solutions to overcome these challenges. The presentations and discussions will identify needs, issues and solutions for working with Tamil content in varied computing environments.

Please fill this anonymous survey related to using Tamil in computers and smartphones.

Presentation Topics 

  • Introduction to Unicode – Elango
  • Using Tamil Keyboards on Computer and Mobile Platforms – Suganthan
  • Android’s New Faster and More Intuitive Method to Type Tamil – Elango
  • Working with Tamil Content in PDFs – Shrinivasan
  • Tamil Font Styles – Uthayan
  • Challenges in Automatic Tamil Font Conversions – Parathan
  • Transliteration Approaches for Library Metadata Generation – Natkeeran

Date

July 27, 2024 (Saturday) – Virtual Presentations and Discussion

9:30 am – 11:30 am (Toronto time)
7 pm – 9 pm (Chennai/Jaffna time)

Zoom
https://utoronto.zoom.us/j/87507821579

Contributors

  • UTSC Library Digital Tamil Studies
  • Kaniyam Foundation
  • Tamil Kanimai Maiyam (தகமை)
  • South Asian Canadian Digital Archive (SACDA)

Working with Tamil Content in Computing Environments (27 July 2024)

27 July 2024 at 04:33

https://tamil.digital.utsc.utoronto.ca/working-with-tamil-content-in-computing-environments-27-july-2024

Unicode is an international standard extensively adopted across the industry and the Internet to represent Tamil and other languages.  Yet, we still face several legacy issues and ongoing challenges. 

The content from government documents cannot be easily extracted. The conversion of documents from one font to another presents problems due to inconsistencies. There exist various, slightly different standards for phonetic transcription of Tamil into latin scripts.  There are varied keyboard layouts and input styles for desktop and mobile.

Researchers, developers and practitioners continue to evolve solutions to overcome these challenges. The presentations and discussions will identify needs, issues and solutions for working with Tamil content in varied computing environments.

Please fill this anonymous survey related to using Tamil in computers and smartphones.

Presentation Topics 

  • Introduction to Unicode – Elango
  • Using Tamil Keyboards on Computer and Mobile Platforms – Suganthan
  • Android’s New Faster and More Intuitive Method to Type Tamil – Elango
  • Working with Tamil Content in PDFs – Shrinivasan
  • Tamil Font Styles – Uthayan
  • Challenges in Automatic Tamil Font Conversions – Parathan
  • Transliteration Approaches for Library Metadata Generation – Natkeeran

Date

July 27, 2024 (Saturday) – Virtual Presentations and Discussion

9:30 am – 11:30 am (Toronto time)
7 pm – 9 pm (Chennai/Jaffna time)

Zoom
https://utoronto.zoom.us/j/87507821579

Contributors

  • UTSC Library Digital Tamil Studies
  • Kaniyam Foundation
  • Tamil Kanimai Maiyam (தகமை)
  • South Asian Canadian Digital Archive (SACDA)

Python - First Week

By: Suresh S
11 July 2024 at 21:23

Python is taught online in Tamil without any cost. The only expectation from them is to create a blog and write our understanding after learning. Hence started writing the blog.

  • Started Learning python through Kaniyam. Got to know about two Tamil people Syed and Srini. Classes will be for Monday to Wednesday at 7pm to 8pm

  • WhatsApp group was created and 3 classes completed. Agenda for every class is clear. During the class Zoom Recording and YouTube Live both were made which is useful for Checking it again.

https://kaniyam.com/python-course-2024/
https://parottasalna.com/python-development/

I have already installed Python and VS code available in my laptop. Find little difficult to understand running the sample program via Terminal and from Vscode. After few tries it is little clear now. So environment is made available for the class.

Lot of free ebooks are available to learn python other than youtube videos. Recommended book links are as below

Day 1: Meet and Greet:

Agenda:

  1. Why Python ?
  2. Course Syllabus
  3. Python Installation - Windows, Linux
  4. Collab Notebook
  5. Where to see updates & recordings.
  6. Where to ask questions ?
  7. Our Expectations
  8. Basic Print Command
  9. About FOSS, FOSS Communities.

Post session, the below information is shared

Youtube Recording:
Part 1: https://www.youtube.com/live/rcJRkt3odlw?si=SZGCr6aBVwSQII0g
Part 2: https://www.youtube.com/live/xBpXOkyoFD8?si=Z89W5VAtLnkUpFHH

How to create a blog:
https://www.youtube.com/watch?v=pkp8WK9ub4o

Google Form to submit your blog url:
https://docs.google.com/forms/d/e/1FAIpQLSdiJ3qQ-37YSi2VnTFpgVIJL0iE9mxveKHA3kFnwVAmhJooMg/viewform?usp=sf_link

Whatsapp Group Links:
Group 1: https://chat.whatsapp.com/DcfvtLP0y6S0iUkjCJLcH7
Group 2: https://chat.whatsapp.com/ErBIxb1lQfs7mNRo33c4Vc
Group 3: https://chat.whatsapp.com/ETxQ9WVCXkp5TYmY22wLaC

Tamil Linux Forum Link: (Ask Your Queries here)
https://forums.tamillinuxcommunity.org/

Community Links
https://forums.tamillinuxcommunity.org/t/gather-all-the-foss-group-in-tamil-nadu/1387

Python Download Link:
https://www.python.org/downloads/
Google Colab Link:
https://colab.research.google.com/

Day 2: Python Print

Agenda:

  1. 10 min discussion on previous class
  2. Basic print statement
  3. Multiple prints
  4. separator
  5. concatenating strings
  6. escape sequences
  7. raw string
  8. printing quotes inside strings.
  9. printing numbers
  10. multiline strings
  11. string multiplication
  12. combining int and str in printing
  13. .format
  14. f-strings

Concepts are understood. Important links are

Youtube Recording:
Session: https://www.youtube.com/watch?v=zr3skBHzbAI&list=PLiutOxBS1Mizte0ehfMrRKHSIQcCImwHL&index=4&pp=gAQBiAQB
Q/A: https://www.youtube.com/watch?v=OWjW7GBMND4&list=PLiutOxBS1Mizte0ehfMrRKHSIQcCImwHL&index=5&pp=gAQBiAQB
Blog: https://parottasalna.com/2024/07/05/python-fundamentals-the-print/
Quiz: https://docs.google.com/forms/d/e/1FAIpQLSeW7dGCYrvPXBK7llexbwa_yImFQWFiHHE4c4ATOk-NwJWxIw/viewform?usp=sf_link
Task: https://parottasalna.com/2024/07/04/task-1-python-print-exercises/
Playlist: https://www.youtube.com/playlist?list=PLiutOxBS1Mizte0ehfMrRKHSIQcCImwHL
Colab Notebook: https://colab.research.google.com/drive/1Uu9btRd_U0i3-PRfZwlR2QalJRp0DbBK?usp=sharing
Infographics: https://parottasalna.com/wp-content/uploads/2024/07/print-method.pdf

Byte of Python book is recommended. The link is'''

https://python.swaroopch.com/
https://www.tutorialspoint.com/python/index.htm
https://python.swaroopch.com/
https://pymbook.readthedocs.io/

'''

Day 3: Data types Variables and constants
Agenda:

  1. Discussion on print quiz.
  2. Numeric Types (int, float, complex)
  3. Text Type (strings)
  4. Boolean Type (bool)
  5. None Type (None)
  6. How to check a data type ?
  7. What is a variable ?
  8. How to define it
  9. valid, invalid variables
  10. assigning values
  11. multiple assignment
  12. unpacking
  13. variable types
  14. Constants

Details shared
Print Quiz Solutions Video: https://youtu.be/JzFLSZySbRI
Print Task Solutions: https://youtu.be/k6pwbOZtQ30

Variables Datatypes & Constants:
Session: https://youtube.com/live/5G0PoJofxXk?feature=share
Q/A: https://youtube.com/live/9cJDqHwQG5k?feature=share
Blog: https://parottasalna.com/2024/07/07/python-fundamentals-constants-variables-and-data-types/
Quiz: https://docs.google.com/forms/d/e/1FAIpQLSezKyjHkKlg4Qo8juWqviZkasyWOcAcEcBzK_NsBwGYG3WAvg/viewform?usp=sf_link
Task: https://parottasalna.com/2024/07/07/task-2-constants-and-variables/
Playlist: https://www.youtube.com/playlist?list=PLiutOxBS1Mizte0ehfMrRKHSIQcCImwHL
Infographics: https://parottasalna.com/wp-content/uploads/2024/07/variables-constants-and-data-types-in-python.pdf

There was a Q&A session planned by Srini and Syed today as there are many participants(11.07.2024 - Thursday)

I told them that I will create a blog this weekend. Srini objected and said that postponing the activity will keep that delayed. Hence today I started writing my first blog.

For teaching Kids, below websites can be checked

Other important links:

I have asked two questions today.

  1. Website link to teach kids?
  2. To know in detail about print function(like hovering over VSCODE on print provides detail) what I have to do?
  3. For the above I have to add some addons. those are Python and Pylance
  4. During the conversation Pandas also came which is a library for Excel data processing.

Also there was some interesting questions came about AI training using Python. It seems like with the available data, next prediction will happen like Regression LinearGraph.To know more about AI, We need to study the Book from Kaniyam

AI Libraries

  • Scifikit
  • Tensorflow
  • pytorch

To do:

  1. Go through the link or search on adding python, Pylance library to VScode
  2. Explore Pandas with the Ebook
  3. Read Byte of python till date

Python_In_Tamil-001

8 July 2024 at 17:06

Dear All,
I am Govindarajan from Thanjavur. I teach Basic Python through OnLine. I am a PCEP and PCAP.
Ok, let us start learning Basic Python.

  1. Install python from python.org as per your computer system.

  2. In windows, in the search bar, type cmd, cmd page will get opened. Write python at the cursor location and press Enter. If you see Python with the version number of the python, then it is confirmed that python is installed in your system. If not, go to the point number 1 above.

  3. Then, in the search bar, type IDLE. Click on IDLE with right side mouse and click Run as administrator. you will see a new window titled as IDLE Shell python version number. This window is called as Shell window or Console window.

  4. In the shell window, click File => New File. Another window with a title as untitled will open. This window is called as Editor window. we will write all our codes/program in this Editor window. It will be saved as python file(.py extension).

  5. Type ('Hello World') with a file name as BP001, save it(Ctrl + s), click Run, click Run Module F5 (or Fn + F5), the code will get executed and you will see Hello World in your Shell Window.

  6. Great !!!. You have successfully completed your first program in Python. Congratulations.

Let us meet tomorrow in 'Python_In_Tamil-002'.

Thanks and Regards.
Govi.
https://www.youtube.com/@Python_In_Tamil

How to create AWS EC2 instance using Terraform

7 January 2024 at 06:36

create directory ec2 and navigate to the directory
$ mkdir ec2 && cd ec2
create main.tf file
$ vim main.tf

provider "aws" {
region = "ap-south-1"
}

resource "aws_instance" "app_server" {
ami = "ami-03f4878755434977f"
instance_type = "t2.nano"
subnet_id = "subnet-0ccba3b8cfd0645e2"
key_name = "awskey"
associate_public_ip_address = "true"
tags = {
Name = "demo-server"
}
}

output "public_ip" {
description = "public ip of the instance"
value = aws_instance.app_server.public_ip
}

save and exit
initialize the terraform
$ terraform init
$ terraform plan
$ terraform apply -auto-approve
it will create the AWS EC2 instance with output the public ip of the instance

To destroy the instance
$ terraform destroy -auto-approve

How to install Terraform in Ubuntu

7 January 2024 at 06:16

Method1: Package manager
$ wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg –dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
$ echo “deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main” | sudo tee /etc/apt/sources.list.d/hashicorp.list
$ sudo apt update && sudo apt install terraform
$ terraform version
To get help options
$ terraform -h

Method2: Binary download
download the binary from wget https://developer.hashicorp.com/terraform/downloads
$ wget https://releases.hashicorp.com/terraform/1.6.6/terraform_1.6.6_linux_amd64.zip

extract using unzip
$ unzip terraform_1.6.6_linux_amd64.zip
$ mv terraform /usr/local/bin/
$ terraform version
$ terraform -h

To remove terraform binary method
$ sudo rm -f /usr/local/bin/terraform

To remove terraform package manager method
$ sudo apt remove terraform --purge

AWS-VPC (Peering Connections)

By: Kannan
26 December 2023 at 17:46

A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them using private IPv4 addresses or IPv6 addresses. Instances in either VPC can communicate with each other as if they are within the same network.

  • VPC peering connections are limited on the number of active and pending peering connections that you can have per VPC.

  • VPC peering is a technique for securely connecting two or more virtual private clouds, or VPCs

Image description

Step-1. As per the above VPC Peering connection architect Create a VPC and subnet and Rout table.

Image description

Image description

Image description

  • Associate the subnet with the route table.

Image description

Step-2. Create the Internet Gateway and attach the VPC.

Image description

  • Edit and add the Internet Gateway in the route table.

Image description

Step-3. Create the EC2 Instance with VPC-A network settings and Publich IP enabled on the Subnet and Instance.

Image description

Step-4. As the above steps we have created another VPC, Subnet and Route table.

Image description

Image description

Image description

  • Associate the Subnet on the route table and create EC2 Instance.

Image description

Image description

Step-5. We need to copy the .pem key from local and paste in the Primary VPC-A to get SSH access for another VPC-B.

  • Not getting connect to the secondary VPC EC 2 Instance via SSH.

**Step-6. **Create a peering connection.

Image description

  • Accept the Peer Request.

Image description

Step-7. Add the Secondary IPV4 CIDR range and select the peering connection and save on the Primary Route table.

Image description
Step-8. Add the Primary IPV4 CIDR range and select the peering connection and save on the Secondary Route table.

Image description

Step-9. Now we able to access the Secondary VPC EC2 Instance through the Primary VPC EC2 Instance via Peering connection.

AWS-Virtual Private Cloud VPC(Subnet,Route table,Internet Gateway,NAT gateway)

By: Kannan
26 December 2023 at 15:22

A virtual private cloud (VPC) is a virtual network dedicated to your AWS account. It is logically isolated from other virtual networks in the AWS Cloud. You can specify an IP address range for the VPC, add subnets, add gateways, and associate security groups.

  • users can avoid underutilizing their resources during periods of low demand or overloading their infrastructure during peak periods. Overall, the advantages of using VPC for your infrastructure include improved security, greater flexibility, and scalability.

  • We are going to create a VPC on particular availability zone and differentiate with Public and private subnet/Route table as mentioned in the architect diagram.

Image description

Step-1. Create a VPC with tag of VPC-A

  • Select and make range for IPV4 CIDR, select the No IPV6 CIDR Block.

Image description

Step-2. Create a Subnet with the VPC ID we created.

  • verify the availability zone and IPV4 VPC CIDR and provide the range of subnet on IPV4 subnet CIDR to create the subnet.

Image description

Step-3.Create a Route table

  • select the VPC and create the route table
    Image description

  • Once route table created associate the subnet with the table. and enable the "Auto assign public IP"

Image description

Image description

Step-4. Create an Internet gateway and attach it with the VPC which we created.

Image description

Image description

  • Add the Internet gateway on the route table.

Image description

Image description

Step-5. Create an EC2 instance

  • On Network settings select the VPC,subnet,and public IP enable.

Image description

  • we are able to access the EC2 instance using public IP via SSH.

Step-6. Now we need to create the private subnet and route table, associate the private subnet on the route table.

Image description

Image description

Image description

Step-7. Create an EC2 instance

  • On Network settings select the VPC,private subnet.

Image description

  • Login to the Public VPC Instance and copy the .pem key from the local to get SSH access for the private instance.

  • We are able to login public Instance and get connected to Private Instance via Local gateway.

  • If we need to access internet on private instance to install any application need to create the NAT gateway.

Step-8.Create a NAT Gateway

  • select the public instance subnet range and allocate the "Elastic IP".

Image description

Step-9. Add the NAT gateway on the private Route table to get internet access on the private Instance.

Image description

Image description

  • We are successfully login to the public instance via SSH and from the public-EC2 we are able to login to private and access the internet.
kannan@kannan-PC:~$ ssh -i apache.pem ubuntu@13.201.97.155
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-1017-aws x86_64)

ubuntu@ip-192-168-1-99:~$ ssh -i apache.pem ubuntu@192.168.2.221
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-1017-aws x86_64)


ubuntu@ip-192-168-2-221:~$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=50 time=1.90 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=50 time=1.55 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=50 time=1.56 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.546/1.671/1.904/0.164 ms
ubuntu@ip-192-168-2-221:~$ ping www.google.com
PING www.google.com (142.251.42.4) 56(84) bytes of data.
64 bytes from bom12s19-in-f4.1e100.net (142.251.42.4): icmp_seq=1 ttl=109 time=1.79 ms
64 bytes from bom12s19-in-f4.1e100.net (142.251.42.4): icmp_seq=2 ttl=109 time=1.58 ms

❌
❌