NetBox is Infrastructure Resource Modeling (IRM) software for network automation and infrastructure design. It was originally created by the DigitalOcean team and has now become an open source project released under the Apache 2 license. NetBox was built on a Python Django web framework with PostgreSQL as the default database, and installing NetBox is very similar to other web applications Python Django.
NetBox helps you manage your infrastructure which includes:
- DCIM (Data Center Infrastructure Management)
- IPAM (IP Address Management)
- Data chains
- Connections (network, console and power)
- Equipment racks
In this article, you will learn how to install NetBox Infrastructure Resource Modeling on a Debian 11 server. This article includes a basic installation of a PostgreSQL database, a Redis server, and a basic setup of Apache2 as a reverse proxy. Eventually, you will have NetBox up and running on your Debian 11 with HTTPS/SSL enabled on top of it.
To complete this guide, you will need the following requirements:
- One Debian 11 server instance.
- A non-root user with root/administrator privileges.
- The domain name pointed to your Debian server.
Installing PostgreSQL Server
The NetBox application only supports PostgreSQL as the default database. So, you will install PostgreSQL on your Debian server. Then create a new database and user to install NetBox.
The current version of NetBox requires at least PostgreSQL version 10 or higher. In Debian 11, the repository provides a PostgreSQL v13 server by default.
To get started, run the apt command below to update the Debian repository and package index.
sudo apt update
Now install the PostgreSQL server using the following apt command. Type Y to confirm and press ENTER, which will begin the PostgreSQL installation.
sudo apt install postgresql postgresql-common
Now that you have finished installing PostgreSQL, run the following systemctl command to check the PostgreSQL service. You should see that PostgreSQL is enabled and will start automatically when the system boots. And the current PostgreSQL service status is running.
sudo systemctl is-enabled postgresql sudo systemctl status postgresql
Next, you will create a new PostgreSQL database and user for Nextbox. To do this, you must log into the PostgreSQL console.
Run the following command to log into the PostgreSQL console using the “postgres” role.
sudo -u postgres psql
Now run the following queries in the PostgreSQL console to create a new database and user. In this example, we will create a new database named “netboxdb” and a PostgreSQL user “netbox” with password “NetBoxRocks”.
CREATE DATABASE netboxdb; CREATE USER netbox WITH ENCRYPTED PASSWORD 'NetBoxRocks'; GRANT ALL PRIVILEGES ON DATABASE netboxdb TO netbox;
Now press “Ctrl+d” to exit the PostgreSQL console, or type “q” to exit.
To check the database and user, run the following command. This will allow you to connect to the PostgreSQL shell using the “netbox” user to the “netboxdb” database on your PostgreSQL server.
When prompted for a database password, enter the password “NetBoxRocks”.
sudo -u postgres psql --username netbox --password --host localhost netboxdb
After logging into the PostgreSQL console and the “netboxdb” database, run the following query to check the current connection. And you should see that you are connected to the PostgreSQL database “netboxdb” with the user “netbox”.
Press “Ctrl+d” to exit the PostgreSQL console, or type “q” to exit.
Redis server installation
Redis is an in-memory key-value database that will be used by NetBox for caching and queuing. So now you will install the Redis server on your Debian server.
At the time of this writing, the latest version of NetBox requires Redis version 4.0 or higher. The latest Debian 11 repository provides Redis v5.6.
Run the apt command below to start installing Redis. Type Y to confirm the installation and hit ENTER, which will begin installing Redis.
sudo apt install redis-server
Once the installation is complete, run the following systemctl commands to check the Redis service. You should see that the Redis service is enabled and will start automatically when the system boots. And the current status of the Redis service is running.
sudo systemctl is-enabled redis-server sudo systemctl status redis-server
Redis installs by default without authentication. For a production environment, it is recommended to use Redis server authentication. To enable Redis authentication, modify the “/etc/redis/redis.conf” configuration file.
Run the following command to edit the Redis configuration file “/etc/redis/redis.conf”.
sudo nano /etc/redis/redis.conf
Uncomment the “requirepass” option and enter the Redis authentication password. In this example, we will use the password “RedisPasswordNetBox”.
When you’re done, save and close the file.
Now run the following command to restart the Redis service and apply the new changes.
sudo systemctl restart redis-server
To test Redi authentication, run the below “redis-cli” command to connect to the Redis console.
Now run the following command to test your Redis authentication. If your password is correct, you will see an output message such as “OK”.
Now press “Ctrl+d” to exit the Redis console.
Installing NetBox IRM
NetBox is an open source web application written in the Python Django framework. So installing NetBox is very similar to Python Django Web-Framework. The latest version of Netbox requires at least Python v3.8 or higher.
Before starting the NetBox installation, run the following command to create a new “netbox” system user that will be used to run the NetBox web application.
sudo useradd -r -d /opt/netbox -s /usr/sbin/nologin netbox
Install Python3 and some package dependencies using the below apt command.
sudo apt install -y git python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev
Once the installation is complete, run the following command to create a new NetBox installation directory “/opt/netbox” and clone the NetBox source code using the Git command.
mkdir -p /opt/netbox; cd /opt/netbox sudo git clone -b master --depth 1 .
Now change the owner of the NetBox installation directory to the correct “netbox” user using the following command.
sudo chown -R netbox:netbox /opt/netbox
Then move the working directory to “/opt/netbox/netbox/netbox” and copy the NetBox configuration example “configuration_example.py” to “configuration.py”.
cd /opt/netbox/netbox/netbox sudo -u netbox cp configuration_example.py configuration.py
Before editing the netBox configuration file, run the following command to generate a “SECRET_KEY” for NetBox. Copy the generated “SECRET_KEY” into your editor, it will be used later when editing the “configuration.py” file.
sudo -u netbox python3 ../generate_secret_key.py
Run the following command to start editing the “configuration.py” file.
sudo -u netbox nano configuration.py
Now you need to set up your NetBox installation as shown below:
- In the “ALLOWED_HOSTS” configuration, enter the domain name for the NetBox installation and the IP address of the server. In this example, NetBox will be installed under the domain name “netbox.hwdomain.io” and the server IP address “192.168.5.20”.
- Enter the PostgreSQL database details for your NetBox in the “DATABASE” parameter.
- Enter the Redis password in the “REDIS” configuration. Be sure to change the password for the “tasks” and “caching” sections.
- Finally, paste the generated “SECRET_KEY” into the file.
When you’re done, save and close the file.
Now to start installing NetBox, you can run the “upgrade.sh” script as shown below.
sudo -u netbox /opt/netbox/upgrade.sh
This script will install and configure the NetBox installation automatically. Detailed version below:
- This will create a new Python virtual environment for your NetBox installation.
- This will also install some Python dependencies and libraries for NetBox.
- Performing database migration for NetBox.
- Create a static file resource for NetBox.
The following is a summary of when the installation starts.
When the installation is complete, you will see the following.
Creating a NetBox Administrator User
You have completed the basic installation of NetBox. You will now create a new admin user for NetBox. And it’s also like when you need to create a Django admin user.
Run the following command to activate the Python virtual environment.
Move the working directory to “/opt/netbox/netbox”. Then run the “manage.py” script to create a new admin user for NetBox.
cd /opt/netbox/netbox python3 manage.py createsuperuser
Enter your username, email address and password for NextBox.
Once the admin setup is complete, run the following command to set up the required cron script for NetBox. This will run automatically daily.
sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping
Finally, run the following command to test and verify your NetBox installation. If your installation is correct, you will see that netBox is now running on port “8000”.
python3 manage.py runserver 0.0.0.0:8000 --insecure
Now press “Ctrl + c” in the terminal for the process. Then run the “deactivate” command to exit the Python virtual environment.
Configuring NetBox as a Systemd Service
After completion, we will configure the administrator for NetBox. You will now configure NetBox as a systemd service. The NetBox service will run under a Gunicorn and HTTP reverse proxy.
All the necessary NetBox Gunicorn configuration and systemd service script are available by default in the “/opt/netbox/contrib” directory.
Run the following command to copy the Gunicorn configuration to “/opt/netbox/gunicorn.py”. Then edit the file with the nano editor.
sudo -u netbox cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py sudo -u netbox nano /opt/netbox/gunicorn.py
In the default configuration, the NetBox application will run on localhost on port “8001”. You can leave the default configuration or make changes depending on your environment.
bind = '127.0.0.1:8001'
Save and close the configuration file when you’re done.
Then copy the systemd service files to the “/etc/systemd/system” directory using the following command. This will enable two services: the “netbox” service as the main service for your NetBox application, and the “netbox-rq” service for the NetBox Request Queue service.
sudo cp -v /opt/netbox/contrib/*.service /etc/systemd/system/
Now restart the system manager to apply the new NetBox service files.
sudo systemctl daemon-reload
After restarting the systemd manager, you can start the “netbox” and “netbox-rq” services using the systemctl command as shown below. Both services will start automatically at system startup.
sudo systemctl start netbox netbox-rq sudo systemctl enable netbox netbox-rq
Finally, check the NetBox services with the following command.
sudo systemctl status netbox sudo systemctl status netbox-rq
In the following output, you can see that the “netbox” service is enabled. And the current status is working.
For the “netbox-rq” service, you will also have access to the output of the service. And she works.
Configuring Apache2 as a Reverse Proxy
Run the apt command below to install the Apache2 web server. Type Y to confirm the installation and press ENTER to start the installation.
sudo apt install apache2
Once the Apache2 installation is complete, run the following command to enable some Aapche2 modules to be used for the reverse proxy. You should see that some additional modules are included as well.
sudo a2enmod ssl proxy proxy_http headers
Then copy the sample Apache2 virtual host configuration for NetBox to “/etc/apache2/sites-available/netbox.conf”. Then edit the “/etc/apache2/sites-available/netbox.conf” file using the nano editor.
sudo cp /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf sudo nano /etc/apache2/sites-available/netbox.conf
Change the domain name for the NetBox installation and the path of the SSL certificates. In this example, we will use the “netbox.hwdomain.io” domain with Letsencrypt’s SSL certificates available in the “/etc/letsencrypt/live/netbox.hwdomain.io/” directory.
When you’re done, save and close the file.
Now run the following command to activate the “netbox.conf” virtual host configuration. Then test and verify the Apache configuration. You should get an output message such as “Syntax OK”, which means that the Apache2 configuration is correct.
sudo a2ensite netbox.conf sudo apachectl configtest
Now restart the Apache2 service to apply the new changes to the virtual host file. The Apache2 web server is now running with HTTPS/SSL enabled, unlike the NetBox web application running on “localhost:8001”.
sudo systemctl restart apache2
To test the installation, open a web browser and navigate to the domain name of the NetBox installation. And you should get the administration panel for NetBox with a locked status.
Click on the “Login” button at the top right.
Now enter the administrator user and password to install netBox and click Login.
You should get NetBox Dashboard Administration.
With this tutorial, you set up NetBox Infrastructure Resource Modeling (IRM) with a PostgreSQL database, Redis caching system, Gunicorn, and an Apache2 reverse proxy on a Debian 11 server. You also set up NetBox as a systemd service that makes it easy to start and stop a web application net box. In the end, you have fully configured NetBox IRM running on your Debian server with secure HTTPS/SSL enabled on top of it.
2370300cookie-checkHow to Install NetBox IRM on Debian 11
Инструкции,Обзоры,Программы,Рабочее окружение,debian 11,NetBox,NetBox IRM
#Install #NetBox #IRM #Debian
❤ XOXO ❤