A photo of Mitesh Shah

Mitesh Shah

Linux Expert | Automation Enthusiast | Security Consultant

Email Skype Github Twitter Resume Hire Me Keybase LinkedIn Stackoverflow

How to Setup Sentry Logging Server


How to Setup Sentry Logging Server

Setup Repository

# Redis Repository
$ sudo add-apt-repository ppa:chris-lea/redis-server

# Postgresql Repository
$ sudo echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >  /etc/apt/sources.list.d/pgdg.list
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Update Packages

$ sudo apt-get update
$ sudo apt-get dist-upgrade

Install Packages

$ sudo apt-get install python-setuptools python-pip python-dev libxslt1-dev libxml2-dev libz-dev libffi-dev libssl-dev libpq-dev libyaml-dev redis-server postgresql-9.4 nginx-full libjpeg-dev

Create Sentry User

# Create sentry user and add to the sudo group.
$ sudo adduser sentry
$ sudo adduser sentry sudo

Setting up an Environment

$ sudo pip install -U virtualenv
  • Once that’s done, choose a location for the environment, and create it with the virtualenv command. For our guide, we’re going to choose /home/sentry
$ su - sentry
$ virtualenv /home/sentry/
$ source /home/sentry/bin/activate
(sentry) $ echo "source /home/sentry/bin/activate" >> ~/.bashrc

Install Sentry

(sentry) $ pip install -U sentry

Database Setup

(sentry) $ sudo su - postgres
$ createdb sentry_db
$ createuser sentry_user --pwprompt
$ psql -d template1 -U postgres
psql (9.4.5)
Type "help" for help.

template1=# GRANT ALL PRIVILEGES ON DATABASE sentry_db to sentry_user;
template1=# \q
postgres@sent01:~$ exit

Initializing the Configuration

  • Now you’ll need to create the default configuration.
  • To do this, you’ll use the init command You can specify an alternative configuration path as the argument to init, otherwise it will use the default of ~/.sentry.
(sentry) $ sentry init
  • The configuration for the server is based on sentry.conf.server, which contains a basic Django project configuration, as well as the default Sentry configuration values.
(sentry) $ vim ~/.sentry/sentry.conf.py
    'default': {
        'ENGINE': 'sentry.db.postgres',
        'NAME': 'sentry_db',
        'USER': 'sentry_user',
        'PASSWORD': '******',
        'HOST': 'localhost',
        'PORT': '',

Running Migrations

  • Sentry provides an easy way to run migrations on the database on version upgrades.
  • Before running it for the first time you’ll need to make sure you’ve created the database.

  • Once done, you can create the initial schema using the upgrade command
(sentry) $ SENTRY_CONF=~/.sentry sentry upgrade
  • Next up you’ll need to create the first user, which will act as a superuser
(sentry) $ SENTRY_CONF=~/.sentry sentry createuser
  • All schema changes and database upgrades are handled via the upgrade command, and this is the first thing you’ll want to run when upgrading to future versions of Sentry.

Starting the Web Service

  • Sentry provides a built-in webserver (powered by uWSGI) to get you off the ground quickly, also you can setup Sentry as WSGI application, in that case skip to section Running Sentry as WSGI application.

Start Builtin Webserver

(sentry) $ SENTRY_CONF=~/.sentry sentry start &

Start Workers

  • A large amount of Sentry’s work is managed via background workers.
  • These need run in addition to the web service workers
(sentry) $ SENTRY_CONF=~/.sentry sentry celery worker &

Start Cron Process

  • Sentry also needs a cron process which is called celery beat
(sentry) $ SENTRY_CONF=~/.sentry sentry celery beat &

Setup a Reverse Proxy

  • By default, Sentry runs on port 9000. Even if you change this, under normal conditions you won’t be able to bind to port 80.
  • To get around this (and to avoid running Sentry as a privileged user, which you shouldn’t), we recommend you setup a simple web proxy.

  • You’ll use the builtin HttpProxyModule within Nginx to handle proxying:
$ sudo vim /etc/nginx/sites-available/sentry
server {
	listen 80 default_server;
	server_name sentry.example.com;

	location / {
		proxy_pass         http://localhost:9000;
		proxy_redirect     off;

		proxy_set_header   Host              $host;
		proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
		proxy_set_header   X-Forwarded-Proto $scheme;

Restart NGINX

(sentry) $ sudo ln -s /etc/nginx/sites-available/sentry /etc/nginx/sites-enabled/
(sentry) $ sudo service nginx restart

More Information

To know more Information refer official documents.

Post Navigation