Skip to content

Installing NetBox

Outcome: a NetBox 4.7.4 install whose database exists, whose static files are collected, and whose administrator account is created — ready for the server to be started in chapter 4. NetBox is the heavy install of its class: a Python application that needs a PostgreSQL server and a Redis server beside it. This chapter assembles all of it, in the order the pieces depend on each other.

What has to be true first

  • PostgreSQL, version 14 or newer. The lab ran 16.15, started fresh in a scratch folder on a lab port, with an empty database named netbox waiting (transcripts t01-postgres-initdb.txt and t12-services-summary.txt). The PostgreSQL guide in this series covers the database itself.
  • Redis, any recent version. The lab ran the system Redis 7.0.15 on a lab port with its files in the lab folder. Two logical databases are used, 0 for tasks and 1 for caching.
  • Python 3.12 in the lab (NetBox 4.7 supports the recent 3.x line), and room: the environment that follows is a few hundred megabytes.

The release tarball

The lab installed NetBox 4.7.4 from the project's official GitHub release — the source archive netbox-v4.7.4.tar.gz (about 21 MB; its SHA-256 is recorded in transcript t00-environment.txt). Unpacked, the top level holds the application in a netbox/ folder, requirements.txt, and an upgrade.sh that automates the steps this chapter does by hand — the lab did them by hand so each one is visible.

The Python environment

NetBox's dependencies are pinned, all of them, in requirements.txt — Django itself (6.1.2 in this release), the REST framework, the PostgreSQL driver, and several dozen more:

python3 -m venv venv
./venv/bin/pip install -r requirements.txt

One honest wrinkle, kept in the open: the pinned PostgreSQL driver, psycopg[c,pool], builds a C extension and needs the PostgreSQL server headers (pg_config.h), which the lab machine did not have. The lab installed the same driver's official prebuilt form instead — psycopg[binary,pool], same version 3.3.6 — which is a distribution the psycopg project itself ships for exactly this situation (transcript t02-psycopg-substitution.txt). On a machine with the server headers, the pinned line works as written.

The configuration file

NetBox is configured by one Python file, copied from the example that ships beside it:

cd netbox
cp netbox/configuration_example.py netbox/configuration.py

The settings the lab changed, and the only ones a first install must touch:

  • ALLOWED_HOSTS = ['*'] — which web host names NetBox will answer to. A real deployment names its own host; the star is a lab setting.
  • The DATABASES block — name netbox, user netbox, host 127.0.0.1, and the lab's PostgreSQL port.
  • The REDIS block — both the tasks and caching sections pointed at the lab's Redis port, databases 0 and 1.
  • SECRET_KEY — generated with the generate_secret_key.py script that ships in the application folder.
  • API_TOKEN_PEPPERS — a random string of at least 50 characters. Since NetBox 4.5, version 2 API tokens are stored as keyed hashes, and at least one pepper must exist before such a token can be created (chapter 9 lives on this line).

Building the database

With configuration in place, one command builds the entire schema:

../venv/bin/python manage.py migrate

The lab's run applied 337 migrations with no unapplied remainder (transcript t04-migrate.log). On a small shared machine this took minutes, not seconds — the run is mostly hundreds of small, careful steps, and its length is normal.

Static files and the administrator

Two more one-time steps:

../venv/bin/python manage.py collectstatic --no-input

copied 225 static files (the pages' styles, scripts and images) into place, and the administrator account is made non-interactively by handing the values through the environment:

DJANGO_SUPERUSER_USERNAME=labadmin \
DJANGO_SUPERUSER_EMAIL=labadmin@example.com \
DJANGO_SUPERUSER_PASSWORD='<a strong password>' \
  ../venv/bin/python manage.py createsuperuser --noinput
Superuser created successfully.

(Transcript t05-collectstatic-and-superuser.txt.) The lab's password is a throwaway for an install that never left loopback; yours, on anything real, should be a proper secret, stored like one.