index.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. Quickstart
  2. ==========
  3. Some basic prerequisites which you'll need in order to run Sentry:
  4. * Python 2.5, 2.6, or 2.7
  5. * python-setuptools, python-dev
  6. * A real database (PostgreSQL is preferred, MySQL also works)
  7. * A UNIX-based operating system
  8. The recommended configuration of Sentry involves setting up a separate web server to handle your error
  9. logging. This means that any number of Sentry clients simply pass on this information to your primary Sentry
  10. server.
  11. This guide will step you through setting up a virtualenv, installing the required packages,
  12. and configuring the basic web service.
  13. Hardware
  14. --------
  15. Sentry provides a number of mechanisms to scale its capacity out horizontally, however there is still a primary
  16. SPOF at the database level. In an HA setup, the database is only utilized for event indexing and basic data
  17. storage, and becomes much less of a capacity concern (see also :doc:`../nodestore/index`).
  18. We don't have any real numbers to tell you what kind of hardware you're going to need, but we'll help you make
  19. your decision based on existing usage from real customers.
  20. If you're looking for an HA, and high throughput setup, you're going to need to setup a fairly complex cluster
  21. of machines, and utilize all of Sentry's advanced configuration options. This means you'll need Postgres, Riak,
  22. Redis, Memcached, and RabbitMQ. It's very rare you'd need this complex of a cluster, and the primary usecase for
  23. this is `getsentry.com <https://getsentry.com/>`_.
  24. For more typical, but still fairly high throughput setups, you can run off of a single machine as long as it has
  25. reasonable IO (ideally SSDS), and a good amount of memory.
  26. The main things you need to consider are:
  27. - TTL on events (how long do you need to keep historical data around)
  28. - Average event throughput
  29. - How many events get grouped together (which means they get sampled)
  30. At a point, getsentry.com was processing approximately 4 million events a day. A majority of this data is stored
  31. for 90 days, which accounted for around 1.5TB of SSDs. Web and worker nodes were commodity (8GB-12GB RAM, cheap
  32. SATA drives, 8 cores), the only two additional nodes were a dedicated RabbitMQ and Postgres instance (both on SSDs,
  33. 12GB-24GB of memory). In theory, given a single high-memory machine, with 16+ cores, and SSDs, you could handle
  34. the entirety of the given data set.
  35. Setting up an Environment
  36. -------------------------
  37. The first thing you'll need is the Python ``virtualenv`` package. You probably already
  38. have this, but if not, you can install it with::
  39. easy_install -UZ virtualenv
  40. Once that's done, choose a location for the environment, and create it with the ``virtualenv``
  41. command. For our guide, we're going to choose ``/www/sentry/``::
  42. virtualenv /www/sentry/
  43. Finally, activate your virtualenv::
  44. source /www/sentry/bin/activate
  45. .. note:: Activating the environment adjusts your PATH, so that things like easy_install now
  46. install into the virtualenv by default.
  47. Install Sentry
  48. --------------
  49. Once you've got the environment setup, you can install Sentry and all its dependencies with
  50. the same command you used to grab virtualenv::
  51. easy_install -UZ sentry
  52. Don't be worried by the amount of dependencies Sentry has. We have a philosophy of using the right tools for
  53. the job, and not reinventing them if they already exist.
  54. Using MySQL or Postgres
  55. ~~~~~~~~~~~~~~~~~~~~~~~
  56. We **highly** recommend using PostgreSQL for your database, or MySQL if you have no other choice. The default
  57. is sqlite and will handle very little load. If you're using MySQL, you should use InnoDB as your storage engine.
  58. These databases require additional packages, but Sentry provides a couple of meta packages to make things easier:
  59. ::
  60. # install sentry and its postgresql dependencies
  61. easy_install -UZ sentry[postgres]
  62. # or if you choose, mysql
  63. easy_install -UZ sentry[mysql]
  64. Installing from Source
  65. ~~~~~~~~~~~~~~~~~~~~~~
  66. If you're installing the Sentry source (e.g. from git), you'll simply need to run the ``make`` command to
  67. get all of the dependencies::
  68. # all things should be this easy
  69. make
  70. Once everything's installed, you should be able to execute the Sentry CLI, via ``sentry``, and get something
  71. like the following::
  72. $ sentry
  73. usage: sentry [--config=/path/to/settings.py] [command] [options]
  74. Initializing the Configuration
  75. ------------------------------
  76. Now you'll need to create the default configuration. To do this, you'll use the ``init`` command
  77. You can specify an alternative configuration path as the argument to init, otherwise it will use
  78. the default of ``~/.sentry/sentry.conf.py``.
  79. ::
  80. # the path is optional
  81. sentry init /etc/sentry.conf.py
  82. The configuration for the server is based on ``sentry.conf.server``, which contains a basic Django project
  83. configuration, as well as the default Sentry configuration values. It defaults to SQLite, however **SQLite
  84. is not a fully supported database and should not be used in production**.
  85. ::
  86. # ~/.sentry/sentry.conf.py
  87. DATABASES = {
  88. 'default': {
  89. 'ENGINE': 'django.db.backends.postgresql_psycopg2', # We suggest PostgreSQL for optimal performance
  90. 'NAME': 'sentry',
  91. 'USER': 'postgres',
  92. 'PASSWORD': '',
  93. 'HOST': '',
  94. 'PORT': '',
  95. 'OPTIONS': {
  96. 'autocommit': True,
  97. }
  98. }
  99. }
  100. # No trailing slash!
  101. SENTRY_URL_PREFIX = 'http://sentry.example.com'
  102. # SENTRY_KEY is a unique randomly generated secret key for your server, and it
  103. # acts as a signing token
  104. SENTRY_KEY = '0123456789abcde'
  105. SENTRY_WEB_HOST = '0.0.0.0'
  106. SENTRY_WEB_PORT = 9000
  107. SENTRY_WEB_OPTIONS = {
  108. 'workers': 3, # the number of gunicorn workers
  109. 'secure_scheme_headers': {'X-FORWARDED-PROTO': 'https'}, # detect HTTPS mode from X-Forwarded-Proto header
  110. }
  111. Configure Outbound Mail
  112. -----------------------
  113. Several settings exist as part of the Django framework which will configure your outbound mail server. For the
  114. standard implementation, using a simple SMTP server, you can simply configure the following::
  115. EMAIL_HOST = 'localhost'
  116. EMAIL_HOST_PASSWORD = ''
  117. EMAIL_HOST_USER = ''
  118. EMAIL_PORT = 25
  119. EMAIL_USE_TLS = False
  120. Being that Django is a pluggable framework, you also have the ability to specify different mail backends. See the
  121. `official Django documentation <https://docs.djangoproject.com/en/1.3/topics/email/?from=olddocs#email-backends>`_ for
  122. more information on alternative backends.
  123. Running Migrations
  124. ------------------
  125. Sentry provides an easy way to run migrations on the database on version upgrades. Before running it for
  126. the first time you'll need to make sure you've created the database:
  127. ::
  128. # If you're using Postgres, and kept the database ``NAME`` as ``sentry``
  129. createdb -E utf-8 sentry
  130. Once done, you can create the initial schema using the ``upgrade`` command::
  131. sentry --config=/etc/sentry.conf.py upgrade
  132. **It's very important that you create the default superuser through the upgrade process. If you do not, there is
  133. a good chance you'll see issues in your initial install.**
  134. If you did not create the user on the first run, you can correct this by doing the following::
  135. # create a new user
  136. sentry --config=/etc/sentry.conf.py createsuperuser
  137. # run the automated repair script
  138. sentry --config=/etc/sentry.conf.py repair --owner=<username>
  139. All schema changes and database upgrades are handled via the ``upgrade`` command, and this is the first
  140. thing you'll want to run when upgrading to future versions of Sentry.
  141. .. note:: Internally, this uses `South <http://south.aeracode.org>`_ to manage database migrations.
  142. Starting the Web Service
  143. ------------------------
  144. Sentry provides a built-in webserver (powered by gunicorn and eventlet) to get you off the ground quickly,
  145. also you can setup Sentry as WSGI application, in that case skip to section `Running Sentry as WSGI application`.
  146. To start the webserver, you simply use ``sentry start``. If you opted to use an alternative configuration path
  147. you can pass that via the --config option.
  148. ::
  149. # Sentry's server runs on port 9000 by default. Make sure your client reflects
  150. # the correct host and port!
  151. sentry --config=/etc/sentry.conf.py start
  152. You should now be able to test the web service by visiting `http://localhost:9000/`.
  153. Setup a Reverse Proxy
  154. ---------------------
  155. By default, Sentry runs on port 9000. Even if you change this, under normal conditions you won't be able to bind to
  156. port 80. To get around this (and to avoid running Sentry as a privileged user, which you shouldn't), we recommend
  157. you setup a simple web proxy.
  158. Proxying with Apache
  159. ~~~~~~~~~~~~~~~~~~~~
  160. Apache requires the use of mod_proxy for forwarding requests::
  161. ProxyPass / http://localhost:9000/
  162. ProxyPassReverse / http://localhost:9000/
  163. ProxyPreserveHost On
  164. RequestHeader set X-Forwarded-Proto "https" env=HTTPS
  165. You will need to enable ``headers``, ``proxy``, and ``proxy_http`` apache modules to use these settings.
  166. Proxying with Nginx
  167. ~~~~~~~~~~~~~~~~~~~
  168. You'll use the builtin HttpProxyModule within Nginx to handle proxying::
  169. location / {
  170. proxy_pass http://localhost:9000;
  171. proxy_redirect off;
  172. proxy_set_header Host $host;
  173. proxy_set_header X-Real-IP $remote_addr;
  174. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  175. proxy_set_header X-Forwarded-Proto $scheme;
  176. }
  177. See :doc:`nginx` for more details on using Nginx.
  178. Enabling SSL
  179. ~~~~~~~~~~~~~
  180. If you are planning to use SSL, you will also need to ensure that you've
  181. enabled detection within the reverse proxy (see the instructions above), as
  182. well as within the Sentry configuration:
  183. ::
  184. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
  185. Running Sentry as a Service
  186. ---------------------------
  187. We recommend using whatever software you are most familiar with for managing Sentry processes. For us, that software
  188. of choice is `Supervisor <http://supervisord.org/>`_.
  189. Configure ``supervisord``
  190. ~~~~~~~~~~~~~~~~~~~~~~~~~
  191. Configuring Supervisor couldn't be more simple. Just point it to the ``sentry`` executable in your virtualenv's bin/
  192. folder and you're good to go.
  193. ::
  194. [program:sentry-web]
  195. directory=/www/sentry/
  196. command=/www/sentry/bin/sentry start http
  197. autostart=true
  198. autorestart=true
  199. redirect_stderr=true
  200. Additional Utilities
  201. --------------------
  202. If you're familiar with Python you'll quickly find yourself at home, and even more so if you've used Django. The
  203. ``sentry`` command is just a simple wrapper around Django's ``django-admin.py``, which means you get all of the
  204. power and flexibility that goes with it.
  205. Some of those which you'll likely find useful are:
  206. createsuperuser
  207. ~~~~~~~~~~~~~~~
  208. Quick and easy creation of superusers. These users have full access to the entirety of the Sentry server.
  209. runserver
  210. ~~~~~~~~~
  211. Testing Sentry locally? Spin up Django's builtin runserver (or ``pip install django-devserver`` for something
  212. slightly better).
  213. Enabling Social Auth
  214. --------------------
  215. Most of the time it doesnt really matter **how** someone authenticates to the service, so much as it that they do. In
  216. these cases, Sentry provides tight integrated with several large social services, including: Twitter, Facebook, Google,
  217. and GitHub. Enabling this is as simple as setting up an application with the respective services, and configuring a
  218. couple values in your ``sentry.conf.py`` file.
  219. By default, users will be able to both signup (create a new account) as well as associate an existing account. If you
  220. want to disable account creation, simply set the following value::
  221. SOCIAL_AUTH_CREATE_USERS = False
  222. Twitter
  223. ~~~~~~~
  224. Register an application at http://twitter.com/apps/new. Take the values given on the page, and configure
  225. the following::
  226. TWITTER_CONSUMER_KEY = ''
  227. TWITTER_CONSUMER_SECRET = ''
  228. .. note:: It's important that input a callback URL, even if its useless. We have no idea why, consult Twitter.
  229. Facebook
  230. ~~~~~~~~
  231. Register an application at http://developers.facebook.com/setup/. You'll also need to make sure you select the "Website
  232. with Facebook Login" and fill in the Site URL field (just use the website's URL you're install Sentry on). Take the
  233. values given on the page, and configure the following::
  234. FACEBOOK_APP_ID = ''
  235. FACEBOOK_API_SECRET = ''
  236. Google
  237. ~~~~~~
  238. Register an application at http://code.google.com/apis/accounts/docs/OAuth2.html#Registering. Take the values given on the page, and configure
  239. the following::
  240. GOOGLE_OAUTH2_CLIENT_ID = ''
  241. GOOGLE_OAUTH2_CLIENT_SECRET = ''
  242. GitHub
  243. ~~~~~~
  244. Register an application at https://github.com/settings/applications/new. Take the values given on the page, and configure
  245. the following::
  246. GITHUB_APP_ID = ''
  247. GITHUB_API_SECRET = ''
  248. For more information on configuring social authentication services, consult the `documentation on django-social-auth
  249. <https://github.com/omab/django-social-auth/>`_.
  250. Trello
  251. ~~~~~~
  252. Generate an application key at https://trello.com/1/appKey/generate. Take the values given on the page, and configure
  253. the following::
  254. TRELLO_API_KEY = ''
  255. TRELLO_API_SECRET = ''
  256. What's Next?
  257. ------------
  258. There are several applications you may want to add to the default Sentry install for various security or other uses. This
  259. is a bit outside of the scope of normal (locked down) installs, as typically you'll host things on your internal network. That
  260. said, you'll first need to understand how you can modify the default settings.
  261. First pop open your ``sentry.conf.py``, and add the following to the **very top** of the file::
  262. from sentry.conf.server import *
  263. Now you'll have access to all of the default settings (Django and Sentry) to modify at your own will.
  264. If you're running in the public domain, we highly recommend looking into `django-secure <http://pypi.python.org/pypi/django-secure>`_
  265. and `django-bcrypt <http://pypi.python.org/pypi/django-bcrypt>`_ to lock down your installation with a little bit more
  266. security. For example, to change the password storage to bcrypt (rather than the Django default), you would add the
  267. following to your ``sentry.conf.py``::
  268. INSTALLED_APPS = INSTALLED_APPS + (
  269. 'django_bcrypt',
  270. )
  271. Configuring Memcache
  272. ~~~~~~~~~~~~~~~~~~~~
  273. You'll also want to consider configuring cache and buffer settings, which respectively require a cache server and a Redis
  274. server. While the Django configuration covers caching in great detail, Sentry allows you to specify a backend for its
  275. own internal purposes:
  276. ::
  277. # You'll need to install django-pyblibmc for this example to work
  278. CACHES = {
  279. 'default': {
  280. 'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
  281. 'LOCATION': 'localhost:11211',
  282. }
  283. }
  284. SENTRY_CACHE_BACKEND = 'default'
  285. See :doc:`../buffer/index` for information on how to configure update buffers to improve performance on concurrent writes.