Setting Up Your Own Sentry Server
Photo by Lance Anderson on Unsplash
Short tutorial on how to set up your own self-hosted Sentry server.
If you are hosting a Django site, Sentry will make your life easier.
After my
review of various hosting companies
I decided to put EnvelopeBudget.com on
Webfaction. But, I was still
impressed with
Digital Ocean so I kept my
virtual server. Why not? It's only $5
per month for full root access! Because
all their servers have SSD's I'ver never seen a virtual server boot so fast.
Soon will be the day when you will hear someone say, "remember when computers
had moving parts?" I kept it because I figured I'd find a use for it eventually.
Well, I found a use for it.
I love Sentry. We used it at SendOutCards to help us better manage our server errors. I think we were running a pre 1.0 release when it was just called django-sentry. It has come a long way. I set up an account on GetSentry.com and loved it. Since I'm bootstrapping a start-up, I decided to set up my own sentry server on my Digital Ocean account.
I documented the process I went through setting up the server.
Create Ubuntu 12.10 X32 Server droplet & ssh into it as root
1# add non-root user2adduser sentry34# add to sudoers5adduser sentry sudo67# log out of root and log in as sentry8exit910# update the local package index11sudo apt-get update1213# actually upgrade all packages that can be upgraded14sudo apt-get dist-upgrade1516# remove any packages that are no longer needed17sudo apt-get autoremove1819# reboot the machine, which is only necessary for some updates20sudo reboot2122# install python-dev23sudo apt-get install build-essential python-dev2425# download distribute26curl -O http://python-distribute.org/distribute_setup.py2728# install distribute29sudo python distribute_setup.py3031# remove installation files32rm distribute\*3334# use distribute to install pip35sudo easy_install pip3637# install virtualenv and virtualenvwrapper38sudo pip install virtualenv virtualenvwrapper3940# to enable virtualenvwrapper add this line to the end of the .bashrc file41echo "" >> .bashrc42echo "source /usr/local/bin/virtualenvwrapper.sh" >> .bashrc4344# exit and log back in to restart your shell45exit4647# make virtualenv48mkvirtualenv sentry_env4950# install sentry51pip install sentry5253# create settings file (file will be located in ~/.sentry/sentry.conf.py)54sentry init5556# install postgres57sudo apt-get install postgresql postgresql-contrib libpq-dev5859# install postgres adminpack60sudo -u postgres psql61CREATE EXTENSION "adminpack";62q6364# change postgres password & create database65sudo passwd postgres66sudo su - postgres67psql -d template1 -c "ALTER USER postgres WITH PASSWORD '<span class="highlight">changeme</span>';"68createdb <span class="highlight">your_sentry_db_name</span>69createuser <span class="highlight">your_sentry_user</span> --pwprompt70psql -d template1 -U postgres71GRANT ALL PRIVILEGES ON DATABASE <span class="highlight">your_sentry_db_name</span> to <span class="highlight">your_sentry_user</span>;72q73exit7475# update config file to use postgres & host (with vim or your editor of choice)76sudo apt-get install vim77vim .sentry/sentry.conf.py
The following are the contents of my sentry.conf.py
file:
1DATABASES = {2 'default': {3 'ENGINE': 'django.db.backends.postgresql_psycopg2',4 'NAME': '<span class="highlight">your_sentry_db_name</span>',5 'USER': '<span class="highlight">your_sentry_user</span>',6 'PASSWORD': '<span class="highlight">your_password</span>',7 'HOST': 'localhost',8 }9}
You will also want to configure your SMTP mail account. I just used my gmail account.
1# going to need psycopg22workon sentry_env3pip install psycopg245# set up databse6sentry upgrade78# let's try it out!9sentry start1011# install nginx12sudo apt-get install nginx1314# remove the default symbolic link15sudo rm /etc/nginx/sites-enabled/default1617# create a new blank config, and make a symlink to it18sudo touch /etc/nginx/sites-available/sentry19cd /etc/nginx/sites-enabled20sudo ln -s ../sites-available/sentry2122# edit the nginx configuration file23sudo vim /etc/nginx/sites-available/sentry
Here are the contents of my Nginx file:
1server {2 # listen on port 803 listen 80;45 # for requests to these domains6 server_name <span class="highlight">yourdomain.com www.yourdomain.com</span>;78 # keep logs in these files9 access_log /var/log/nginx/sentry.access.log;10 error_log /var/log/nginx/sentry.error.log;1112 # You need this to allow users to upload large files13 # See http://wiki.nginx.org/HttpCoreModule#client_max_body_size14 # I'm not sure where it goes, so I put it in twice. It works.15 client_max_body_size 0;1617 location / {18 proxy_pass http://localhost:9000;19 proxy_redirect off;2021 proxy_read_timeout 5m;2223 # make sure these HTTP headers are set properly24 proxy_set_header Host $host;25 proxy_set_header X-Real-IP $remote_addr;26 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;27 }28}
That's about it.
1# restart nginx2sudo service nginx restart
I set up supervisor as recommend in the comments and the docs to keep sentry runny (though it has never crashed, it does make restarting easier)
1sudo apt-get install supervisor2sudo vim /etc/supervisor/conf.d/sentry.conf
Add the following to the sentry.conf file:
1[program:sentry-web]2directory=/home/sentry/3command=/home/sentry/.virtualenvs/sentry_env/bin/sentry start http4autostart=true5autorestart=true6redirect_stderr=true
Restart supervidord
1sudo killall supervisord2sudo supervisord
Upgrading Sentry:
I've upgraded twice. It was a painless process...
1workon sentry_env2pip install sentry --upgrade3sentry upgrade4sudo supervisorctl restart sentry-web