installation.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. Installation
  2. ============
  3. This guide will step you through setting up a Python-based virtualenv,
  4. installing the required packages, and configuring the basic web service.
  5. Dependencies
  6. ------------
  7. Some basic prerequisites which you'll need in order to run Sentry:
  8. * A UNIX-based operating system. We test on Ubuntu and this documentation
  9. assumes an ubuntu based system.
  10. * Python 2.7
  11. * ``python-setuptools``, ``python-pip``, ``python-dev``, ``libxslt1-dev``,
  12. ``libxml2-dev``, ``libz-dev``, ``libffi-dev``, ``libssl-dev``, ``libpq-dev``,
  13. ``libyaml-dev``
  14. * `PostgreSQL <http://www.postgresql.org/>`_
  15. * `Redis <http://redis.io>`_ (the minimum version requirement is 2.8.9, but 2.8.18, 3.0, or newer are recommended)
  16. * If running Ubuntu < 15.04, you'll need to install from a different PPA.
  17. We recommend `chris-lea/redis-server <https://launchpad.net/~chris-lea/+archive/ubuntu/redis-server>`_
  18. * `Nginx <http://nginx.org>`_ (``nginx-full``)
  19. * A dedicated domain to host Sentry on (i.e. `sentry.yourcompany.com`).
  20. If you're building from source you'll also need:
  21. * Node.js 0.12 or newer.
  22. Hardware
  23. --------
  24. Sentry provides a number of mechanisms to scale its capacity out
  25. horizontally, however there is still a primary SPOF at the database level.
  26. In an HA setup, the database is only utilized for event indexing and basic
  27. data storage, and becomes much less of a capacity concern (see also
  28. :doc:`nodestore`).
  29. We don't have any real numbers to tell you what kind of hardware you're
  30. going to need, but we'll help you make your decision based on existing
  31. usage from real customers.
  32. If you're looking for an HA, and high throughput setup, you're going to
  33. need to setup a fairly complex cluster of machines, and utilize all of
  34. Sentry's advanced configuration options. This means you'll need Postgres,
  35. Riak, Redis, Memcached, and RabbitMQ. It's very rare you'd need this
  36. complex of a cluster, and the primary usecase for this is for the
  37. Hosted Sentry on `getsentry.com <https://getsentry.com/>`_.
  38. For more typical, but still fairly high throughput setups, you can run off
  39. of a single machine as long as it has reasonable IO (ideally SSDs), and a
  40. good amount of memory.
  41. The main things you need to consider are:
  42. - TTL on events (how long do you need to keep historical data around)
  43. - Average event throughput
  44. - How many events get grouped together (which means they get sampled)
  45. At a point, getsentry.com was processing approximately 4 million events a
  46. day. A majority of this data is stored for 90 days, which accounted for
  47. around 1.5TB of SSDs. Web and worker nodes were commodity (8GB-12GB RAM,
  48. cheap SATA drives, 8 cores), the only two additional nodes were a
  49. dedicated RabbitMQ and Postgres instance (both on SSDs, 12GB-24GB of
  50. memory). In theory, given a single high-memory machine, with 16+ cores,
  51. and SSDs, you could handle the entirety of the given data set.
  52. Setting up an Environment
  53. -------------------------
  54. The first thing you'll need is the Python ``virtualenv`` package. You
  55. probably already have this, but if not, you can install it with::
  56. pip install -U virtualenv
  57. It's also available as ``python-virtualenv`` on ubuntu in the package
  58. manager.
  59. Once that's done, choose a location for the environment, and create it
  60. with the ``virtualenv`` command. For our guide, we're going to choose
  61. ``/www/sentry/``::
  62. virtualenv /www/sentry/
  63. Finally, activate your virtualenv::
  64. source /www/sentry/bin/activate
  65. .. note:: Activating the environment adjusts your ``PATH``, so that things
  66. like ``pip`` now install into the virtualenv by default.
  67. Install Sentry
  68. --------------
  69. Once you've got the environment setup, you can install Sentry and all its
  70. dependencies with the same command you used to grab virtualenv::
  71. pip install -U sentry
  72. Don't be worried by the amount of dependencies Sentry has. We have a
  73. philosophy of using the right tools for the job, and not reinventing them
  74. if they already exist.
  75. Once everything's installed, you should be able to execute the Sentry CLI,
  76. via ``sentry``, and get something like the following:
  77. .. code-block:: bash
  78. $ sentry
  79. Usage: sentry [OPTIONS] COMMAND [ARGS]...
  80. Sentry is cross-platform crash reporting built with love.
  81. Options:
  82. --config PATH Path to configuration files.
  83. --version Show the version and exit.
  84. --help Show this message and exit.
  85. Commands:
  86. celery Start background workers.
  87. cleanup Delete a portion of trailing data based on...
  88. config Manage runtime config options.
  89. createuser Create a new user.
  90. devserver Start a light Web server for development.
  91. django Execute Django subcommands.
  92. export Exports core metadata for the Sentry...
  93. help Show this message and exit.
  94. import Imports data from a Sentry export.
  95. init Initialize new configuration directory.
  96. repair Attempt to repair any invalid data.
  97. shell Run a Python interactive interpreter.
  98. start Start running a service.
  99. upgrade Perform any pending database migrations and...
  100. Installing from Source
  101. ~~~~~~~~~~~~~~~~~~~~~~
  102. If you're installing the Sentry source (e.g. from git), you'll also need
  103. to install ``npm``.
  104. Once your system is prepared, symlink your source into the virtualenv:
  105. .. code-block:: bash
  106. $ python setup.py develop
  107. .. Note:: This command will install npm dependencies as well as compile
  108. static assets.
  109. You can also use pip to directly install the package from GitHub:
  110. .. code-block:: bash
  111. $ pip install -e git+https://github.com/getsentry/sentry.git@master#egg=sentry-dev
  112. And more importantly, you can easily pin to a specific SHA:
  113. .. code-block:: bash
  114. $ pip install -e git+https://github.com/getsentry/sentry.git@___SHA___#egg=sentry-dev
  115. Initializing the Configuration
  116. ------------------------------
  117. Now you'll need to create the default configuration. To do this, you'll
  118. use the ``init`` command You can specify an alternative configuration path
  119. as the argument to init, otherwise it will use the default of
  120. ``~/.sentry``.
  121. ::
  122. # the path is optional
  123. sentry init /etc/sentry
  124. Starting with 8.0.0, ``init`` now creates two files, ``sentry.conf.py`` and
  125. ``config.yml``. To avoid confusion, ``config.yml`` will slowly be replacing
  126. ``sentry.conf.py``, but right now, the uses of ``config.yml`` are limited.
  127. The configuration inherits all of the server defaults, but you may need to
  128. change certain things, such as the database connection:
  129. ::
  130. # ~/.sentry/sentry.conf.py
  131. # for more information on DATABASES, see the Django configuration at:
  132. # https://docs.djangoproject.com/en/1.6/ref/databases/
  133. DATABASES = {
  134. 'default': {
  135. 'ENGINE': 'sentry.db.postgres',
  136. 'NAME': 'sentry',
  137. 'USER': 'postgres',
  138. 'PASSWORD': '',
  139. 'HOST': '',
  140. 'PORT': '',
  141. }
  142. }
  143. Configure Redis
  144. ---------------
  145. Redis is used as the default implementation for various backend services,
  146. including the time-series storage, SQL update buffers, and rate limiting.
  147. We recommend running two separate Redis clusters: one for persistent data
  148. (TSDB) and one for temporal data (buffers, rate limits). This is because
  149. you can configure the nodes in very different ones to enable more
  150. aggressive/optimized LRU.
  151. That said, if you're running a small install you can probably get away
  152. with just setting up the defaults in ``config.yml``:
  153. .. code-block:: yaml
  154. redis.clusters:
  155. default:
  156. hosts:
  157. 0:
  158. host: 127.0.0.1
  159. port: 6379
  160. # password: "my-secret-password"
  161. All built-in Redis implementations (other than the queue) will use these
  162. default settings, but each individual service also will allow you to
  163. override it's cluster settings by passing the name of the cluster to use as the
  164. ``cluster`` option.
  165. Cluster options are passed directly to rb (a Redis routing library) as keyword
  166. arguments to the ``Cluster`` constructor. A more thorough discussion of the
  167. availabile configuration parameters can be found at the `rb GitHub repository
  168. <https://github.com/getsentry/rb>`_.
  169. See the individual documentation for :doc:`the queue <queue/>`,
  170. :doc:`update buffers <buffer>`, :doc:`quotas <throttling>`, and
  171. :doc:`time-series storage <tsdb>` for more details.
  172. Configure Outbound Mail
  173. -----------------------
  174. Initially, you will be prompted to supply these values during our Installation
  175. Wizard, but you may wish to explicitly declare them in your config file. For
  176. the standard implementation, using a simple SMTP server, you can simply
  177. configure the following in ``config.yml``:
  178. .. code-block:: yaml
  179. mail.from: 'sentry@localhost'
  180. mail.host: 'localhost'
  181. mail.port: 25
  182. mail.username: ''
  183. mail.password: ''
  184. mail.use-tls: false
  185. Alternatively, if you want to disable email entirely, you could set:
  186. .. code-block:: yaml
  187. mail.backend: 'dummy'
  188. Running Migrations
  189. ------------------
  190. Sentry provides an easy way to run migrations on the database on version
  191. upgrades. Before running it for the first time you'll need to make sure
  192. you've created the database:
  193. .. code-block:: bash
  194. # If you kept the database ``NAME`` as ``sentry``
  195. $ createdb -E utf-8 sentry
  196. Once done, you can create the initial schema using the ``upgrade`` command:
  197. .. code-block:: bash
  198. $ SENTRY_CONF=/etc/sentry sentry upgrade
  199. Next up you'll need to create the first user, which will act as a superuser:
  200. .. code-block:: bash
  201. # create a new user
  202. $ SENTRY_CONF=/etc/sentry sentry createuser
  203. All schema changes and database upgrades are handled via the ``upgrade``
  204. command, and this is the first thing you'll want to run when upgrading to
  205. future versions of Sentry.
  206. .. note:: Internally this uses `South <http://south.readthedocs.io/en/latest/index.html>`_ to
  207. manage database migrations.
  208. Starting the Web Service
  209. ------------------------
  210. Sentry provides a built-in webserver (powered by uWSGI) to
  211. get you off the ground quickly, also you can setup Sentry as WSGI
  212. application, in that case skip to section `Running Sentry as WSGI
  213. application`.
  214. To start the built-in webserver run ``sentry run web``:
  215. ::
  216. SENTRY_CONF=/etc/sentry sentry run web
  217. You should now be able to test the web service by visiting `http://localhost:9000/`.
  218. Starting Background Workers
  219. ---------------------------
  220. A large amount of Sentry's work is managed via background workers. These need run
  221. in addition to the web service workers:
  222. ::
  223. SENTRY_CONF=/etc/sentry sentry celery worker
  224. See :doc:`queue` for more details on configuring workers.
  225. .. note:: `Celery <http://celeryproject.org/>`_ is an open source task
  226. framework for Python.
  227. Starting the Cron Process
  228. -------------------------
  229. Sentry also needs a cron process which is called "celery beat":
  230. ::
  231. SENTRY_CONF=/etc/sentry sentry celery beat
  232. It's recommended to only run one of them at the time or you will see
  233. unnecessary extra tasks being pushed onto the queues but the system will
  234. still behave as intended if multiple beat processes are run. This can be
  235. used to achieve high availability.
  236. Setup a Reverse Proxy
  237. ---------------------
  238. By default, Sentry runs on port 9000. Even if you change this, under
  239. normal conditions you won't be able to bind to port 80. To get around this
  240. (and to avoid running Sentry as a privileged user, which you shouldn't),
  241. we recommend you setup a simple web proxy.
  242. Proxying with Apache
  243. ~~~~~~~~~~~~~~~~~~~~
  244. Apache requires the use of mod_proxy for forwarding requests::
  245. ProxyPass / http://localhost:9000/
  246. ProxyPassReverse / http://localhost:9000/
  247. ProxyPreserveHost On
  248. RequestHeader set X-Forwarded-Proto "https" env=HTTPS
  249. You will need to enable ``headers``, ``proxy``, and ``proxy_http`` apache
  250. modules to use these settings.
  251. Proxying with Nginx
  252. ~~~~~~~~~~~~~~~~~~~
  253. You'll use the builtin HttpProxyModule within Nginx to handle proxying::
  254. location / {
  255. proxy_pass http://localhost:9000;
  256. proxy_redirect off;
  257. proxy_set_header Host $host;
  258. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  259. proxy_set_header X-Forwarded-Proto $scheme;
  260. }
  261. See :doc:`nginx` for more details on using Nginx.
  262. Enabling SSL
  263. ~~~~~~~~~~~~~
  264. If you are planning to use SSL, you will also need to ensure that you've
  265. enabled detection within the reverse proxy (see the instructions above), as
  266. well as within the Sentry configuration:
  267. .. code-block:: python
  268. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
  269. SESSION_COOKIE_SECURE = True
  270. CSRF_COOKIE_SECURE = True
  271. Running Sentry as a Service
  272. ---------------------------
  273. We recommend using whatever software you are most familiar with for
  274. managing Sentry processes. For us, that software of choice is `Supervisor
  275. <http://supervisord.org/>`_.
  276. Configure ``supervisord``
  277. ~~~~~~~~~~~~~~~~~~~~~~~~~
  278. Configuring Supervisor couldn't be more simple. Just point it to the
  279. ``sentry`` executable in your virtualenv's bin/ folder and you're good to
  280. go.
  281. ::
  282. [program:sentry-web]
  283. directory=/www/sentry/
  284. environment=SENTRY_CONF="/etc/sentry"
  285. command=/www/sentry/bin/sentry start
  286. autostart=true
  287. autorestart=true
  288. redirect_stderr=true
  289. stdout_logfile=syslog
  290. stderr_logfile=syslog
  291. [program:sentry-worker]
  292. directory=/www/sentry/
  293. environment=SENTRY_CONF="/etc/sentry"
  294. command=/www/sentry/bin/sentry celery worker
  295. autostart=true
  296. autorestart=true
  297. redirect_stderr=true
  298. stdout_logfile=syslog
  299. stderr_logfile=syslog
  300. [program:sentry-cron]
  301. directory=/www/sentry/
  302. environment=SENTRY_CONF="/etc/sentry"
  303. command=/www/sentry/bin/sentry celery beat
  304. autostart=true
  305. autorestart=true
  306. redirect_stderr=true
  307. stdout_logfile=syslog
  308. stderr_logfile=syslog
  309. Removing Old Data
  310. -----------------
  311. One of the most important things you're going to need to be aware of is
  312. storage costs. You'll want to setup a cron job that runs to automatically
  313. trim stale data. This won't guarantee space is reclaimed (i.e. by SQL),
  314. but it will try to minimize the footprint. This task is designed to run
  315. under various environments so it doesn't delete things in the most optimal
  316. way possible, but as long as you run it routinely (i.e. daily) you should
  317. be fine.
  318. .. code-block:: bash
  319. $ crontab -e
  320. 0 3 * * * sentry cleanup --days=30
  321. What's Next?
  322. ------------
  323. At this point you should have a fully functional installation of Sentry. You
  324. may want to explore :doc:`various plugins <plugins>` available.