Bobcares

Netbox Installation

by | May 5, 2022

Netbox installation will will allow us to automate most networking operations. Its an open-source, web-based Infrastructure Resource Modeling (IRM) application.

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.

Check out how our Support team assisted a customer with installing and configuring NetBox on Ubuntu 20.04.

Netbox Installation

NetBox is a web-based, open-source Infrastructure Resource Modeling (IRM) application. Its main tool is IP Address Management (IPAM), which manages IP addresses. Another tool is Datacenter Infrastructure Management (DCIM), which manages and documents computer networks.

Prerequisites

  • Firstly, install Ubuntu 20.04 LTS, with at least 2GB of RAM and 1 vCPU core, on Vultr.
  • In addition, create a sudo-enabled non-root user.

Install and configure PostgreSQL

  1. Firstly, PostgreSQL should be installed.
    sudo apt install postgresql libpq-dev -yCopy Code
  2. Secondly, we need to start the database server.
  3. Meanwhile, allow the database server to start automatically when the server is restarted.
    sudo systemctl enable postgresqlCopy Code
  4. Change PostgreSQL’s default password.
    sudo passwd STRONGPASSWORDCopy Code
  5. In addition, change user to postgres.
    su - postgresCopy Code
  6. Then, log in to the PostgreSQL database.
    psqlCopy Code
  7. Create a database called netbox.
    CREATE DATABASE netbox;Copy Code
  8. Similarly, create a user netbox with password STRONGPASSWORD . Use a strong password in place of STRONGPASSWORD .
    CREATE USER netbox WITH ENCRYPTED password 'STRONGPASSWORD';Copy Code
  9. Most importantly, ll privileges on the netbox database should be granted to the netbox user.
    GRANT ALL PRIVILEGES ON DATABASE netbox to netbox;Copy Code
  10. Finally, PostgreSQL should now be exited.
    \qCopy Code
  11. Meanwhile ,return to sudo user account as a non-root user.
    exitCopy Code

Install Redis

Redis is a key-value store that runs in memory. So, it’s used by NetBox for caching and queuing.

We can install Redis using the following command.

sudo apt install -y redis-serverCopy Code

Install and configure NetBox

It’s best to install NetBox from the official git repository. So that we can upgrade without having to re-pull the master branch.

  1. Firstly, all of the required packages should be installed.
    sudo apt install python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev git -yCopy Code
  2. In addition, PIP should be updated to the latest version.
    sudo pip3 install --upgrade pipCopy Code
  3. The installation directory will be /opt/netbox/. So, create the /opt/netbox/ directory and change to the/opt/netbox/ directory.
    sudo mkdir -p /opt/netbox/ && cd /opt/netbox/ Copy Code

  4. Then, in the current directory, clone NetBox from the official git repository.
    sudo git clone -b master https://github.com/netbox-community/netbox.gitCopy Code
  5. After that, make a system user called netbox.
    sudo adduser --system --group netboxCopy Code
  6. Most importantly, give the user netbox ownership of the directory /opt/netbox/netbox/media/.
    sudo chown --recursive netbox /opt/netbox/netbox/media/Copy Code
  7. After that, browse to the directory /opt/netbox/netbox/netbox/.
    cd /opt/netbox/netbox/netbox/Copy Code
  8. In addition, copy the configuration.example.py example configuration file to the configuration.py file we’ll use to configure the project.
    sudo cp configuration.example.py configuration.pyCopy Code
  9. After that, create a Python binary symbolic link.
    sudo ln -s /usr/bin/python3 /usr/bin/pythonCopy Code
  10. Then, create a
    SECRET_KEYCopy Code
    with at least 50 alphanumeric characters at random.
    sudo /opt/netbox/netbox/generate_secret_key.py;Copy Code

    We will be given a random secret_key, similar to the one shown below. Create a copy of it and keep it somewhere safe. It’ll be required in the configuration file.

    XLM7Wd$9M8hajGqqJC^DS&*-fed=jF&k-k9jjxQ-n5#8s$LLvgCopy Code
  11. Open the configuration.py file and make changes.
    sudo nano /opt/netbox/netbox/netbox/configuration.pyCopy Code

    Most importantly, following settings should be included in the final file.

    
    ALLOWED_HOSTS = ['*']Copy Code

    DATABASE = {
    ‘NAME’: ‘netbox’, # Database name we created
    ‘USER’: ‘netbox’, # PostgreSQL username we created
    ‘PASSWORD’: ‘my_strong_password’, # PostgreSQL password we set
    ‘HOST’: ‘localhost’, # Database server
    ‘PORT’: ”, # Database port (leave blank for default)
    }

    SECRET_KEY = ‘-^%YEl*Q2etCR6$kNG70H=&sM(45XvJaBWdf3O)inZ@L9j8_w1’

  12. Then, run the script to upgrade the server.
    sudo /opt/netbox/upgrade.shCopy Code
  13. Now, we will enter the Python virtual environment.
    source /opt/netbox/venv/bin/activateCopy Code
  14. Meanwhile, navigate to the /opt/netbox/netbox directory.
    cd /opt/netbox/netboxCopy Code
  15. Then, set up a superuser account.
    python3 manage.py createsuperuserCopy Code
  16. Finally, To apply the changes, reboot.
    sudo rebootCopy Code

Configure Gunicorn

/opt/netbox/contrib/gunicorn.py should be copied to /opt/netbox/gunicorn.py

sudo cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.pyCopy Code

Configure Systemd

  1. Firstly, in the /etc/systemd/system/ directory, copy contrib/netbox.service and contrib/netbox-rq.service.
    sudo cp /opt/netbox/contrib/*.service /etc/systemd/system/Copy Code
  2. Secondly , to enable the Systemd changes, reload the daemon.
    sudo systemctl daemon-reloadCopy Code
  3. Then, start the services netbox and netbox-rq.
    sudo systemctl start netbox netbox-rqCopy Code
  4. Finally, allow services to start automatically when the server boots up.
    sudo systemctl enable netbox netbox-rqCopy Code

Configure Nginx Web Server

  1. Firstly , set up the Nginx web server.
    sudo apt install -y nginxCopy Code
  2. Secondly, copy the nginx.conf file from NetBox Nginx to /etc/nginx/sites-available/netbox.
    sudo cp /opt/netbox/contrib/nginx.conf /etc/nginx/sites-available/netboxCopy Code
  3. Edit the netbox file.
    sudo nano /etc/nginx/sites-available/netboxCopy Code

    Replace the content of the files with the code below. Most importantly, replace the server name value with the IP address of our server:

    
    server {
        listen 80;
    
        # CHANGE THIS TO OUR SERVER'S NAME
        server_name 192.0.2.10;
    
        client_max_body_size 25m;
    
        location /static/ {
            alias /opt/netbox/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;
        }
    }
    
    Copy Code
  4. Then, delete the file /etc/nginx/sites-enabled/default.
    sudo rm /etc/nginx/sites-enabled/defaultCopy Code
  5. After that, create a symlink to the netbox configuration file in the sites-enabled directory.
    sudo ln -s /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netboxCopy Code
  6. Finally, to enable the new configurations, restart the nginx service.
    sudo systemctl restart nginxCopy Code

[Looking for a solution to another query? We are just a click away.]

Conclusion

To sum up, NetBox has been successfully installed. We can now log in using the username and password we assigned to the superuser account when we created it.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Speed issues driving customers away?
We’ve got your back!