NetBox is an open-source Infrastructure Resource Modeling (IRM) tool designed for network automation and infrastructure engineering. This guide provides a step-by-step approach to installing and configuring NetBox IRM on a Debian 12 server.
📋 Prerequisites
Before proceeding, ensure you have:
- A Debian 12 server.
- A non-root user with sudo privileges.
- A domain name pointed to your server’s IP address (optional but recommended).
🔧 Step 1: Install Required Dependencies
Update your package index and install necessary packages:
sudo apt update<br>sudo apt install apache2 postgresql postgresql-common libpq-dev redis-server git python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libssl-dev zlib1g-dev -y
Verify that the services are running:
sudo systemctl is-enabled apache2
sudo systemctl status apache2
sudo systemctl is-enabled postgresql
sudo systemctl status postgresql
sudo systemctl is-enabled redis
sudo systemctl status redis
🗄️ Step 2: Configure PostgreSQL Database
Switch to the PostgreSQL user and create a new database and user for NetBox:
sudo -u postgres psql
Within the PostgreSQL shell, execute:
CREATE USER netbox LOGIN CREATEDB PASSWORD 'p4ssw0rd';
CREATE DATABASE netboxdb OWNER netbox;
\du
\l
\q
Test the connection:
sudo -u postgres psql --username netbox --password --host localhost netboxdb
\conninfo
\q
🔁 Step 3: Configure Redis Server
Edit the Redis configuration file to set a password:
sudo nano /etc/redis/redis.conf
Uncomment and set the requirepass directive:
requirepass p4ssw0rdNetBox
Restart Redis to apply changes:
sudo systemctl restart redis
Test the Redis connection:
redis-cli
AUTH p4ssw0rdNetBox
PING
exit
📥 Step 4: Install NetBox
Create a system user for NetBox and clone the repository:
sudo useradd -r -d /opt/netbox -s /usr/sbin/nologin netbox
cd /opt
sudo git clone -b master --depth 1 https://github.com/netbox-community/netbox.git
sudo chown -R netbox:netbox /opt/netbox
Generate a secret key:
cd /opt/netbox/netbox/netbox
sudo -u netbox python3 ../generate_secret_key.py
Copy the example configuration:
sudo -u netbox cp configuration_example.py configuration.py
sudo -u netbox nano configuration.py
In the configuration.py file, set the following:
ALLOWED_HOSTS = ['netbox.example.com', '192.168.10.15']
DATABASE = {
'NAME': 'netboxdb',
'USER': 'netbox',
'PASSWORD': 'p4ssw0rd',
'HOST': 'localhost',
'PORT': '',
'CONN_MAX_AGE': 300,
}
REDIS = {
'tasks': {
'HOST': 'localhost',
'PORT': 6379,
'PASSWORD': 'p4ssw0rdNetBox',
'DATABASE': 0,
'SSL': False,
},
'caching': {
'HOST': 'localhost',
'PORT': 6379,
'PASSWORD': 'p4ssw0rdNetBox',
'DATABASE': 1,
'SSL': False,
}
}
SECRET_KEY = 'your-generated-secret-key'
Replace ‘your-generated-secret-key’ with the key generated earlier.
🔄 Step 5: Run NetBox Upgrade Script
Execute the upgrade script to set up the environment:
sudo -u netbox /opt/netbox/upgrade.sh
👤 Step 6: Create Superuser Account
Activate the virtual environment and create a superuser:
source /opt/netbox/venv/bin/activate
cd /opt/netbox/netbox
python3 manage.py createsuperuser
Follow the prompts to set up the admin account.
🔧 Step 7: Configure Gunicorn and Systemd Services
Copy and edit the Gunicorn configuration:
sudo -u netbox cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
sudo -u netbox nano /opt/netbox/gunicorn.py
Set the bind address:
bind = '127.0.0.1:8001'
Copy the systemd service files and reload the daemon:
sudo cp -v /opt/netbox/contrib/*.service /etc/systemd/system/
sudo systemctl daemon-reload
Start and enable the services:
sudo systemctl start netbox netbox-rq netbox-housekeeping
sudo systemctl enable netbox netbox-rq netbox-housekeeping
Check the status of the services:
sudo systemctl status netbox
sudo systemctl status netbox-rq
🌐 Step 8: Configure Apache as a Reverse Proxy
Generate SSL certificates (for local domains):
openssl req -x509 -newkey rsa:4096 -sha256 -days 365 \
-nodes -keyout /etc/ssl/private/netbox.key -out /etc/ssl/certs/netbox.crt -subj "/CN=netbox.example.com" \
-addext "subjectAltName=DNS:netbox.example.com,IP:192.168.10.15"
Copy and edit the Apache configuration:
sudo cp /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf
sudo nano /etc/apache2/sites-available/netbox.conf
Update the ServerName and SSL certificate paths accordingly.
Enable necessary Apache modules and the NetBox site:
sudo a2enmod ssl proxy proxy_http headers rewrite
sudo a2ensite netbox.conf
sudo apachectl configtest
sudo systemctl restart apache2
✅ Step 9: Access NetBox Web Interface
Open your web browser and navigate to:
https://netbox.example.com/
Log in using the superuser credentials you created earlier.
🎉 Conclusion
You’ve successfully installed and configured NetBox IRM on Debian 12. This setup includes PostgreSQL as the database backend, Redis for caching, and Apache as a reverse proxy secured with SSL. NetBox is now ready to assist you in managing and documenting your network infrastructure efficiently.
Meta Description: Learn how to install and configure NetBox IRM on Debian 12 with PostgreSQL, Redis, and Apache. This step-by-step guide ensures a secure and efficient setup for network infrastructure management.
SEO Keywords: NetBox installation Debian 12, configure NetBox IRM, NetBox PostgreSQL setup, NetBox Redis configuration, Apache reverse proxy NetBox
Hướng dẫn cài đặt Cluster Kafka trên Ubuntu
https://forum.congdonglinux.com










Add Comment