Installing Sentry on Centos 6.5

Sentry is a real time event logging and aggregation platform. It allows to aggregate all events of your project in one place. It may be handy to get all logging messages and to have a possibility to track what’s going on with your application. You could use Sentry with node.js, PHP, Go, Python, Java and some other languages/applications. Full list of available clients.

So let’s get started. First problem you encounter while installing Sentry on Centos 6.5. is Python version. It’s written with use of Django and requires  Python 2.7, while Centos shipped with version 2.6.  There are various ways to get Python on Centos, for instance, to compile it from the sources, which is obviously not the best way.  We will use pyenv, version management system for Python. Detailed description on how to install Python 2.7 on Centos 6.5 can be found in our previous post.

One important note, it would be much better to create some system account and to use it for all following actions. Let’s call it sentry:

adduser sentry ; su  - sentry

Once Python 2.7 is installed, install Sentry:

pip2.7 install sentry

We are going to use MySQL so we need one more package for Sentry:

pip2.7 install sentry[mysql]

(If you encounter and issue make sure you have mysql-devel installed).

Init Sentry config:

sentry init

Modify the config to file with your real values for host, databases, etc:

from sentry.conf.server import *
import os.path
CONF_ROOT = os.path.dirname(__file__)
DATABASES = {
 'default': {
 'ENGINE': 'django.db.backends.mysql',
 'NAME': 'sentry',
 'USER': 'sentry',
 'PASSWORD': 'strongpasswprd',
 'HOST': 'localhost',
 'PORT': '3306',
 }
}
CELERY_ALWAYS_EAGER = False
BROKER_URL = 'redis://localhost:6379'
SENTRY_BUFFER = 'sentry.buffer.redis.RedisBuffer'
SENTRY_REDIS_OPTIONS = {
 'hosts': {
 0: {
 'host': '127.0.0.1',
 'port': 6379,
 }
 }
}
USE_X_FORWARDED_HOST = True
SENTRY_WEB_HOST = '127.0.0.1'
SENTRY_WEB_PORT = 9028
SENTRY_WEB_OPTIONS = {
 'secure_scheme_headers': {'X-FORWARDED-PROTO': 'https'},
}
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'sentry.example.com'
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = ''
EMAIL_PORT = 25
EMAIL_USE_TLS = False
SERVER_EMAIL = 'sentry@example.com'
SECRET_KEY = '7mdR5dLYdS5dS5F4sfFswsEUfH8s45sdgtfisdqdYVgdIsbdduv6g7gggsgJFgXg=='
TWITTER_CONSUMER_KEY = ''
TWITTER_CONSUMER_SECRET = ''
FACEBOOK_APP_ID = ''
FACEBOOK_API_SECRET = ''
GOOGLE_OAUTH2_CLIENT_ID = ''
GOOGLE_OAUTH2_CLIENT_SECRET = ''
GITHUB_APP_ID = ''
GITHUB_API_SECRET = ''
TRELLO_API_KEY = ''
TRELLO_API_SECRET = ''
BITBUCKET_CONSUMER_KEY = ''
BITBUCKET_CONSUMER_SECRET = ''
INSTALLED_APPS += ('nagios_sentry', )

If you don’t have Redis installed, install it and proceed:

yum install redis

Create MySQL database for Sentry:

CREATE DATABASE sentry_database CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON sentry_database .* TO 'user'@'%' identified by 'passwd';

Run the migrations:

sentry upgrade

Now create admin user:

sentry createsuperuser
setry repair --owner=<username>

We are ready to start Sentry.

sentry start

Now you can log in and start using Sentry.

Few notes about performance and monitoring.

  • If are going to send thousands of log messages it would make sense to use both Celery workers and update buffers (using Redis as backend). It allows to improve the performace a lot.
  • It would make sense to monitor Sentry.  For this purpose you could use nagios-sentry. You can install it using pip2.7.

It does make sense to use nginx as  a http server and gunicorn server for Sentry behind it. Here’s a sample configuration for nginx:

server {
 server_name sentry.example.com;
 listen 192168.1.1:80;
 access_log /var/log/nginx/sentry.example.com-access.log;
 error_log /var/log/nginx/sentry.example.com-error.log;
 proxy_set_header Host $http_host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_redirect off;
 proxy_connect_timeout 300;
 proxy_send_timeout 300;
 proxy_read_timeout 300;
 keepalive_timeout 0;
 send_timeout 5s;
 resolver_timeout 5s;
 client_body_timeout 5s;
 client_max_body_size 150k;
 client_body_buffer_size 150k;

 location / {
 proxy_pass http://localhost:9028;
 }

 location ~* /api/(?P<projectid>\d+/)?store/ {
 proxy_pass http://localhost:9028;

 }
 }

It’s handy to use supervisord to  lauch Sentry after reboots. Here is a sample configuration for web and workers:

[program:sentry-web]
autostart=true
autorestart=true
startsecs=10
startretries=3
command=su - sentry -c "/home/sentry/.pyenv/shims/sentry --config=/home/sentry/.sentry.conf.py start >> /var/log/sentry/web.log 2>> /var/log/sentry/web.log"
autostart=true
logfile=/var/log/sentry/web.log
redirect_stderr=true

[program:sentry-worker]
autostart=true
autorestart=true
startsecs=10
startretries=3
command=su - sentry -c "/home/sentry/.pyenv/shims/sentry --config=/home/sentry/.sentry.conf.py celery worker -B 2> /var/log/sentry/worker.log 2>> /var/log/sentry/worker.log"
redirect_stderr=true
logfile=/var/log/sentry/worker.log

Happy logging!

Leave a Reply

Your email address will not be published.