Installed on Debian 10
2021/08/24
NetBox requires PostgreSQL 9.6 or higher.
apt install postgresql
Check the PostgreSQL version.
psql --version
Start the service and enable it to run at boot time.
systemctl start postgresql
systemctl enable postgresql
Login to PostgreSQL with the postgres
user.
sudo -u postgres psql
Create a new database.
CREATE DATABASE netbox;
Create a new user.
CREATE USER netbox WITH PASSWORD '*****';
Grant privileges on the new database for the new user.
GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;
Exit PostgreSQL.
\q
Login to the DB with the netbox
user.
psql --username netbox --password --host localhost netbox
Once you've successfully logged in, show the connection info for your current session.
\conninfo
Exit.
\q
NetBox v2.9.0 and later require Redis v4.0 or higher.
apt install redis
Show the installed version.
redis-cli --version
Test that the Redis service is functioning.
redis-cli ping
NetBox v2.8.0 and later require Python 3.6, 3.7, or 3.8.
apt install -y python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev
Update pip.
pip3 install --upgrade pip
I will be going the route of cloning Netbox's GIT repository for the sake of ease.
Create a new directory for Netbox.
mkdir -p /opt/netbox/ && cd /opt/netbox/
Install git.
apt install -y git
Clone the master branch of the NetBox GitHub repository into the current directory.
git clone -b master https://github.com/netbox-community/netbox.git .
adduser --system --group netbox
Change ownership of Netbox files.
chown --recursive netbox /opt/netbox/netbox/media/
Move into the configuration directory and make a copy of configuration.example.py
named configuration.py
.
cd /opt/netbox/netbox/netbox/
cp configuration.example.py configuration.py
Open configuration.py
for editing.
vim configuration.py
Modify AT LEAST these parameters:
ALLOWED_HOSTS
DATABASE
REDIS
SECRET_KEY
This is where you specify valid hostnames/IPs of the server Netbox can be reached at.
ALLOWED_HOSTS = ['netbox.example.com', '192.0.2.123']
You can allow all interfaces to accept connections by using an asterisk.
ALLOWED_HOSTS = ['*']
This is self-explanatory - fill out the applicable fields.
DATABASE = {
'NAME': 'netbox', # Database name
'USER': 'netbox', # PostgreSQL username
'PASSWORD': '*****', # PostgreSQL password
'HOST': 'localhost', # Database server
'PORT': '', # Database port (leave blank for default)
'CONN_MAX_AGE': 300, # Max database connection age
}
The default values should suffice in most cases. There are two instances - tasks
and caching
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,
}
}
This parameter must be assigned a randomly-generated key employed as a salt for hashing and related cryptographic functions. (Note, however, that it is never directly used in the encryption of secret data.) This key must be unique to this installation and is recommended to be at least 50 characters long. It should not be shared outside the local system.
Use the pre-packaged Python script to generate this key.
python3 ../generate_secret_key.py
Paste the output of the script into the SECRET_KEY = ‘’
field. Example:
SECRET_KEY = ‘*************’
Save the config file.
To run the actual installation, run the upgrade.sh
script.
It will perform the following functions:
/opt/netbox/upgrade.sh
Netbox does not come with any default user(s), so login is not possible at this point. A super user will need to be created.
Enter into the Python virtual environment created by the upgrade script:
source /opt/netbox/venv/bin/activate
You will see (venv)
prepended to your console prompt.
Create a superuser account using the createsuperuser
Django management command (via manage.py
).
cd /opt/netbox/netbox
python3 manage.py createsuperuser
Use NetBox's development server for testing the application.
python3 manage.py runserver 0.0.0.0:8000 --insecure
This will start the Netbox dev server. You should be able to connect via http://server-ip:8000/
Make sure you can login as the Super User we just created. Navigate to different pages; make sure everything appears to be working correctly.
If you cannot connect to the dev server, something is wrong, do not continue until it is working.
Use deactivate
to exit the Python virtual environment.
deactivate
Because Netbox is a WSGI application, we need to setup Gunicorn.
Copy the Gunicorn config to prevent a future upgrade from overwriting it.
cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
The pre-populated config should suffice for most; check it out to see if there is anything applicable to your situation.
systemd will control both Netbox's worker process and Gunicorn.
Copy contrib/netbox.service
and contrib/netbox-rq.service
to the /etc/systemd/system/
directory and reload the systemd dameon.
cp -v /opt/netbox/contrib/*.service /etc/systemd/system/
systemctl daemon-reload
Start and enable netbox
and netbox-rq
services.
systemctl start netbox netbox-rq
systemctl enable netbox netbox-rq
Use the following command to verify the WSGI service is running:
systemctl status netbox
Installa Apache
apt install -y apache2
Copy the Netbox prebuilt Apache config file to the Apache config directory.
cp /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf
Open the new config file and change the ServerName
parameter appropriately. (I did go through the config and modify it to operate on HTTP instead of HTTPS)
Enable required Apache modules.
a2enmod ssl proxy proxy_http headers
Enable the new site. Disable the default site.
a2ensite netbox
a2dissite 000-default.conf
Restart Apache.
systemctl restart apache2