CentOS 7 部署 Sentry

由于工作需要,需要部署一套Sentry环境用来统计前端的报错,遇到了很多坑,将部署的正确姿势记录下来,留作备份。

更新yum源

1
2
3
4
5
6
7
8
# 1. 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 2. 添加
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 或
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 3.生成缓存
yum makecache

Docker相关

docker-ce

卸载旧版Docker

因为我装了一个比较低版本的docker,所以要先卸载

1
2
3
4
$ yum list installed | grep docker 

## remove掉列出来的docker相关
$ yum remove [docker]

安装最新版Docker

1
2
3
4
5
6
7
8
9
10
11
12
$ curl -fsSL https://get.docker.com/ | sh

# centos 7
$ systemctl restart docker # 启动服务
$ systemctl enable docker # 开机启动

# centos 6
$ service docker restart # 启动服务
$ chkconfig docker on # 开机启动

# 查看安Docker版本
$ docker version # docker -v

安装Docker-compose

https://github.com/docker/compose/releases

去这个链接找到最新的安装脚本,比如

1
2
curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Sentry 相关

clone代码

https://github.com/getsentry/onpremise

部署Sentry

按照Up and Running步骤来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 1. 创建数据卷
docker volume create --name=sentry-data && docker volume create --name=sentry-postgres

# 2. 生成.env
cp -n .env.example .env

# 3. 构建
docker-compose build

# 4. 生成secret-key 并且将生成的key加入到.env文件
docker-compose run --rm web config generate-secret-key

# 5. 运行,这最后可以创建一个超级管理员用户
docker-compose run --rm web upgrade

# 6. 启动
docker-compose up -d

# 7. 访问
localhost:9000

其他命令

创建用户

1
docker-compose run --rm web createuser

查看日志

1
2
3
4
docker-compose logs web

## 实时日志
docker-compose logs --tail="1000" -f web

进入容器

1
docker-compose exec web bash

LDAP 相关

https://github.com/Banno/getsentry-ldap-auth

增加LDAP配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
###########
# LDAP/AD #
###########

import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfUniqueNamesType

AUTH_LDAP_SERVER_URI = 'ldap://example'
AUTH_LDAP_BIND_DN = 'cn=readuser,ou=ex,dc=example,dc=com'
AUTH_LDAP_BIND_PASSWORD = 'example'
OU=unicode('dc=example,dc=com', 'utf8')
AUTH_LDAP_USER_SEARCH = LDAPSearch(
OU,
ldap.SCOPE_SUBTREE,
'(cn=%(user)s)',
)

AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
'',
ldap.SCOPE_SUBTREE,
'(objectClass=groupOfUniqueNames)'
)

AUTH_LDAP_GROUP_TYPE = GroupOfUniqueNamesType()
AUTH_LDAP_REQUIRE_GROUP = None
AUTH_LDAP_DENY_GROUP = None

AUTH_LDAP_USER_ATTR_MAP = {
'name': 'cn',
'email': 'email'
}

AUTH_LDAP_FIND_GROUP_PERMS = False
AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600

AUTH_LDAP_DEFAULT_SENTRY_ORGANIZATION = u'sentry'
AUTH_LDAP_SENTRY_ORGANIZATION_ROLE_TYPE = 'member'
AUTH_LDAP_SENTRY_ORGANIZATION_GLOBAL_ACCESS = True
AUTH_LDAP_SENTRY_USERNAME_FIELD = 'uid'

AUTHENTICATION_BACKENDS = AUTHENTICATION_BACKENDS + (
'sentry_ldap_auth.backend.SentryLdapBackend',
)

安装依赖

更新容器apt

进入容器

1
docker-compose exec web bash

因为容器内很干净,所以安装vim来编辑

1
apt install vim

查看Linux版本,可以看出是 Debian 9

1
2
3
cat /etc/issue

Debian GNU/Linux 9 \n \l

更新apt源,在/etc/apt/sources.list新增

1
2
3
4
5
6
deb http://mirrors.aliyun.com/debian stretch main contrib non-free
deb-src http://mirrors.aliyun.com/debian stretch main contrib non-free
deb http://mirrors.aliyun.com/debian stretch-updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian stretch-updates main contrib non-free
deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free

update

1
apt-get update

修改Dockerfile

修改Dockerfile文件,在下面加入

1
2
RUN apt-get update && apt-get install -y libsasl2-dev python-dev libldap2-dev libssl-dev
RUN pip install sentry-ldap-auth

sentry-ldap-auth作者推荐将插件加入到requirements.txt里面,但是这样会有问题,不要尝试

重启Sentry服务

分别执行上面3567步骤登录的时候就可以用ldap账户登录了,但是登陆进去没有组织

参考

  1. Centos安装最新版Docker CE、Docker-Compose
  2. Debian9换源(阿里源)(Linux子系统)