Linux

How to install the NetBox Network Management and Documentation Tool on Ubuntu 20.04 LTS

How to install the NetBox Network Management and Documentation Tool on Ubuntu 20.04 LTS

Netbox is a free and powerful IP address (IPAM) tool and a data center infrastructure (DCIM) management tool. This is used to store information about your network, VM, inventory and more. Initially developed by the network engineering team at DigitalOcean. This tool is written in the Django Python framework and relies on the PostgreSQL database. The aim is to function as a domain-specific source of truth for network operations.

In this tutorial, we will explain how to install Netbox with Nginx as a reverse proxy on Ubuntu 20.04.

Precondition

  • Server running Ubuntu 20.04.
  • The root password is configured on your server.

Start

Before you begin, you must install a number of dependencies that are needed by Netbox. You can install everything by running the following command:

apt-get install nginx git gcc supervisor python3 python3-dev python3-pip python3-setuptools build-essential libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev zlib1g-dev -y

After all packages have been installed, you can proceed to the next step.

Install and Configure PostgreSQL Database

Netbox relies on the PostgreSQL database for data storage. You can install it with the following command:

apt-get install postgresql postgresql-contrib -y

After PostgreSQL is installed, enter PostgreSQL with the following command:

su - postgres
postgres@ubuntu2004:~$ psql

You should get the following output:

psql (12.2 (Ubuntu 12.2-4))
Type "help" for help.

Next, create a database and users for Netbox with the following command:

postgres=# CREATE DATABASE netbox;
postgres=# CREATE USER netbox WITH PASSWORD 'password';

Next, give all privileges to the Netbox database with the following command:

postgres=# GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;

Next, exit the PostgreSQL shell with the following command:

postgres=# exit
postgres@ubuntu2004:~$ exit

Install and Configure NetBox

First, change the directory to / opt and download the latest version of Netbox from the Git Hub repository using the following command:

cd /opt/
git clone -b master https://github.com/digitalocean/netbox.git

Next, create a symbolic link from the Python binary with the following command:

ln -s /usr/bin/python3 /usr/bin/python

Next, change the directory to / opt / netbox / netbox / and create the Django SECRET Key by running the following command:

cd /opt/netbox/netbox/
./generate_secret_key.py

You should get the following output:

