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
- Firstly, PostgreSQL should be installed.
sudo apt install postgresql libpq-dev -y
Copy Code - Secondly, we need to start the database server.
- Meanwhile, allow the database server to start automatically when the server is restarted.
sudo systemctl enable postgresql
Copy Code - Change PostgreSQL’s default password.
sudo passwd STRONGPASSWORD
Copy Code - In addition, change user to postgres.
su - postgres
Copy Code - Then, log in to the PostgreSQL database.
psql
Copy Code - Create a database called netbox.
CREATE DATABASE netbox;
Copy Code - 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 - 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 - Finally, PostgreSQL should now be exited.
\q
Copy Code - Meanwhile ,return to sudo user account as a non-root user.
exit
Copy 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-server
Copy 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.
- 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 -y
Copy Code - In addition, PIP should be updated to the latest version.
sudo pip3 install --upgrade pip
Copy Code - 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 - Then, in the current directory, clone NetBox from the official git repository.
sudo git clone -b master https://github.com/netbox-community/netbox.git
Copy Code - After that, make a system user called netbox.
sudo adduser --system --group netbox
Copy Code - Most importantly, give the user netbox ownership of the directory /opt/netbox/netbox/media/.
sudo chown --recursive netbox /opt/netbox/netbox/media/
Copy Code - After that, browse to the directory /opt/netbox/netbox/netbox/.
cd /opt/netbox/netbox/netbox/
Copy Code - 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.py
Copy Code - After that, create a Python binary symbolic link.
sudo ln -s /usr/bin/python3 /usr/bin/python
Copy Code - Then, create a
with at least 50 alphanumeric characters at random.SECRET_KEY
Copy Code
sudo /opt/netbox/netbox/generate_secret_key.py;
Copy CodeWe 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$LLvg
Copy Code - Open the configuration.py file and make changes.
sudo nano /opt/netbox/netbox/netbox/configuration.py
Copy CodeMost importantly, following settings should be included in the final file.
ALLOWED_HOSTS = ['*']
Copy CodeDATABASE = {
‘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’
- Then, run the script to upgrade the server.
sudo /opt/netbox/upgrade.sh
Copy Code - Now, we will enter the Python virtual environment.
source /opt/netbox/venv/bin/activate
Copy Code - Meanwhile, navigate to the /opt/netbox/netbox directory.
cd /opt/netbox/netbox
Copy Code - Then, set up a superuser account.
python3 manage.py createsuperuser
Copy Code - Finally, To apply the changes, reboot.
sudo reboot
Copy 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.py
Copy Code
Configure Systemd
- 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 - Secondly , to enable the Systemd changes, reload the daemon.
sudo systemctl daemon-reload
Copy Code - Then, start the services netbox and netbox-rq.
sudo systemctl start netbox netbox-rq
Copy Code - Finally, allow services to start automatically when the server boots up.
sudo systemctl enable netbox netbox-rq
Copy Code
Configure Nginx Web Server
- Firstly , set up the Nginx web server.
sudo apt install -y nginx
Copy Code - 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/netbox
Copy Code - Edit the netbox file.
sudo nano /etc/nginx/sites-available/netbox
Copy CodeReplace 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 - Then, delete the file /etc/nginx/sites-enabled/default.
sudo rm /etc/nginx/sites-enabled/default
Copy Code - 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/netbox
Copy Code - Finally, to enable the new configurations, restart the nginx service.
sudo systemctl restart nginx
Copy 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.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments