Skip to content

Commit 9352867

Browse files
committed
Fix up the installation docs
1 parent 93837c5 commit 9352867

12 files changed

+68
-173
lines changed

contrib/gunicorn.conf

Lines changed: 0 additions & 22 deletions
This file was deleted.

contrib/gunicorn.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The IP address (typically localhost) and port that the Netbox WSGI process should listen on
2+
bind = '127.0.0.1:8001'
3+
4+
# Number of gunicorn workers to spawn. This should typically be 2n+1, where
5+
# n is the number of CPU cores present.
6+
workers = 5
7+
8+
# Number of threads per worker process
9+
threads = 3
10+
11+
# Timeout (in seconds) for a request to complete
12+
timeout = 120
13+
14+
# The maximum number of requests a worker can handle before being respawned
15+
max_requests = 5000
16+
max_requests_jitter = 500

contrib/netbox-rq.service

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
[Unit]
2-
Description=Netbox RQ Worker
2+
Description=NetBox Request Queue Worker
33
Documentation=https://netbox.readthedocs.io/en/stable/
44
After=network-online.target
55
Wants=network-online.target
66

77
[Service]
88
Type=simple
99

10-
EnvironmentFile=/etc/sysconfig/netbox.env
11-
1210
User=www-data
1311
Group=www-data
1412

15-
WorkingDirectory=${WorkingDirectory}
13+
WorkingDirectory=/opt/netbox
1614

17-
ExecStart=/usr/bin/python3 ${WorkingDirectory}/netbox/manage.py rqworker
15+
ExecStart=/usr/bin/python3 /opt/netbox/netbox/manage.py rqworker
1816

1917
Restart=on-failure
2018
RestartSec=30

contrib/netbox.env

Lines changed: 0 additions & 15 deletions
This file was deleted.

contrib/netbox.service

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
[Unit]
2-
Description=Netbox WSGI
2+
Description=NetBox WSGI Service
33
Documentation=https://netbox.readthedocs.io/en/stable/
44
After=network-online.target
55
Wants=network-online.target
66

77
[Service]
88
Type=simple
99

10-
EnvironmentFile=/etc/sysconfig/netbox.env
11-
1210
User=www-data
1311
Group=www-data
14-
PIDFile=${PidPath}
15-
WorkingDirectory=${WorkingDirectory}
12+
PIDFile=/var/tmp/netbox.pid
13+
WorkingDirectory=/opt/netbox
1614

17-
ExecStart=/usr/local/bin/gunicorn --pid ${PidPath} --pythonpath ${WorkingDirectory}/netbox --config ${ConfigPath} netbox.wsgi
15+
ExecStart=/usr/local/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/netbox --config /opt/netbox/gunicorn.py netbox.wsgi
1816

1917
Restart=on-failure
2018
RestartSec=30
2119
PrivateTmp=true
2220

2321
[Install]
24-
WantedBy=multi-user.target
22+
WantedBy=multi-user.target

contrib/[email protected]

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/installation/1-postgresql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ NetBox requires a PostgreSQL database to store data. This can be hosted locally
44
The installation instructions provided here have been tested to work on Ubuntu 18.04 and CentOS 7.5. The particular commands needed to install dependencies on other distributions may vary significantly. Unfortunately, this is outside the control of the NetBox maintainers. Please consult your distribution's documentation for assistance with any errors.
55

66
!!! warning
7-
NetBox v2.2 and later requires PostgreSQL 9.4 or higher.
7+
NetBox requires PostgreSQL 9.4 or higher.
88

99
# Installation
1010

docs/installation/2-netbox.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,7 @@ Superuser created successfully.
212212
```no-highlight
213213
# python3 manage.py collectstatic --no-input
214214
215-
You have requested to collect static files at the destination
216-
location as specified in your settings:
217-
218-
/opt/netbox/netbox/static
219-
220-
This will overwrite existing files!
221-
Are you sure you want to do this?
222-
223-
Type 'yes' to continue, or 'no' to cancel: yes
215+
959 static files copied to '/opt/netbox/netbox/static'.
224216
```
225217

226218
# Load Initial Data (Optional)
@@ -254,3 +246,11 @@ Next, connect to the name or IP of the server (as defined in `ALLOWED_HOSTS`) on
254246