wcq@L2)eTDpo(k^f4Sm9bariUnK0syCPMGEIjW6XV_8l5xhB7z

Next, change the directory to netbox and rename the example configuration file:

cd netbox
mv configuration.example.py configuration.py

Next, edit the Netbox configuration file and specify your database, secret key and allowed host:

nano configuration.py

Make the following changes:

ALLOWED_HOSTS = ['your-server-ip']

# PostgreSQL database configuration. See the Django documentation for a complete list of available parameters:
#   https://docs.djangoproject.com/en/stable/ref/settings/#databases
DATABASE = {
    'NAME': 'netbox',         # Database name
    'USER': 'netbox',               # PostgreSQL username
    'PASSWORD': 'password',           # PostgreSQL password
    'HOST': 'localhost',      # Database server
    'PORT': '',               # Database port (leave blank for default)
    'CONN_MAX_AGE': 300,      # Max database connection age
}

SECRET_KEY = 'wcq@L2)eTDpo(k^f4Sm9bariUnK0syCPMGEIjW6XV_8l5xhB7z'

Save and close the file then install all Python dependencies with the following command:

pip3 install -r /opt/netbox/requirements.txt

Next, migrate the database with the following command:

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

Next, create an administrative administrative Netbox with the following command:

python3 manage.py createsuperuser

You will be asked to provide a username and password as shown below:

Username (leave blank to use 'root'): netboxadmin
Email address: hitjethva@gmail.com
Password: 
Password (again): 
Superuser created successfully.

Next, gather a static file with the following command:

python3 manage.py collectstatic

You will see the following output:

976 static files copied to '/opt/netbox/netbox/static'.

Install and configure Gunicorn

Netbox is a Django based application. So you need to install Gunicorn on your system. You can install it by running the following command:

pip3 install gunicorn

After installing Gunicorn, create a new Gunicorn configuration file for Netbox with the following command:

nano /opt/netbox/gunicorn_config.py

Add the following lines:

command = '/usr/local/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = 'your-server-ip:8001'
workers = 3
user = 'www-data'

Save and close the file when you are finished.

Install and Configure Supervisor

Supervisor is a client / server system that allows you to monitor and control NetBox services. You can create a new Supervisor configuration file for Netbox with the following command:

nano /etc/supervisor/conf.d/netbox.conf

Add the following lines:

[program:netbox]
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
user = www-data

Save and close the file when finished. Then, restart the Supervisor service with the following command:

systemctl restart supervisor

You can also verify the status of the Supervisor service using the following command:

systemctl status supervisor

You should get the following output:

? supervisor.service - Supervisor process control system for UNIX
     Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-05-30 05:49:08 UTC; 14s ago
       Docs: http://supervisord.org
   Main PID: 550606 (supervisord)
      Tasks: 5 (limit: 4691)
     Memory: 184.3M
     CGroup: /system.slice/supervisor.service
             ??550606 /usr/bin/python3 /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
             ??550626 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550628 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550629 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550630 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi

May 30 05:49:08 ubuntu2004 systemd[1]: Started Supervisor process control system for UNIX.
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,664 CRIT Supervisor is running as root.  Privileges were not dropped becau>
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,664 INFO Included extra file "/etc/supervisor/conf.d/netbox.conf" during p>
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,671 INFO RPC interface 'supervisor' initialized
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,671 CRIT Server 'unix_http_server' running without any HTTP authentication>
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,672 INFO supervisord started with pid 550606
May 30 05:49:09 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:09,676 INFO spawned: 'netbox' with pid 550626
May 30 05:49:11 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:11,060 INFO success: netbox entered RUNNING state, process has stayed up for

Configure Nginx for NetBox

It is a good idea to configure Nginx as a reverse proxy to access Netbox on port 80. You can create a new Nginx virtual host configuration by using the following command:

nano /etc/nginx/sites-available/netbox.conf

Add the following lines:

server {
    listen 80;
    server_name your-server-ip;
    client_max_body_size 25m;

    location /static/ {
        alias /opt/netbox/netbox/static/;
    }

    location / {
        proxy_pass http://your-server-ip:8001;
    }
}

Save and close the file. Then, create a symbolic link to the / etc / nginx / site-enabled / directory:

ln -s /etc/nginx/sites-available/netbox.conf /etc/nginx/sites-enabled/

Next, verify Nginx for each syntax error with the following command:

nginx -t

If everything is fine, you should get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart the Nginx service to implement the changes.

systemctl restart nginx

You can also verify Nginx with the following command:

systemctl status nginx

You should get the following output:

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-05-30 22:28:13 EST; 4min 14s ago
  Process: 984 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 982 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 980 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 985 (nginx)
    Tasks: 3 (limit: 25028)
   Memory: 5.5M
   CGroup: /system.slice/nginx.service
           ??985 nginx: master process /usr/sbin/nginx
           ??986 nginx: worker process
           ??987 nginx: worker process

May 30 21:28:12 ubuntu2004 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 30 21:28:12 ubuntu2004 nginx[982]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 30 21:28:12 ubuntu2004 nginx[982]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 30 21:28:13 ubuntu2004 systemd[1]: Started The nginx HTTP and reverse proxy server.

At this point, the Nginx web server is configured to serve Netbox on port 80. Now you can continue to access the Netbox web interface.

Netbox Web Interface Access

Open your web browser and visit the URL http: // your-server-ip. You will be directed to the following page:

1

Click on the Enter button. You should see the Netbox login page on the following screen:

2

Provide the admin username, password, and click the login button. You will see the default Netbox dashboard on the following page:

3

Conclusion

In this guide, you learn how to install Netbox on Ubuntu 20.04 with Nginx. You can now start documenting your network infrastructure. For more information, visit the official Netbox documentation. It’s free to ask me if you have questions.

Related posts

How to install Grafana Enterprise Edition on Ubuntu Server 20.04

Linux

How to Install Joomla with Apache2 and Let’s Encrypt on Ubuntu 20.04

Linux

How to Activate Dark Mode on Ubuntu 20.04 LTS

Howto

How to Set Up WireGuard VPN Server and Client on Ubuntu 20.04

Linux

How to Install Skype on Ubuntu 20.04

Linux

How to Play PS2 Games on Ubuntu Using PCSX2

Linux

How to Install Ruby on Ubuntu 20.04

Linux

How to Use Sudo Commands on Linux

Linux

How to Install the GitScrum Agile Project Management Tool on Ubuntu 20.04 LTS

Linux