1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

58 lines
2.8 KiB
Markdown
Raw Normal View History

2020-07-20 16:53:04 -04:00
# Gunicorn
2020-11-17 12:01:10 -05:00
Like most Django applications, NetBox runs as a [WSGI application](https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface) behind an HTTP server. This documentation shows how to install and configure [gunicorn](http://gunicorn.org/) (which is automatically installed with NetBox) for this role, however other WSGI servers are available and should work similarly well. [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/) is a popular alternative.
2020-07-20 16:53:04 -04:00
## Configuration
2020-11-17 12:01:10 -05:00
NetBox ships with a default configuration file for gunicorn. To use it, copy `/opt/netbox/contrib/gunicorn.py` to `/opt/netbox/gunicorn.py`. (We make a copy of this file rather than pointing to it directly to ensure that any local changes to it do not get overwritten by a future upgrade.)
2020-07-20 16:53:04 -04:00
```no-highlight
2020-11-17 12:01:10 -05:00
sudo cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
2020-07-20 16:53:04 -04:00
```
2020-11-17 12:01:10 -05:00
While the provided configuration should suffice for most initial installations, you may wish to edit this file to change the bound IP address and/or port number, or to make performance-related adjustments. See [the Gunicorn documentation](https://docs.gunicorn.org/en/stable/configure.html) for the available configuration parameters.
2020-07-20 16:53:04 -04:00
## systemd Setup
We'll use systemd to control both gunicorn and NetBox's background worker process. First, copy `contrib/netbox.service` and `contrib/netbox-rq.service` to the `/etc/systemd/system/` directory and reload the systemd daemon:
2020-07-20 16:53:04 -04:00
```no-highlight
2020-11-17 12:01:10 -05:00
sudo cp -v /opt/netbox/contrib/*.service /etc/systemd/system/
sudo systemctl daemon-reload
2020-07-20 16:53:04 -04:00
```
Then, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time:
```no-highlight
2020-11-17 12:01:10 -05:00
sudo systemctl start netbox netbox-rq
sudo systemctl enable netbox netbox-rq
2020-07-20 16:53:04 -04:00
```
You can use the command `systemctl status netbox` to verify that the WSGI service is running:
```no-highlight
systemctl status netbox.service
```
You should see output similar to the following:
```no-highlight
2020-07-20 16:53:04 -04:00
● netbox.service - NetBox WSGI Service
2020-11-17 12:01:10 -05:00
Loaded: loaded (/etc/systemd/system/netbox.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-08-30 04:02:36 UTC; 14h ago
Docs: https://docs.netbox.dev/
Main PID: 1140492 (gunicorn)
Tasks: 19 (limit: 4683)
Memory: 666.2M
2020-11-17 12:01:10 -05:00
CGroup: /system.slice/netbox.service
├─1140492 /opt/netbox/venv/bin/python3 /opt/netbox/venv/bin/gunicorn --pid /va>
├─1140513 /opt/netbox/venv/bin/python3 /opt/netbox/venv/bin/gunicorn --pid /va>
├─1140514 /opt/netbox/venv/bin/python3 /opt/netbox/venv/bin/gunicorn --pid /va>
2020-07-20 16:53:04 -04:00
...
```
2020-11-17 12:01:10 -05:00
!!! note
If the NetBox service fails to start, issue the command `journalctl -eu netbox` to check for log messages that may indicate the problem.
2020-07-20 16:53:04 -04:00
Once you've verified that the WSGI workers are up and running, move on to HTTP server setup.