您的位置:首页 > 其它

Install Sentry Server(Sentry Server的搭建)[for_wind]

2016-05-12 00:10 471 查看

Why use sentry?

Sentry1 is a modern error logging and aggregation platform.

The Sentry package fundamentally is just a simple server and web UI. It will handle authenticating clients (such as Raven) and all of the logic behind storage and aggregation.

Sentry2 is not limited to Python. The primary implementation is in Python, but it contains a full API for sending events from any language, in any application.

How to Setup Sentry Server?

The Sentry Server is the core Python application that powers all of the Sentry installations.

This guide will step you through setting up a Python-based virtualenv, installing the required packages, and configuring the basic web service.3

Here I will give some more detailed steps.You can find more information from Sentry official website.

Operating system

A UNIX-based operating system. We test on Ubuntu and this documentation assumes an ubuntu based system.

Dependencies

You could find the latest dependency from from here.

Python 2.7

https://www.python.org/downloads/

Redis

Install redis

find latest version from http://download.redis.io/releases/

try the following commands.

$ wget http://download.redis.io/releases/redis-3.0.6.tar.gz $ tar xzf redis-3.0.6.tar.gz
$ cd redis-3.0.6
$ make


Run redis

$ src/redis-server


save problem: try
sudo vim redis.conf
, and find “dir ./ “. The default value is: ./ and change it to “/root/path/to/dir/with/write/access/”

Note that you must specify a directory here, not a file name.

dir /root/path/to/dir/with/write/access/

Postgresql

Install postgresql

try this command:

apt-get install postgresql-9.4


if it does not work, try to use the PostgreSQL Apt Repository. and try the following method. You can get more detail from here and its wiki.

(You may determine the codename of your distribution by running lsb_release -c). For a shorthand version of the above, presuming you are using a supported release:

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'


Import the repository key from https://www.postgresql.org/media/keys/ACCC4CF8.asc , update the package lists, and start installing packages:

sudo apt-get install wget ca-certificates

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install postgresql-9.4 pgadmin3


Other Dependencies

install python-setuptools, python-pip, python-dev, libxslt1-dev, libxml2-dev, libz-dev, libffi-dev, libssl-dev, libssl-dev, libpq-dev, libyaml-dev.

sudo apt-get install python-setuptools python-pip  python-dev  libxslt1-dev libxml2-dev libz-dev libffi-dev  libssl-dev  libpq-dev  libyaml-dev

sudo apt-get install nginx


Setting up an Environment

Install Virtualenv

pip install -U virtualenv


Setup enviroment and activate

Once that is done, choose a location for the environment, and create it with the virtualenv command. For our guide, we’re going to choose /www/sentry/:

sudo mkdir -p /www/sentry/
virtualenv /www/sentry/


Finally, activate your virtualenv:

source /www/sentry/bin/activate


Install Sentry

Once you’re got the environment setup, you can install Sentry and all its dependencies with the same command you used to grab virtualenv:

pip install -U sentry


Initializing the Configuration

Now you’l need to create the default configuration. To do this, you’l use the init command You can specify an alternative configuration path as the argument to init, otherwise it will use the default of ~/.sentry.

# the path is optional
sentry init /www/sentry/


Running Migrations

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

# If you're using Postgres, and kept the database ``NAME`` as ``sentrydb``
sudo -u postgres psql
create user "<admin>" with password '<password>';
create database "sentrydb" with owner="<admin>";
\q


Once done, you can create the initial schema using the upgrade command:

$ SENTRY_CONF=/www/sentry/sentry.conf.py sentry upgrade


During the upgrade, You can create the first user.

If not,next up you’l need to create the first user, which will act as a superuser:

# create a new user
$ SENTRY_CONF=/www/sentry/sentry.conf.py sentry createuser


Configure Sentry

sudo vim /www/sentry/sentry.conf.py


Here is my configuration of sentry for test. You can find more support from Sentry Official website4.

Note line 12,13,14,15,155,156,158,171,172,173,174

# This file is just Python, with a touch of Django which means
# you can inherit and tweak settings to your hearts content.
from sentry.conf.server import *

import os.path

CONF_ROOT = os.path.dirname(__file__)

DATABASES = {
'default': {
'ENGINE': 'sentry.db.postgres',
'NAME': 'sentrydb',
'USER': '<admin>',
'PASSWORD': '<password>',
'HOST': '127.0.0.1',
'PORT': '',
}
}

# You should not change this setting after your database has been created
# unless you have altered all schemas first
SENTRY_USE_BIG_INTS = True

# If you're expecting any kind of real traffic on Sentry, we highly recommend
# configuring the CACHES and Redis settings

###########
# General #
###########

# Instruct Sentry that this install intends to be run by a single organization
# and thus various UI optimizations should be enabled.
SENTRY_SINGLE_ORGANIZATION = True

#########
# Redis #
#########

# Generic Redis configuration used as defaults for various things including:
# Buffers, Quotas, TSDB

SENTRY_REDIS_OPTIONS = {
'hosts': {
0: {
'host': '127.0.0.1',
'port': 6379,
}
}
}

#########
# Cache #
#########

# Sentry currently utilizes two separate mechanisms. While CACHES is not a
# requirement, it will optimize several high throughput patterns.

# If you wish to use memcached, install the dependencies and adjust the config
# as shown:
#
#   pip install python-memcached
#
# CACHES = {
#     'default': {
#         'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
#         'LOCATION': ['127.0.0.1:11211'],
#     }
# }

# A primary cache is required for things such as processing events
SENTRY_CACHE = 'sentry.cache.redis.RedisCache'

#########
# Queue #
#########

# See https://docs.getsentry.com/on-premise/server/queue/ for more
# information on configuring your queue broker and workers. Sentry relies
# on a Python framework called Celery to manage queues.