255247
!!! warning
256248
If the test service does not run, or you cannot reach the NetBox home page, something has gone wrong. Do not proceed with the rest of this guide until the installation has been corrected.
249+
250+
Note that the initial UI will be locked down for non-authenticated users.
251+
252+
![NetBox UI as seen by a non-authenticated user](../media/installation/netbox_ui_guest.png)
253+
254+
After logging in as the superuser you created earlier, all areas of the UI will be available.
255+
256+
![NetBox UI as seen by an administrator](../media/installation/netbox_ui_admin.png)

docs/installation/3-http-daemon.md

Lines changed: 28 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -107,99 +107,26 @@ Install gunicorn:
107107
# pip3 install gunicorn
108108
```
109109

110-
Save the following configuration in the root NetBox installation path as `gunicorn_config.py` (e.g. `/opt/netbox/gunicorn_config.py` per our example installation). Be sure to verify the location of the gunicorn executable on your server (e.g. `which gunicorn`) and to update the `pythonpath` variable if needed. If using CentOS/RHEL, change the username from `www-data` to `nginx` or `apache`. More info on `max_requests` can be found in the [gunicorn docs](https://docs.gunicorn.org/en/stable/settings.html#max-requests).
110+
Copy `contrib/gunicorn.conf` to `/opt/netbox/gunicorn.conf`. We make a copy of this file to ensure that any changes to it do not get overwritten by a future upgrade.
111111

112112
```no-highlight
113-
command = '/usr/bin/gunicorn'
114-
pythonpath = '/opt/netbox/netbox'
115-
bind = '127.0.0.1:8001'
116-
workers = 3
117-
user = 'www-data'
118-
max_requests = 5000
119-
max_requests_jitter = 500
113+
# cp contrib/gunicorn.py /opt/netbox/gunicorn.py
120114
```
121115

122-
# systemd configuration
123-
124-
Copy or link contrib/netbox.service and contrib/netbox-rq.service to /etc/systemd/system/netbox.service and /etc/systemd/system/netbox-rq.service
125-
126-
```no-highlight
127-
# cp contrib/netbox.service to /etc/systemd/system/netbox.service
128-
# cp contrib/netbox-rq.service to /etc/systemd/system/netbox-rq.service
129-
```
130-
131-
Edit /etc/systemd/system/netbox.service and /etc/systemd/system/netbox-rq.service. Be sure to verify the location of the gunicorn executable on your server (e.g. `which gunicorn`). If using CentOS/RHEL, change the username from `www-data` to `nginx` or `apache`:
132-
133-
```no-highlight
134-
/usr/local/bin/gunicorn --pid ${PidPath} --pythonpath ${WorkingDirectory}/netbox --config ${ConfigPath} netbox.wsgi
135-
```
136-
137-
```no-highlight
138-
User=www-data
139-
Group=www-data
140-
```
141-
142-
Copy contrib/netbox.env to /etc/sysconfig/netbox.env
143-
144-
```no-highlight
145-
# cp contrib/netbox.env to /etc/sysconfig/netbox.env
146-
```
147-
148-
Edit /etc/sysconfig/netbox.env and change the settings as required. Update the `WorkingDirectory` variable if needed.
149-
150-
```no-highlight
151-
# Name is the Process Name
152-
#
153-
Name = 'Netbox'
116+
You may wish to edit this file to change the bound IP address or port number, or to make performance-related adjustments.
154117

