IT & Networking

Master Netbox Installation Tutorial

Welcome to this detailed Netbox installation tutorial, designed to guide you through the process of deploying Netbox on your server. Netbox is an open-source web application crafted for network resource modeling and management, providing powerful IP address management (IPAM) and data center infrastructure management (DCIM) capabilities. Following this Netbox installation tutorial will equip you with a robust platform to document and manage your network infrastructure effectively.

A successful Netbox installation is crucial for organizations looking to streamline their network operations and maintain an accurate, real-time inventory of their devices, IP addresses, and connections. This tutorial covers all necessary prerequisites and step-by-step procedures to ensure a smooth setup.

Prerequisites for Netbox Installation

Before diving into the core of the Netbox installation tutorial, it is essential to prepare your system by ensuring all necessary prerequisites are met. This includes both hardware and software requirements.

System Requirements

  • Operating System: A recent version of Ubuntu (e.g., 20.04 LTS or 22.04 LTS) or CentOS/RHEL is recommended for this Netbox installation tutorial.

  • RAM: A minimum of 4GB RAM is advised, with 8GB or more preferred for larger deployments.

  • CPU: At least 2 CPU cores are recommended.

  • Storage: Sufficient disk space (e.g., 20GB+) for the operating system, Netbox application, and database.

Required Software Components

Your Netbox installation will rely on several key software packages:

  • PostgreSQL: A robust relational database management system.

  • Redis: An in-memory data store, used by Netbox for caching and job queuing.

  • Python 3: The programming language Netbox is built upon.

  • Git: For cloning the Netbox repository.

  • Nginx: A high-performance web server to serve Netbox to users.

  • Gunicorn: A Python WSGI HTTP Server for UNIX, which interfaces between Nginx and Netbox.

  • Virtualenv: To create an isolated Python environment for Netbox.

Preparing Your Server Environment

The first practical step in our Netbox installation tutorial is to set up your server environment. This involves updating packages and installing core services.

Updating System Packages

Always start by updating your system to ensure all packages are current and security patches are applied.

sudo apt update && sudo apt upgrade -y

Installing PostgreSQL

PostgreSQL will serve as Netbox’s primary database. Install it along with its development libraries.

sudo apt install -y postgresql postgresql-contrib libpq-dev

Next, create a database and a user for Netbox. Replace your_db_name, your_db_user, and your_password with strong, unique credentials.

sudo -u postgres psql -c "CREATE DATABASE your_db_name;"

sudo -u postgres psql -c "CREATE USER your_db_user WITH PASSWORD 'your_password';"

sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE your_db_name TO your_db_user;"

Installing Redis

Redis is straightforward to install and configure for the Netbox installation tutorial.

sudo apt install -y redis-server

You can verify its status to ensure it’s running correctly.

sudo systemctl status redis-server

Setting Up Netbox Core Components

With the foundational services in place, we can now proceed with installing Netbox itself.

Installing Python and Dependencies

Ensure Python 3 and its virtual environment tools are installed.

sudo apt install -y python3 python3-dev python3-pip python3-venv build-essential libxml2-dev libxslt1-dev libffi-dev zlib1g-dev

Creating a Virtual Environment

Creating a dedicated virtual environment is a best practice for Python applications like Netbox.

sudo mkdir -p /opt/netbox

sudo chown -R $USER:$USER /opt/netbox

cd /opt/netbox

python3 -m venv venv

source venv/bin/activate

Downloading Netbox

Clone the Netbox repository and switch to a stable release branch. Consult the official Netbox documentation for the latest stable version.

git clone -b develop https://github.com/netbox-community/netbox.git .

git checkout (e.g., git checkout v3.5.1)

Install the required Python packages within your virtual environment.

pip install -r requirements.txt

Configuring Netbox Settings

Copy the example configuration file and edit it to match your environment.

cp netbox/configuration.example.py netbox/configuration.py

nano netbox/configuration.py

Inside configuration.py, you must update the following sections:

  • ALLOWED_HOSTS: Add your server’s IP address or domain name (e.g., ['your_domain.com', 'your_server_ip']).

  • DATABASE: Configure with the PostgreSQL credentials you created earlier.

  • SECRET_KEY: Generate a strong secret key using the provided command: python3 netbox/generate_secret_key.py and paste the output here.

  • REDIS: Ensure the Redis settings are correctly configured for caching and queuing.

Database Migration and User Creation

Once configuration.py is set, apply the database schema and create an administrative user.

Applying Database Migrations

This command creates all necessary tables in your PostgreSQL database.

python3 netbox/manage.py migrate

Creating a Superuser

You need an administrator account to log into Netbox. Follow the prompts to create one.

python3 netbox/manage.py createsuperuser

Running Netbox with Gunicorn and Nginx

This part of the Netbox installation tutorial focuses on setting up the web server and application server for production.

Configuring Gunicorn

Create a Gunicorn systemd service file to manage the Netbox application.

sudo nano /etc/systemd/system/gunicorn.socket

Add the following content:

[Unit] Description=gunicorn socket [Socket] ListenStream=/run/gunicorn.sock [Install] WantedBy=sockets.target

sudo nano /etc/systemd/system/gunicorn.service

Add the following content (adjust ExecStart path if your virtual environment is elsewhere):

[Unit] Description=gunicorn daemon After=network.target [Service] User=netbox Group=netbox WorkingDirectory=/opt/netbox ExecStart=/opt/netbox/venv/bin/gunicorn --workers 3 --bind unix:/run/gunicorn.sock netbox.wsgi:application [Install] WantedBy=multi-user.target

Create the netbox user and group for Gunicorn.

sudo adduser --system --no-create-home netbox

sudo addgroup --system netbox

sudo usermod -a -G netbox www-data

sudo chown -R netbox:netbox /opt/netbox/netbox/static

Collect static files for Nginx.

python3 netbox/manage.py collectstatic --no-input

Setting Up Nginx

Install Nginx if you haven’t already.

sudo apt install -y nginx

Create an Nginx configuration file for Netbox.

sudo nano /etc/nginx/sites-available/netbox.conf

Add the following content (replace your_domain.com with your actual domain or IP):

server { listen 80; server_name your_domain.com your_server_ip; client_max_body_size 25m; location /static/ { alias /opt/netbox/netbox/static/; } location / { proxy_pass http://unix:/run/gunicorn.sock; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } }

Enable the Nginx site and remove the default one.

sudo ln -s /etc/nginx/sites-available/netbox.conf /etc/nginx/sites-enabled/

sudo rm /etc/nginx/sites-enabled/default

Enabling and Starting Services

Enable and start Gunicorn and Nginx services to bring Netbox online.

sudo systemctl daemon-reload

sudo systemctl restart gunicorn.socket gunicorn.service nginx

sudo systemctl enable gunicorn.socket gunicorn.service nginx

Post-Installation Steps

After successfully completing the Netbox installation tutorial, there are a few final steps.

Accessing Netbox

Open your web browser and navigate to your server’s IP address or domain name. You should be presented with the Netbox login screen. Use the superuser credentials you created earlier.

Initial Configuration

Upon logging in, explore the Netbox interface. You can begin populating your network data, configuring custom fields, and setting up users and permissions. Refer to the official Netbox documentation for advanced configuration and usage.

Conclusion

Completing this Netbox installation tutorial provides you with a powerful, open-source solution for managing your network infrastructure. You’ve successfully navigated through system preparation, component installation, database configuration, and web server setup. Netbox will significantly enhance your ability to document and track IP addresses, devices, cables, and more, offering a centralized source of truth for your network. Continue exploring Netbox’s extensive features to fully leverage its capabilities for your organization’s needs.