Installing Sentry on Ubuntu 12.04.5 LTS

Installing Sentry on Ubuntu 12.04.5 LTS

Installing Sentry on Ubuntu 12.04.5 LTS

**This post is no longer valid – I will make an updated post to replace this one**
Sentry makes life so much easier for a Sys Admin. It will tell you when there are errors on a web server. Everyone has had one of those days where the QA team just deploy an update and things aren’t working as they should. That’s where Sentry saves you hours of sifting through logs. It plot a nice graph of how often errors are occurring and it will give you the actual error below that with when last the error occurred. Installing Sentry will make a world of difference.


First install nginx as root.

root@sent01:~# apt-get install nginx

Now add the sentry user and add the user to the sudo group

root@sent01:~# adduser sentry
root@sent01:~# adduser sentry sudo

Switch to the sentry user

root@sent01:~# su - sentry

Install the prerequisites

sentry@sent01:/root$ sudo apt-get install build-essential python-dev

Make sure that you are in the sentry home directory

sentry@sent01:/root$ cd ~

Download the python distro package and run it

sentry@sent01:~$ wget http://python-distribute.org/distribute_setup.py
sentry@sent01:~$ sudo python distribute_setup.py

Remove the files as they are not needed again

sentry@sent01:~$ rm -f distribute.*

Install pip

sentry@sent01:~$ sudo easy_install pip

Install the virtual environment packages

sentry@sent01:~$ sudo pip install virtualenv virtualenvwrapper

Add the following to the sentry .bashrc, then exit and switch back to the sentry user and back to the sentry home folder

sentry@sent01:~$ echo "" >> .bashrc
sentry@sent01:~$ echo "source /usr/local/bin/virtualenvwrapper.sh" >> .bashrc
sentry@sent01:~$ exit
sentry@sent01:~$ su sentry
sentry@sent01:~$ cd ~

Make the virtual environment for sentry and install sentry

sentry@sent01:~$ mkvirtualenv sentry_env
(sentry_env)sentry@sent01:~$ pip install sentry

Initialize sentry – this also creates the config file for sentry (it will show you the location)

(sentry_env)sentry@sent01:~$ sentry init

Now install postgresql and create the database

(sentry_env)sentry@sent01:~$ sudo apt-get install postgresql postgresql-contrib libpq-dev

Install postgres adminpack

(sentry_env)sentry@sent01:~$ sudo -u postgres psql
psql (9.1.14)
Type "help" for help.

postgres=# CREATE EXTENSION "adminpack";
postgres=# \q

Change the postgres password

(sentry_env)sentry@sent01:~$ sudo passwd postgres

Switch to the postgres user and create the database

(sentry_env)sentry@sent01:~$ sudo su - postgres
postgres@sent01:~$ psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'changeme';"
postgres@sent01:~$ createdb your_sentry_db_name
postgres@sent01:~$ createuser your_sentry_user --pwprompt
postgres@sent01:~$ psql -d template1 -U postgres
psql (9.1.14)
Type "help" for help.

postgres=# GRANT ALL PRIVILEGES ON DATABASE your_sentry_db_name to your_sentry_user;
postgres=# \q
postgres@sent01:~$ exit

Edit the sentry config file and add the new database info

sentry@sent01:~$ vi .sentry/sentry.conf.py

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': os.path.join(CONF_ROOT, 'sentrydb'),
        'USER': 'sentry_user',
        'PASSWORD': '******',
        'HOST': 'localhost',
        'PORT': '',

Install psycopg2 and run the sentry upgrade

sentry@sent01:~$ workon sentry_env
(sentry_env)sentry@sent01:~$ sentry upgrade

I just added the sentry config to the nginx default config

sentry@sent01:~$ sudo vi /etc/nginx/sites-available/default

server {
        listen   80 default;
        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;


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

  proxy_set_header   Host              $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;
}

#       location / {
#               root   /var/www/nginx-default;
#               index  index.html index.htm;
#       }

        location /doc {
                root   /usr/share;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        location /images {
                root   /usr/share;
                autoindex on;
        }
}

Restart nginx

(sentry_env)sentry@sent01:~$ sudo /etc/init.d/nginx restart

Install and configure supervisor to keep sentry running

(sentry_env)sentry@sent01:~$ sudo apt-get install supervisor
(sentry_env)sentry@sent01:~$ sudo vi /etc/supervisor/conf.d/sentry.conf

[program:sentry-web]
directory=/home/sentry/
command=/home/sentry/.virtualenvs/sentry_env/bin/sentry start http
autostart=true
autorestart=true
redirect_stderr=true

== Restart Supervisor ==

(sentry_env)sentry@sent01:~$ sudo killall supervisord
(sentry_env)sentry@sent01:~$ sudo supervisord
 **NOTE** Please make sure that you give the VM you are using ample RAM if you are using this in a production environment, after many Nginx Bad gateway 502 errors I found the problem was lack of RAM once the machine starts collecting stats. 2GB and over should work fine, also you might want to give it a second CPU.

Leave a Reply

Your email address will not be published. Required fields are marked *