155-
# ConfigPath is the path to the gunicorn config file.
156-
#
157-
ConfigPath=/opt/netbox/gunicorn.conf
158-
159-
# WorkingDirectory is the Working Directory for Netbox.
160-
#
161-
WorkingDirectory=/opt/netbox/
162-
163-
# PidPath is the path to the pid for the netbox WSGI
164-
#
165-
PidPath=/var/run/netbox.pid
166-
```
118+
# systemd configuration
167119

168-
Copy contrib/gunicorn.conf to gunicorn.conf
120+
We'll use systemd to control the daemonization of NetBox services. First, copy `contrib/netbox.service` and `contrib/netbox-rq.service` to the `/etc/systemd/system/` directory:
169121

170122
```no-highlight
171-
# cp contrib/gunicorn.conf to gunicorn.conf
123+
# cp contrib/*.service /etc/systemd/system/
172124
```
173125

174-
Edit gunicorn.conf and change the settings as required.
126+
!!! note
127+
These service files assume that gunicorn is installed at `/usr/local/bin/gunicorn`. If the output of `which gunicorn` indicates a different path, you'll need to correct the `ExecStart` path in both files.
175128

176-
```
177-
# Bind is the ip and port that the Netbox WSGI should bind to
178-
#
179-
bind='127.0.0.1:8001'
180-
181-
# Workers is the number of workers that GUnicorn should spawn.
182-
# Workers should be: cores * 2 + 1. So if you have 8 cores, it would be 17.
183-
#
184-
workers=3
185-
186-
# Threads
187-
# The number of threads for handling requests
188-
# Threads should be: cores * 2 + 1. So if you have 4 cores, it would be 9.
189-
#
190-
threads=3
191-
192-
# Timeout is the timeout between gunicorn receiving a request and returning a response (or failing with a 500 error)
193-
#
194-
timeout=120
195-
196-
# ErrorLog
197-
# ErrorLog is the logfile for the ErrorLog
198-
#
199-
errorlog='/opt/netbox/netbox.log'
200-
```
201-
202-
Finally, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time:
129+
Then, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time:
203130

204131
```no-highlight
205132
# systemctl daemon-reload
@@ -209,7 +136,24 @@ Finally, start the `netbox` and `netbox-rq` services and enable them to initiate
209136
# systemctl enable netbox-rq.service
210137
```
211138

212-
At this point, you should be able to connect to the nginx HTTP service at the server name or IP address you provided. If you are unable to connect, check that the nginx service is running and properly configured. If you receive a 502 (bad gateway) error, this indicates that gunicorn is misconfigured or not running.
139+
You can use the command `systemctl status netbox` to verify that the WSGI service is running:
140+
141+
```
142+
# systemctl status netbox.service
143+
● netbox.service - NetBox WSGI Service
144+
Loaded: loaded (/etc/systemd/system/netbox.service; enabled; vendor preset: enabled)
145+
Active: active (running) since Thu 2019-12-12 19:23:40 UTC; 25s ago
146+
Docs: https://netbox.readthedocs.io/en/stable/
147+
Main PID: 11993 (gunicorn)
148+
Tasks: 6 (limit: 2362)
149+
CGroup: /system.slice/netbox.service
150+
├─11993 /usr/bin/python3 /usr/local/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/...
151+
├─12015 /usr/bin/python3 /usr/local/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/...
152+
├─12016 /usr/bin/python3 /usr/local/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath /opt/netbox/...
153+
...
154+
```
155+
156+
At this point, you should be able to connect to the HTTP service at the server name or IP address you provided. If you are unable to connect, check that the nginx service is running and properly configured. If you receive a 502 (bad gateway) error, this indicates that gunicorn is misconfigured or not running.
213157

214158
!!! info
215-
Please keep in mind that the configurations provided here are bare minimums required to get NetBox up and running. You will almost certainly want to make some changes to better suit your production environment.
159+
Please keep in mind that the configurations provided here are bare minimums required to get NetBox up and running. You may want to make adjustments to better suit your production environment.
77.3 KB
Loading
76 KB
Loading

netbox/netbox/configuration.example.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
'CONN_MAX_AGE': 300, # Max database connection age
2121
}
2222

23-
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
24-
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
25-
# symbols. NetBox will not run without this defined. For more information, see
26-
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY
27-
SECRET_KEY = ''
28-
2923
# Redis database settings. The Redis database is used for caching and background processing such as webhooks
3024
# Seperate sections for webhooks and caching allow for connecting to seperate Redis instances/datbases if desired.
3125
# Full connection details are required in both sections, even if they are the same.
@@ -48,6 +42,12 @@
4842
}
4943
}
5044

45+
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
46+
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
47+
# symbols. NetBox will not run without this defined. For more information, see
48+
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY
49+
SECRET_KEY = ''
50+
5151

5252
#########################
5353
# #

0 commit comments

Comments
 (0)