CELERY_ALWAYS_EAGER = False
BROKER_URL = 'redis://localhost:6379'

###############
# Rate Limits #
###############

# Rate limits apply to notification handlers and are enforced per-project
# automatically.

SENTRY_RATELIMITER = 'sentry.ratelimits.redis.RedisRateLimiter'

##################
# Update Buffers #
##################

# Buffers (combined with queueing) act as an intermediate layer between the
# database and the storage API. They will greatly improve efficiency on large
# numbers of the same events being sent to the API in a short amount of time.
# (read: if you send any kind of real data to Sentry, you should enable buffers)

SENTRY_BUFFER = 'sentry.buffer.redis.RedisBuffer'

##########
# Quotas #
##########

# Quotas allow you to rate limit individual projects or the Sentry install as
# a whole.

SENTRY_QUOTAS = 'sentry.quotas.redis.RedisQuota'

########
# TSDB #
########

# The TSDB is used for building charts as well as making things like per-rate
# alerts possible.

SENTRY_TSDB = 'sentry.tsdb.redis.RedisTSDB'

###########
# Digests #
###########

# The digest backend powers notification summaries.

SENTRY_DIGESTS = 'sentry.digests.backends.redis.RedisBackend'

################
# File storage #
################

# Any Django storage backend is compatible with Sentry. For more solutions see
# the django-storages package: https://django-storages.readthedocs.org/en/latest/ 
SENTRY_FILESTORE = 'django.core.files.storage.FileSystemStorage'
SENTRY_FILESTORE_OPTIONS = {
'location': '/tmp/sentry-files',
}

##############
# Web Server #
##############

# If you're using a reverse SSL proxy, you should enable the X-Forwarded-Proto
# header and uncomment the following settings
# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# SESSION_COOKIE_SECURE = True

# If you're not hosting at the root of your web server, and not using uWSGI,
# you need to uncomment and set it to the path where Sentry is hosted.
# FORCE_SCRIPT_NAME = '/sentry'

SENTRY_WEB_HOST = '<YY.YY.YY.YY>' #your machine ip
SENTRY_WEB_PORT = 9000
SENTRY_WEB_OPTIONS = {
'workers': 3,  # the number of gunicorn workers
# 'secure_scheme_headers': {'X-FORWARDED-PROTO': 'https'},
}

###############
# Mail Server #
###############

# For more information check Django's documentation:
# https://docs.djangoproject.com/en/1.6/topics/email/ 
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_HOST = '<XX.XX.XX.XX>'
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = 'XXXX@XXX.com'
EMAIL_PORT = 25
EMAIL_USE_TLS = False

# The email address to send on behalf of
SERVER_EMAIL = 'SSSS@XX.com'

# If you're using mailgun for inbound mail, set your API key and configure a
# route to forward to /api/hooks/mailgun/inbound/
MAILGUN_API_KEY = ''


Starting the Web Service

sudo sentry --config=/www/sentry/sentry.conf.py start


You should now be able to test the web service by visiting http://localhost:9000/

Using supervisor

Install supervisor

sudo pip install supervisor -U


Configure

create a sample supervisor config file.

sudo echo_supervisord_conf > /etc/supervisord.conf


or try this

#echo to some file and then copy to ...
echo_supervisord_conf > supervisord.conf


Edit

sudo vim supervisord.conf


add the following content:

[program:sentry-web]
directory=/www/sentry/
command=sentry start
autostart=true
autorestart=true
redirect_stderr=true
stopasgroup=true
killasgroup=true
environment=SENTRY_CONF="/www/sentry/sentry.conf.py"

[program:sentry-worker]
directory=/www/sentry/
command=sentry celery worker -B -l INFO
autostart=true
autorestart=true
redirect_stderr=true
stopasgroup=false
killasgroup=true
environment=SENTRY_CONF="/www/sentry/sentry.conf.py",C_FORCE_ROOT="true"

[program:sentry-cron]
directory=/www/sentry/
command=sentry celery beat
autostart=true
autorestart=true
redirect_stderr=true
killasgroup=true
environment=SENTRY_CONF="/www/sentry/sentry.conf.py"


unComent #18~21 line and change username and password

[inet_http_server]         ; inet (TCP) server disabled by default
port=127.0.0.1:9001        ; (ip_address:port specifier, *:port for all iface)
username=user              ; (default is no username (open server))
password=123               ; (default is no password (open server))


save /etc/supervisord.conf, and start superviord(see below). Now you can browse from http://127.0.0.1:9001

Running Supervisor

Start supervior

Now you can simply run the following command to start sentry web service, sentry worker and redis-server.

sudo supervisord  -c /etc/supervisord.conf


Stop supervior

sudo supervisorctl -c /etc/supervisord.conf stop all


sudo supervisorctl -c /etc/supervisord.conf shutdown


Summery

学习了一下错误记录集中管理平台Sentry的搭建。把安装server部分的重要过程和遇到问题记录了一下。具体细节请看官网吧。

安装好Sentry server后,客户端代码中只要插入相应的简单代码,就可以快速实现错误的记录和管理。在最新版本中已经加入了人员的管理和任务管理,不要太赞啊。。快来试试吧。

最好先update一下系统,然后再安装依赖的软件。这样一路通畅。哈哈哈

在配置supervior之前,最好先简单测试一下server的基本情况。在redis跑起来后,手动跑一下sentry start 那个命令。

写完成了,撒花。。。撒花。。。我真乖。//for_wind

http://sentry.readthedocs.org/
https://github.com/getsentry/sentry/
http://sentry.readthedocs.org/en/latest/installation.html
http://sentry.readthedocs.org/en/latest/installation.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Sentry server