Setting Up Your DevOps Environment with Python, Django, and More

Jul 4, 2024 | Programming

In today’s fast-paced technological landscape, having a robust DevOps environment is essential for effective project delivery and collaboration. This guide walks you through the installation and configuration of a DevOps stack using Python 3.9.13, Django 2.2.16, Channels 2.4.0, Celery 5.2.7, and Ansible 2.9.14, along with Kubernetes and Docker, to facilitate smooth application deployments.

Prerequisites

  • Ensure you have CentOS 7.5 installed.
  • Install Python 3.9.13 and necessary dependencies.
  • Have Docker and Kubernetes set up on your system.

Step-by-Step Configuration

Let’s break down the different components needed for your DevOps environment.

1. Install Required Packages

Start by installing essential packages and dependencies using the following bash commands:

bash
yum install -y epel-release
yum install -y gcc sshpass python3-devel mysql-devel

2. Set Up MySQL Database

To create a database for your application, run:

bash
docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql:5.7.31
docker exec -it mysql bin/bash
mysql -uroot -p
CREATE DATABASE devops DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON devops.* TO 'devops'@'%' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;

3. Deploy Redis

Redis will be used for Celery session management. Deploy Redis using:

bash
docker run --name redis-server -p 6379:6379 -d redis:6.0.8

4. Configure Django Settings

In the devopssettings.py, configure your database settings as follows:

python
DATABASES = {
    'default': {
        'ENGINE': 'db_pool.mysql',
        'NAME': 'devops',
        'USER': 'devops',
        'PASSWORD': 'devops',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'OPTIONS': {
            'init_command': 'SET sql_mode=STRICT_TRANS_TABLES',
        }
    }
}

5. Migrations and Data Loading

Run the following commands to set up your application:

bash
sh delete_makemigrations.sh
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py loaddata initial_data.json

6. Start Celery and Daphne Workers

Use the following commands to start your Celery and Daphne workers:

bash
nohup celery -A devops worker -l info &
nohup daphne -b 0.0.0.0 -p 8001 --access-log=logsdaphne_access.log devops.asgi:application &

Troubleshooting

  • Make sure all Docker containers are running by checking with docker ps.
  • If you encounter database connection issues, ensure the credentials in devopssettings.py are correct.
  • For Redis or Celery related issues, verify that the respective services are up and configured properly.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

You now have a functional DevOps environment using Python, Django, and related technologies. This setup helps you streamline your development process, akin to having a well-organized toolkit for any major assembly project.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Visual References

Here are some screenshots that illustrate parts of the process:

  • Screenshot 1
  • Screenshot 2
  • Screenshot 3
  • Screenshot 4
  • Screenshot 5
  • Screenshot 6
  • Screenshot 7
  • Screenshot 8
  • Screenshot 9
  • Screenshot 10

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox