第四百零五节,centos7下搭建sentry错误日志服务器,接收python以及Django错误,
注意:版本,不然会报错
Docker >=1.11
Compose >1.6.0
通过docker安装sentry
安装docker
1.卸载旧版本
sudo yum remove docker docker-common docker-selinux docker-engine
2.安装依赖包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
3.添加稳定的源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装docker ce
1.更新yum包
sudo yum makecache fast
2.安装docker ce
sudo yum install docker-ce
3.启动docker
sudo systemctl start docker
4.测试docker
sudo docker run hello-world 输出: Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
安装docker-compose
1. sudo yum install epel-release 2. sudo yum install -y python-pip 3. sudo pip install docker-compose
安装sentry
sentry 依赖的组件比较多 包括 redis、 postgresql、 outbound email
在安装sentry前请确保 docker 版本大于1.10
1.安装git
sudo yum install git
2.下载docker镜像并构建容器
cd进入到要安装的目录,创建一个程序目录
mkdir -p data/{sentry,postgres}
3.下载onpremise-master项目,放在与刚才创建的data目录同级
两者选一即可
下载地址:https://github.com/getsentry/onpremise
也可以不用下载进行克隆
sudo yum install git
$ git clone https://github.com/getsentry/onpremise.git
$ cd onpremise
4.cd onpremise,进入到onpremise-master项目,执行命令生成key
注意:以下所有的目录,都是要在onpremise下执行的
docker-compose run --rm web config generate-secret-key
复制生成的key写入到docker-compose.yml文件
vim docker-compose.yml
5.生成数据表
docker-compose run --rm web upgrade
6.启动项目,在9000端口,如果是阿里云服务器记得开放端口
docker-compose up -d
访问服务器ip加9000端口
可以看到是英文的
首先要改成中文
1
2
以后启动项目
首先启动docker
sudo systemctl start docker
然后cd进入到onpremise下执行
docker-compose up -d
错误日志监控配置
python脚本监控
选择监控类型
python监控
#!/usr/bin/env python # -*- coding:utf8 -*- from raven import Client # 设置dns的key client = Client('http://f77284e1694144319ff6e27cf1cf9ae3:dd866ea1b3c34604ad9717deca56c320@47.52.39.160:9000/14') try: 1 / 0 except ZeroDivisionError: # 获取错误推送到错误监控 client.captureException()
监控
Docker监控
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app1', 'social_django', 'raven.contrib.django.raven_compat', # 配置监控APP ] # 配置监控配置 RAVEN_CONFIG = { 'dsn': 'http://5def24308c64410fab2f8f4dda116195:619079b681ee4fb599ab62db4da8524f@47.52.39.160:9000/15', }