NetBox Installation unter Debian 12.x

PostgreSQL Installation

sudo apt update
sudo apt install -y postgresql

Anlegen der Datenbank

sudo -u postgres psql
CREATE DATABASE netbox;
CREATE USER netbox WITH PASSWORD 'SICHERES_PASSWORT';
ALTER DATABASE netbox OWNER TO netbox;
-- the next two commands are needed on PostgreSQL 15 and later
\connect netbox;
GRANT CREATE ON SCHEMA public TO netbox;

Test der Datenbank Verbindung

$ psql --username netbox --password --host localhost netbox
Password for user netbox: 
psql (12.5 (Ubuntu 12.5-0ubuntu0.20.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

netbox=> \conninfo
You are connected to database "netbox" as user "netbox" on host "localhost" (address "127.0.0.1") at port "5432".
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
netbox=> \q

Redis

sudo apt install -y redis-server
redis-server -v

Test Redis -> es sollte ein Pong zurückkommen

redis-cli ping

NetBox Installation (supports Python 3.10, 3.11 and 3.12)

apt install -y python3 python3-pip python3-venv python3-dev \
build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev \
libssl-dev zlib1g-dev

Python Version prüfen

python3 -V

Installation wget, Download NetBox und entpacken nach /opt

apt install -y wget

wget https://github.com/netbox-community/netbox/archive/refs/tags/v4.3.4.tar.gz
tar xvzf v4.3.4.tar.gz -C /opt
ln -s /opt/netbox-4.3.4/ /opt/netbox

Nutzer anlegen und Rechte vergeben

adduser --system --group netbox
chown --recursive netbox /opt/netbox/netbox/media/
chown --recursive netbox /opt/netbox/netbox/reports/
chown --recursive netbox /opt/netbox/netbox/scripts/

Konfigurationsdatei configuration.py kopieren und bearbeiten

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

vi configuration.py

DATABASES = {
    'default': {
        'NAME': 'netbox',               # Database name
        'USER': 'netbox',               # PostgreSQL username
        'PASSWORD': 'SICHERES_PASSWORT', # PostgreSQL password
        'HOST': 'localhost',            # Database server
        'PORT': '',                     # Database port (leave blank for default)
        'CONN_MAX_AGE': 300,            # Max database connection age (seconds)
    }
}

REDIS = {
    'tasks': {
        'HOST': 'localhost',      # Redis server
        'PORT': 6379,             # Redis port
        'PASSWORD': '',           # Redis password (optional)
        'DATABASE': 0,            # Database ID
        'SSL': False,             # Use SSL (optional)
    },
    'caching': {
        'HOST': 'localhost',
        'PORT': 6379,
        'PASSWORD': '',
        'DATABASE': 1,            # Unique ID for second database
        'SSL': False,
    }
}

Key erzeugen und in die configuration.py eintragen

python3 ../generate_secret_key.py

Update Script aufrufen

/opt/netbox/upgrade.sh

Super User anlegen

source /opt/netbox/venv/bin/activate

cd /opt/netbox/netbox
python3 manage.py createsuperuser

Housekeeping

ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping

Startscripte

/etc/systemd/system/netbox.service

[Unit]
Description=NetBox WSGI Service
After=network.target

[Service]
Type=simple
User=netbox
Group=netbox
WorkingDirectory=/opt/netbox-4.4.4/netbox
ExecStart=/opt/netbox-4.4.4/venv/bin/gunicorn --workers 3 --max-requests 500 --timeout 120 \
  --bind 127.0.0.1:8001 netbox.wsgi
Restart=on-failure

[Install]
WantedBy=multi-user.target

/etc/systemd/system/netbox-rq.service

[Unit]
Description=NetBox RQ Worker
After=network.target

[Service]
Type=simple
User=netbox
Group=netbox
WorkingDirectory=/opt/netbox-4.4.4/netbox
ExecStart=/opt/netbox-4.4.4/venv/bin/python /opt/netbox-4.4.4/netbox/manage.py rqworker
Restart=on-failure

[Install]
WantedBy=multi-user.target

Fertig!

Strukturhinweise

Organization

Sites - Örtlichkeit (Bsp.: Headquarter Company A)

Regions - Standort (Bsp.: Europa -> Deutschland -> Senftenberg)

Site Groups - Gruppierung der Sites (Bsp.: Headquarter Company A, Aussenstelle 1 Company A, ...)

Locations - Raumbezeichnung (Bsp.: Serverraum 301, Büro 212, etc.)

Tenants - Mandanten

Tenant Groups - Gruppierung von Mandanten

Contacts - Kontakte

Contact Groups - Gruppierung von Kontakten

Contact Roles - spezifische Rollen der Kontakte (Bsp.: IT-Administrator, IT-Koordinator, ...)

Racks

Racks - Anlegen von Racks für den späteren "Einbau" der Systeme

Rack Roles - Funktionale Einordnung der Racks (Bsp.: Passive Komponenten)

Devices

Devices - Konkrete Geräte (Bsp.: hqswitch01, hqrouter02, pc-gf, Dose-3.1, etc.)

Modules - Module welche in Geräten verbaut sein können

Device Roles - Funktionale Rollen der Geräte (Bsp.: Switch, Router, Firewall, ...)

Platforms - Betriebssysteme der Geräte

Virtual Chassis - Logische Einheiten bestehend aus mehreren physischen Geräten (Bsp.: Gestackter Switch)

Device Types - Konkrete Typen-Bezeichnung des Geräts (Bsp.: ASA5512)

Manufacturers - Hersteller (Bsp.: Cisco, Fujitsu, ...)