Sentry部署
前期准备
[root@Aaron ~]# uname -r
3.10.0-327.el7.x86_64
[root@Aaron ~]# uname -a
Linux Aaron 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@Aaron ~]# python -V
Python 2.7.5
[root@Aaron ~]# pip -V
pip 9.0.1 from /usr/lib/python2.7/site-packages (python 2.7)
创建虚拟环境
[root@Aaron ~]# pip install -U virtualenv
[root@Aaron ~]# virtualenv /www/sentry/
[root@Aaron ~]# source /www/sentry/bin/activate
(sentry) [root@Aaron ~]#
安装sentry
这里sentry官网推荐postgres,因为我之前没使用过postgres,折腾了一会,感觉非常难受,所以最终选择mysql5.7,用哪个数据库都一样,只要在sentry.conf.py文件配置好就行。
安装redis
(sentry) [root@Aaron ~]# yum install redis
(sentry) [root@Aaron sentry]# systemctl start redis
(sentry) [root@Aaron sentry]# systemctl status redis
安装mysql
(sentry) [root@Aaron sentry]# yum install mysql-devel
(sentry) [root@Aaron sentry]# pip install mysqlclient
(sentry) [root@Aaron sentry]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
(sentry) [root@Aaron sentry]# yum -y install mysql57-community-release-el7-10.noarch.rpm
(sentry) [root@Aaron sentry]# yum -y install mysql-community-server
(sentry) [root@Aaron sentry]# systemctl start mysqld.service
(sentry) [root@Aaron sentry]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2018-11-06 10:47:51 CST; 6s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4775 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4698 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4779 (mysqld)
CGroup: /system.slice/mysqld.service
└─4779 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
11月 06 10:47:47 Aaron systemd[1]: Starting MySQL Server...
11月 06 10:47:51 Aaron systemd[1]: Started MySQL Server.
(sentry) [root@Aaron sentry]# grep "password" /var/log/mysqld.log
2018-11-06T02:47:48.394158Z 1 [Note] A temporary password is generated for root@localhost: wbP&Wms*p0y9
(sentry) [root@Aaron sentry]# mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY ‘Root.123456';
这里我就顺便把sentry数据库给创建了
mysql> create database sentry;
Query OK, 1 row affected (0.00 sec)
我这里图方便,直接yum安装了
没有安装redis执行pip install -U sentry会报错
redis-py-cluster 1.3.5 has requirement redis>=2.10.6, but you'll have redis 2.10.5 which is incompatible.
一定要先安装好redis和mysql,并且启动redis和mysql
(sentry) [root@Aaron ~]# yum install -y python-devel
(sentry) [root@Aaron ~]# pip install -U sentry
如果觉得慢,使用豆瓣源
pip install -i https://pypi.douban.com/simple/ sentry
(sentry) [root@Aaron ~]# mkdir $HOME/sentry/
(sentry) [root@Aaron ~]# echo "export SENTRY_CONF=$HOME/sentry/" >> ~/.bash_profile
(sentry) [root@Aaron ~]# source ~/.bash_profile
(sentry) [root@Aaron ~]# sentry init $HOME/sentry/
(sentry) [root@Aaron ~]# cd ~/sentry/
(sentry) [root@Aaron sentry]# ls
config.yml sentry.conf.py
修改config.yml
[root@Aaron sentry]# cat config.yml|grep -v "^#"| grep -v "^$"
mail.backend: 'dummy' # Use dummy if you want to disable email entirely
system.secret-key: '(tn%ksnk&(%uxcsh_=3(wf%0upe)w(b0o02morvw)nvoj@6e#0'
redis.clusters:
default:
hosts:
0:
host: 127.0.0.1
port: 6379
filestore.backend: 'filesystem'
filestore.options:
location: '/tmp/sentry-files'
修改sentry.conf.py
[root@Aaron sentry]# cat sentry.conf.py|grep -v "^#"| grep -v "^$"
from sentry.conf.server import *
import os.path
CONF_ROOT = os.path.dirname(__file__)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sentry',
'USER': 'root',
'PASSWORD': 'Root.123456',
'HOST': 'localhost',
'PORT': '3306',
'AUTOCOMMIT': True,
'ATOMIC_REQUESTS': False,
}
}
SENTRY_USE_BIG_INTS = True
SENTRY_SINGLE_ORGANIZATION = True
DEBUG = False
SENTRY_CACHE = 'sentry.cache.redis.RedisCache'
BROKER_URL = 'redis://localhost:6379'
SENTRY_RATELIMITER = 'sentry.ratelimits.redis.RedisRateLimiter'
SENTRY_BUFFER = 'sentry.buffer.redis.RedisBuffer'
SENTRY_QUOTAS = 'sentry.quotas.redis.RedisQuota'
SENTRY_TSDB = 'sentry.tsdb.redis.RedisTSDB'
SENTRY_DIGESTS = 'sentry.digests.backends.redis.RedisBackend'
SENTRY_WEB_HOST = '0.0.0.0'
SENTRY_WEB_PORT = 9000
SENTRY_WEB_OPTIONS = {
# 'workers': 3, # the number of web workers
# 'protocol': 'uwsgi', # Enable uwsgi protocol instead of http
}
(sentry) [root@Aaron sentry]# sentry upgrade
(sentry) [root@Aaron sentry]# sentry run web
然后访问ip:9000