Skip to content

Instantly share code, notes, and snippets.

@kmanwar89
Created March 4, 2021 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmanwar89/25d7875b06790a0ca32aabd2797c43a2 to your computer and use it in GitHub Desktop.
Save kmanwar89/25d7875b06790a0ca32aabd2797c43a2 to your computer and use it in GitHub Desktop.
NetBox Installation Ubuntu Server 20.04.1
This gist contains instructions on how to install NetBox on a vanilla installation of Ubuntu server. The official documentation has some steps missing, and some steps out of order.
OS: Windows 10 Pro x64
Software: VMWare Workstation Pro 16
VM OS: Ubuntu Server 20.04.2 LTS
# DISCLAIMER
This installation is *not* secure, intentionally. I simply wanted to get it running and write a guide in my own flavor. I found a few issues in the official documentation that are addressed in this guide and will be fed back to the documentation maintainers.
# Install SSH & Postgres
sudo apt-get install openssh-server postgresql libpq-dev -y
sudo systemctl start postgresql
sudo systemctl enable postgresql
# Configure & Validate postgres
sudo -u postgres psql
# Create DB and assign permissions
CREATE DATABASE <DB NAME>;
CREATE USER <USERNAME> WITH PASSWORD '<SECURE PASSWORD>';
GRANT ALL PRIVILEGES ON DATABASE <DB NAME> TO <USERNAME>;
\q
# Validate PostgreSQL DB
psql --username <USERNAME> --password --host localhost <DB NAME>
\conninfo
\q
# Install Redis
sudo apt install -y redis-server
redis-cli ping
# Response will be PONG if it is configured right
# Install System Packages & upgrade Pip
sudo apt install -y python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev
sudo pip3 install --upgrade pip
# Clone Netbox Git Repo
sudo mkdir -p /opt/netbox/ && cd /opt/netbox/
sudo apt install -y git
sudo git clone -b master https://github.com/netbox-community/netbox.git .
# Modify user
sudo adduser --system --group netbox
sudo chown --recursive netbox /opt/netbox/netbox/media/
# Generate secret key to secure Redis installation
cd /opt/netbox/netbox/
python3 generate_secret_key.py
# Configure Netbox
cd netbox && sudo cp configuration.example.py configuration.py && sudo nano configuration.py
# Modify the following fields to match your configuration.
ALLOWED_HOSTS = ['*'] # allows any hosts to reach the installation.
DATABASE = {
'NAME': 'netbox',
'USER': '<USERNAME>',
'PASSWORD' : '<SECURE PASSWORD>',
'HOST' : 'localhost',
'PORT': '',
'CONN_MAX_AGE' : 300,
}
SECRET_KEY='output from generate_secret_key.py script'
Save the configuration, write the changes and exit out.
# Install Napalm <----- totally missing from the docs.
pip install napalm
# Upgrade Netbox <----- this will only work if Napalm is installed, as mentioned above. Any errors will be pretty clearly stated and have to be resolved in order to move on, such as syntax errors.
sudo /opt/netbox/upgrade.sh
# Get into the virtual environment created by upgrade script, above.
source /opt/netbox/venv/bin/activate
# Create a superuser
cd /opt/netbox/netbox
python3 manage.py createsuperuser
# Start Netbox
python3 manage.py runserver 0.0.0.0:8000 --insecure
# Validate server is reachable at <server IP address>:8000 from a web browser.
CTRL+C to quit the server
# Gunicorn setup
sudo cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
# Systemd setup
sudo cp -v /opt/netbox/contrib/*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start netbox netbox-rq
sudo systemctl enable netbox netbox-rq
sudo systemctl status netbox
q
# HTTP Server Setup ---- DO NOT USE THIS FOR A PRODUCTION ENVIRONMENT
# Generate a self-signed cert
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/netbox.key \
-out /etc/ssl/certs/netbox.crt
# Configure nginx
sudo apt install -y nginx
sudo cp /opt/netbox/contrib/nginx.conf /etc/nginx/sites-available/netbox
# Edit the nginx sites-available config
sudo nano /etc/nginx/sites-available/netbox
- change 'netbox.example.com' to '127.0.0.1'
- change 'listen 80;' to 'listen 8005';
- save and quit the editor
- I changed to a port other than 80 b/c my Ubuntu VM was configured for NextCloud, which used port 80 by default.
# More configurations & symlinking
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox
# Restart nginx
sudo systemctl restart nginx
NETBOX IS NOW ACCESSIBLE AT <server IP>:8005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment