Preamble:
Hi All,
I’m a relatively inexperienced user, training to be a SA/DevOps guy who’s recently taken it upon himself to deploy the netbox db/app on Centos 6/7 respectively. While I’m aware that the deployment has been dockerized, and well documented on Debian based systems I thought I could learn something by taking the road less traveled.
My goal with this document is to share some of the pitfalls I encountered while trying to adapt the installation documents to my process, in the hopes this can save others some time/effort in deploying the app under similar conditions.
Installation parameters:
Centos 6 (referred to as host 1):
PostgreSQL server.
Centos 7 (referred to as host 2):
Python 2
Httpd stack
Supervisord
Gunicorn
Database Preparation:
Starting with this document as a template modify the process as following:
yum install -y postgresql postgresql-server postgresql-devel python-psycopg2
postgresql-setup initdb
sudo service postgresql initdb
sudo vi /var/lib/pgsql/data/pg_hba.conf -> replace ident with md5
Postpone this until after you have created the db user, attempt logging in
If you can’t login try setting the password via sudo passwd postgresql
sudo -u postgres psql
Follow commands given in the document, use unique password for netbox user, as it will be stored in plaintext on your app host.
sudo vi /var/lib/pgsql/data/pg_hba.conf
Now replace the auth with md5
Add a line -> host all all *full CIDR IP Address of host 2* trust
sudo vi /var/lib/pgsql/data/postgresql.conf
Uncomment and edit line: listen_addresses = “octet IP address of host 1”
Uncomment port line
Make iptables rules
sudo iptables -I INPUT 5 -p udp --dport 5432 -j ACCEPT
sudo iptables -I INPUT 5 -p tcp --dport 5432 -j ACCEPT
Make iptables rules permanent
sudo iptables-save > /etc/iptables.conf
sudo vi /etc/rc.conf -> add line
Iptables-restore < /etc/iptables.conf
sudo service psql restart
App host setup: Netbox Install
On installing the requirements:
I tried installing the required python packages on top of Python3, but found that pip wasn’t in my PATH. So, for the sake of convenience I suggest using Python2, after which pip just worked for me.
While it's possible to git clone the current state of the project, I had some trouble getting gunicorn to serve the app, which may have been related to the fact that I wasn’t working on a stable release.
While it should be technically possible to unpack and run the project from a folder other than /opt/netbox, I recommend getting an install running at this location before making changes as there are a lot of moving parts with regards to apache, gunicorn, and supervisord. If you really feel like putting it elsewhere, just use symlinks :)
Starting with this document, modify the following:
Get the required packages using yum
Download the latest stable release from https://github.com/digitalocean/netbox/releases using wget
Using the doc as a guide, unpack the contents to /opt/ and symlink the resulting folder to /opt/netbox
From /opt/netbox
sudo pip install -r requirements.txt
sudo ./generate_secret_key.py
copy the key down.
From /opt/netbox/netbox
sudo cp configuration.example.py configuration.py
Edit the new configuration.py according to instructions
Under “ALLOWED_HOSTS” edit target field to be ’*’
Under /opt/netbox/netbox/ do the following according to instructions with sudo
./manage.py migrate
./manage.py createsuperuser
./manage.py collectstatic
./manage.py loaddata initial_data
Try running the dev server to see if it throws any errors.
App host setup: Server Setup
On installing the requirements:
From this part of the guide on I am assuming that you’ve got httpd up and running, and firewall rules to allow your web server to be reached. For guides on how to do that check out digitalocean’s wiki:
Starting with this document, modify the following:
sudo pip install gunicorn
sudo yum install supervisor
sudo vi /etc/httpd/conf.d/netbox.conf
Insert the two following lines at the top of the file
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
Copy the template from the instructions to the rest of the file, save it.
sudo systemctl restart httpd
sudo vi /opt/netbox/netbox/gunicorn_config.py
Use the suggested template provided and replace www-data with apache
sudo vi /etc/supervisord.conf
Add line ‘files = supervisord.d/*.conf’
sudo vi /etc/supervisord.d/netbox.conf
Create file according to the template, replace www-data with apache
sudo systemctl restart supervisord
sudo supervisorctl add netbox
sudo supervisorctl start netbox
Add line ‘files = supervisord.d/*.conf