Install Cabot on CentOS7 using uwsgi, nginx, and mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The Cabot quick start instructions are for auto installing on ubuntu using fabric, gunicorn, postgres. | |
I wanted to install manually on CentOS 7 running with uwsgi, nginx, mysql, and use our own mail server for | |
alerts instead of Amazon SES | |
These are my notes on how I did that. | |
These notes aren't a complete walkthrough, and a few steps may be missing or wrong, but I thought they might | |
be helpful anyways. | |
Setup | |
1. adduser www | |
passwd www | |
mkdir /var/www/ | |
mkdir /var/www/logs/ | |
mkdir /var/www/run/ | |
mkdir /var/www/run/celery/ | |
chown -R www.www /var/www/ | |
2. download(or clone) Cabot from github: https://github.com/arachnys/cabot/archive/master.zip | |
3. unziped to /var/www/cabot/ | |
4. python setup.py install | |
I'm not sure if this was necessary | |
5. yum install pip gcc python-devel openssl-devel | |
6. pip install setuptools --upgrade | |
7. copied list of required packages from setup.py to requirements.txt | |
replaced psycopg2 with MySQL-python | |
8. pip install -r requirements.txt | |
9. If you want to use your own smtp server instead of amazon: | |
nano cabot/settings.py | |
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | |
EMAIL_HOST = "mail.example.com" | |
10. cp conf/production.env.example cp conf/production.env | |
11. nano conf/production.env | |
DATABASE_URL=mysql://cabot:PASSWORD@db.lan2/Cabot | |
ADMIN_EMAIL=admin@example.com | |
GRAPHITE_API=http://graphite.lan2/ | |
GRAPHITE_USER=cabot | |
GRAPHITE_PASS=PASSWORD | |
WWW_HTTP_HOST=monitor.lan2 | |
12. Install node: | |
yum install gcc-c++ | |
wget http://nodejs.org/dist/v0.10.33/node-v0.10.33.tar.gz | |
./configure | |
make | |
make install | |
npm install -g coffee-script less@1.3 --registry http://registry.npmjs.org/ | |
13. sh -ac ' . ./conf/production.env; python manage.py syncdb' | |
14. sh -ac ' . ./conf/production.env; python manage.py migrate' | |
15. sh -ac ' . ./conf/production.env; python manage.py collectstatic --noinput' | |
16. sh -ac ' . ./conf/production.env; python manage.py compress' | |
17. Setup uwsgi | |
pip install uwsgi | |
nano /etc/systemd/system/uwsgi.service | |
[Unit] | |
Description=uWSGI Emperor | |
After=syslog.target | |
[Service] | |
ExecStart=/bin/uwsgi --ini /etc/uwsgi/emperor.ini | |
Restart=always | |
KillSignal=SIGQUIT | |
Type=notify | |
StandardError=syslog | |
NotifyAccess=main | |
[Install] | |
WantedBy=multi-user.target | |
nano /etc/uwsgi/vassals/cabot.ini | |
[uwsgi] | |
chdir=/var/www/cabot | |
module=cabot.wsgi | |
master=True | |
vacuum=True | |
max-requests=50000 | |
socket=localhost:5000 | |
processes=10 | |
logto=/var/www/logs/cabot_uwsgi.log | |
for-readline = /var/www/cabot/conf/production.env | |
env = %(_) | |
endfor = | |
systemctl start uwsgi | |
systemctl enable uwsgi | |
18. Setup Nginx | |
Install official Nginx rpm from repo: http://wiki.nginx.org/Install | |
nano /etc/nginx/conf.d/cabot.conf | |
upstream django { | |
server 127.0.0.1:5000; | |
} | |
server { | |
listen 10.1.0.74:80; | |
server_name monitor.lan2; | |
access_log /var/www/logs/cabot.access.log; | |
error_log /var/www/logs/cabot.error.log; | |
location / { | |
uwsgi_pass django; | |
include uwsgi_params; | |
} | |
location /static/ { | |
alias /var/www/cabot/static/; | |
} | |
} | |
systemctl start nginx | |
systemctl enable nginx | |
19. Setup systemd file to run celery workers | |
nano /etc/systemd/system/cabot-worker.service | |
# Copied and modified from https://github.com/celery/celery/blob/3.1/extra/systemd/celery.service | |
[Unit] | |
Description=CabotCelery workers | |
After=network.target | |
[Service] | |
Type=forking | |
User=www | |
Group=www | |
WorkingDirectory=/var/www/cabot/ | |
EnvironmentFile=/var/www/cabot/conf/production.env | |
ExecStart=/bin/celery multi start worker \ | |
-A cabot --pidfile=/var/www/run/celery/%n.pid \ | |
--logfile=/var/www/logs/celery_%n.log --loglevel="INFO" \ | |
-B | |
ExecStop=/bin/celery multi stopwait worker \ | |
--pidfile=/var/run/celery/%n.pid | |
ExecReload=/bin/celery multi restart worker \ | |
-A cabot --pidfile=/var/www/run/celery/%n.pid \ | |
--logfile=/var/www/logs/celery_%n.log --loglevel="INFO" | |
[Install] | |
WantedBy=multi-user.target | |
systemctl start cabot-worker | |
systemctl enable cabot-worker | |
20. Install redis | |
Install epel: rpm -Uvh http://mirror.symnds.com/distributions/fedora-epel/7/x86_64/e/epel-release-7-2.noarch.rpm | |
yum install redis | |
systemctl start redis | |
systemctl enable redis | |
21. goto http://monitor.lan2 and see if everything is successfully running | |
Run cabot without uwsgi and nginx for testing: | |
sh -ac ' . ./conf/production.env; python manage.py runserver' | |
To run uwsgi server for testing: | |
sh -ac ' . ./conf/production.env; uwsgi --socket localhost:5000 --module cabot.wsgi --chmod-socket=664' | |
Manually run celery workers: | |
sh -ac '. ./conf/production.env; celery worker -B -A cabot --loglevel=INFO --concurrency=16 -Ofair' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am good up to step 12 when I run step 13 I am getting
[root@ cabot]# sh -ac ' . ./conf/production.env; python manage.py syncdb'
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 350, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 324, in execute
django.setup()
File "/usr/lib/python2.7/site-packages/django/init.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib64/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/usr/lib/python2.7/site-packages/polymorphic/init.py", line 11, in
from .polymorphic_model import PolymorphicModel
File "/usr/lib/python2.7/site-packages/polymorphic/polymorphic_model.py", line 19, in
from django.contrib.contenttypes.models import ContentType
File "/usr/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 159, in
class ContentType(models.Model):
File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 94, in new
app_config = apps.get_containing_app_config(module)
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Here is my manage.py
#!/usr/bin/env python
import os
import sys
if name == "main":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cabot.settings")