Netbox Installation (bobcares.com)
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
- 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
- Change PostgreSQL’s default password.
sudo passwd postgres
- In addition, change user to postgres.
su - postgres
- Then, log in to the PostgreSQL database.
psql
- Create a database called netbox.
CREATE DATABASE netbox;
- Similarly, create a user netbox with password STRONGPASSWORD . Use a strong password in place of STRONGPASSWORD .
CREATE USER netbox WITH ENCRYPTED password 'STRONGPASSWORD';
- Most importantly, ll privileges on the netbox database should be granted to the netbox user.
GRANT ALL PRIVILEGES ON DATABASE netbox to netbox;
- Finally, PostgreSQL should now be exited.
\q
- Meanwhile ,return to sudo user account as a non-root user.
exit
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
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
- In addition, PIP should be updated to the latest version.
sudo pip3 install --upgrade pip
- 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/
- Then, in the current directory, clone NetBox from the official git repository.
sudo git clone -b master https://github.com/netbox-community/netbox.git
- After that, make a system user called netbox.
sudo adduser --system --group netbox
- Most importantly, give the user netbox ownership of the directory /opt/netbox/netbox/media/.
sudo chown --recursive netbox /opt/netbox/netbox/media/
- After that, browse to the directory /opt/netbox/netbox/netbox/.
cd /opt/netbox/netbox/netbox/
- 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
- After that, create a Python binary symbolic link.
sudo ln -s /usr/bin/python3 /usr/bin/python
- Then, create a
SECRET_KEY
with at least 50 alphanumeric characters at random.sudo /opt/netbox/netbox/generate_secret_key.py;
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$LLvg
- Open the configuration.py file and make changes.
sudo nano /opt/netbox/netbox/netbox/configuration.py
Most importantly, following settings should be included in the final file.
DATABASE = {
ALLOWED_HOSTS = ['*']
‘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
- Now, we will enter the Python virtual environment.
source /opt/netbox/venv/bin/activate
- Meanwhile, navigate to the /opt/netbox/netbox directory.
cd /opt/netbox/netbox
- Then, set up a superuser account.
python3 manage.py createsuperuser
- Finally, To apply the changes, reboot.
sudo reboot
Configure Gunicorn
/opt/netbox/contrib/gunicorn.py should be copied to /opt/netbox/gunicorn.pysudo cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
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/
- Secondly , to enable the Systemd changes, reload the daemon.
sudo systemctl daemon-reload
- Then, start the services netbox and netbox-rq.
sudo systemctl start netbox netbox-rq
- Finally, allow services to start automatically when the server boots up.
sudo systemctl enable netbox netbox-rq
Configure Nginx Web Server
- Firstly , set up the Nginx web server.
sudo apt install -y nginx
- 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
- Edit the netbox file.
sudo nano /etc/nginx/sites-available/netbox
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; } }
- Then, delete the file /etc/nginx/sites-enabled/default.
sudo rm /etc/nginx/sites-enabled/default
- 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
- Finally, to enable the new configurations, restart the nginx service.
sudo systemctl restart nginx
[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.