System Environment Preparation
This procedure utilizes a minimal installation of Rocky Linux 9. Ensure SELinux is disabled and the firewall is stopped to simplify the initial deployment.
systemctl disable --now firewalld
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
setenforce 0
PostgreSQL Database Configuration
Install the PostgreSQL 15 server and initialize the database. It is recommended to create a dedicated database and user for the application.
dnf install -y postgresql-server postgresql-contrib
postgresql-setup --initdb
systemctl enable --now postgresql
Access the database shell to create the schema and user credentials.
sudo -u postgres psql
CREATE DATABASE netbox_prod;
CREATE USER netbox_user WITH PASSWORD 'SecureDBPass123';
GRANT ALL PRIVILEGES ON DATABASE netbox_prod TO netbox_user;
\q
Redis Cache and Task Queue Setup
Install and configure Redis for caching and background task management. Set a strong password in the configuration file.
dnf install -y redis
# Edit /etc/redis.conf to set requirepass
sed -i 's/^# requirepass .*/requirepass RedisSecurePass456/' /etc/redis/redis.conf
systemctl enable --now redis
Python Environment
NetBox 4.0 requires Python 3.10 or newer. Install Python 3.11 along with necessary development headers for compiling dependencies.
dnf install -y python3.11 python3.11-pip python3.11-devel libxml2-devel libxslt-devel libpq-devel redhat-rpm-config
NetBox Application Installation
Create a system user for the application and download the source code. This example uses the 4.0 release branch.
useradd --system --home-dir /opt/netboxapp --shell /sbin/nologin netbox
cd /opt
wget https://github.com/netbox-community/netbox/archive/refs/tags/v4.0.0.tar.gz
tar -xzf v4.0.0.tar.gz
mv netbox-4.0.0 netboxapp
chown -R netbox:netbox /opt/netboxapp
Core Configuration
Navigate to the configuration directory and generate a secret key. Create the configuration.py file and define the database, Redis, and localization settings.
cd /opt/netboxapp/netbox/netbox
sudo -u netbox cp configuration_example.py configuration.py
sudo -u netbox python3 ../generate_secret_key.py
Edit configuration.py to match your environment parameters. Enable localization to support multi-language interfaces.
ALLOWED_HOSTS = ['*']
SECRET_KEY = '<GENERATED_KEY_HERE>'
DATABASE = {
'NAME': 'netbox_prod',
'USER': 'netbox_user',
'PASSWORD': 'SecureDBPass123',
'HOST': 'localhost',
'PORT': '',
'CONN_MAX_AGE': 300,
}
REDIS = {
'tasks': {
'HOST': 'localhost',
'PORT': 6379,
'PASSWORD': 'RedisSecurePass456',
'DATABASE': 0,
'SSL': False,
},
'caching': {
'HOST': 'localhost',
'PORT': 6379,
'PASSWORD': 'RedisSecurePass456',
'DATABASE': 1,
'SSL': False,
}
}
ENABLE_LOCALIZATION = True
TIME_ZONE = 'Asia/Shanghai'
Database Initialization and Static Files
Run the upgrade script to install Python dependencies, apply database migrations, and collect static files.
sudo -u netbox /opt/netboxapp/upgrade.sh
Administrative User Creation
Activate the Python virtual environment to create an administrative superuser account.
source /opt/netboxapp/venv/bin/activate
cd /opt/netboxapp/netbox
python3 manage.py createsuperuser
Service Configuration
Deploy the systemd service files for the Gunicorn WSGI server and the Redis queue worker.
cp /opt/netboxapp/contrib/*.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now netbox netbox-rq
Nginx Reverse Proxy
Configure Nginx to serve as a frontend proxy for the NetBox application.
dnf install -y nginx
cat <<EOF > /etc/nginx/conf.d/netbox.conf
server {
listen 80;
server_name netbox.example.local;
client_max_body_size 25m;
location /static/ {
alias /opt/netboxapp/netbox/static/;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
EOF
systemctl enable --now nginx
Chinese Language Localization
To implement the Chinese language pack, replace the default translation file with the localized version and compile the messages.
cd /opt/netboxapp/netbox/locale/zh_Hans/LC_MESSAGES
# Download or place the translated django.po file here
wget -O django.po https://example.com/netbox-cn.po
source /opt/netboxapp/venv/bin/activate
cd /opt/netboxapp/netbox
python3 manage.py compilemessages
systemctl restart netbox netbox-rq