溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

sentry日志管理系統(tǒng)安裝以及使用教程

發(fā)布時(shí)間:2020-06-18 17:23:20 來源:網(wǎng)絡(luò) 閱讀:12318 作者:AndyMac 欄目:建站服務(wù)器

Sentry 是一個(gè)開源的實(shí)時(shí)錯(cuò)誤報(bào)告工具,支持 web 前后端、移動(dòng)應(yīng)用以及游戲,支持 Python、OC、Java、Go、Node、Django、RoR 等主流編程語言和框架 ,還提供了 GitHub、Slack、Trello 等常見開發(fā)工具的集成。

github地址

一、環(huán)境準(zhǔn)備

環(huán)境 說明
ubuntu16.04 ip: 10.211.55.14

二、安裝必備組件

1. 安裝PostgreSQL

1. apt 安裝
sudo apt-get -y install postgresql postgresql-contrib
2. 修改Postgres角色的密碼
> sudo su
> su - postgres
> psql

輸入:

postgres =# \password #修改當(dāng)前用戶密碼
Enter new password:
Enter it again:
postgres =# \q # 退出

運(yùn)行exit離開postgres用戶

2. 安裝redis

1. 安裝
> sudo wget http://download.redis.io/releases/redis-3.2.6.tar.gz
> sudo tar -zxvf redis-3.2.6.tar.gz
> sudo cp -rf redis-3.2.6 /usr/local/redis
> cd /usr/local/redis
> sudo apt install gcc
> sudo make
> sudo make install

如果提示make test, 則輸入make test

2. 啟動(dòng)

運(yùn)行redis-server 啟動(dòng)redis

3. 安裝python, pip, 以及其他環(huán)境

1. 安裝系統(tǒng)組件
sudo apt install python-setuptools python-dev libxslt1-dev gcc libffi-dev libjpeg-dev libxml2-dev libxslt-dev libyaml-dev libpq-dev
2. 安裝pip

下載get-pip.py

> wget "https://bootstrap.pypa.io/get-pip.py"
> sudo python get-pip.py
3. 安裝python庫
> pip install -U virtualenv

三、安裝sentry

1. 創(chuàng)建虛擬環(huán)境

> sudo mkdir /var/www
> sudo chmod -R 777 /var/www
> cd /var/www/
> mkdir sentry
> cd sentry
> virtualenv venv

2. 安裝sentry

> source venv/bin/activate
> pip install -U sentry
> sentry
Usage: sentry [OPTIONS] COMMAND [ARGS]...

  Sentry is cross-platform crash reporting built with love.

  The configuration file is looked up in the `~/.sentry` config directory but this can
  be overridden with the `SENTRY_CONF` environment variable or be explicitly provided
  through the `--config` parameter.

Options:
  --config PATH  Path to configuration files.
  --version      Show the version and exit.
  --help         Show this message and exit.

Commands:
  celery      DEPRECATED see `sentry run` instead.
  cleanup     Delete a portion of trailing data based on...
  config      Manage runtime config options.
  createuser  Create a new user.
  devserver   Starts a lightweight web server for...
  django      Execute Django subcommands.
  dsym        Manage system symbols in Sentry.
  export      Exports core metadata for the Sentry...
  files       Manage files from filestore.
  help        Show this message and exit.
  import      Imports data from a Sentry export.
  init        Initialize new configuration directory.
  plugins     Manage Sentry plugins.
  queues      Manage Sentry queues.
  repair      Attempt to repair any invalid data.
  run         Run a service.
  shell       Run a Python interactive interpreter.
  start       DEPRECATED see `sentry run` instead.
  tsdb        Tools for interacting with the time series...
  upgrade     Perform any pending database migrations and...

四、配置sentry

1. 初始化

sentry init 配置文件路徑

> sentry init /var/www/sentry/conf

2. 修改postgreSQL的連接賬號密碼

打開/var/www/sentry/conf/sentry.conf.py

修改下面這段

DATABASES = {
    'default': {
        'ENGINE': 'sentry.db.postgres',
        'NAME': 'sentry',
        'USER': 'postgres',
        'PASSWORD': '123123', # 剛才安裝完postgreSQL 后你設(shè)置的密碼
        'HOST': '',
        'PORT': '',
        'AUTOCOMMIT': True,
        'ATOMIC_REQUESTS': False,
    }
}

3. 初始化數(shù)據(jù)并且創(chuàng)建用戶

> createdb -E utf-8 sentry

如果提示createdb: could not connect to database template1: FATAL: role "lin" does not exist

則切換到postgre用戶執(zhí)行

執(zhí)行

SENTRY_CONF=/var/www/sentry/conf/ sentry upgrade

如果提示OperationalError: FATAL: Peer authentication failed for user "postgres"

解決方案:

  1. sudo vim /etc/postgresql/9.5/main/pg_hba.conf
  2. 修改
    
    local   all             postgres                                peer

TYPE DATABASE USER ADDRESS METHOD

"local" is for Unix domain socket connections only

local all all peer

IPv4 local connections:

host all all 127.0.0.1/32 md5

IPv6 local connections:

host all all ::1/128 md5

local all postgres md5

TYPE DATABASE USER ADDRESS METHOD

"local" is for Unix domain socket connections only

local all all peer

IPv4 local connections:

host all all 127.0.0.1/32 md5

IPv6 local connections:

host all all ::1/128 md5

3. 重啟postgresql

sudo service postgresql restart


再次執(zhí)行

SENTRY_CONF=/var/www/sentry/conf/ sentry upgrade


如果提示`sentry.exceptions.InvalidConfiguration: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.`

解決方案:
1. 進(jìn)入redis redis-cli
2. 執(zhí)行

config set stop-writes-on-bgsave-error no


再次執(zhí)行

再次執(zhí)行 SENTRY_CONF=/var/www/sentry/conf/ sentry upgrade


在這一步執(zhí)行完成后可能提示你是否要?jiǎng)?chuàng)建用戶,則按照要求創(chuàng)建用戶即可, 沒有提示的話執(zhí)行以下語句創(chuàng)建

SENTRY_CONF=/var/www/sentry/conf/ sentry createuser


## 五、運(yùn)行服務(wù)

SENTRY_CONF=/var/www/sentry/conf/ sentry run web # 運(yùn)行web服務(wù)
SENTRY_CONF=/var/www/sentry/conf/ sentry run worker # 運(yùn)行日志搜集進(jìn)程

SENTRY_CONF=/var/www/sentry/conf/ sentry run cron # 啟動(dòng)cron進(jìn)程

六、配置項(xiàng)目

  1. 瀏覽器打開sentry的web管理, http://ip:9000
  2. 輸入剛才設(shè)置的賬號密碼
  3. 點(diǎn)擊New Project創(chuàng)建一個(gè)項(xiàng)目
  4. 平臺選擇php, 輸入項(xiàng)目的名稱, 點(diǎn)擊創(chuàng)建
  5. 跳轉(zhuǎn)的頁面會顯示連接的代碼
  6. 測試錯(cuò)誤
    
    <?php
    require_once 'vendor/autoload.php';
    Raven_Autoloader::register();

這里替換成你自己的項(xiàng)目id, 在顯示連接幫助的頁面

$client = new Raven_Client('http://f2c047b856bb41fcbf486f467b7fcf5b:aa2a33c7176d4c1fb86a3aa8cb4728aa@10.211.55.14:9000/1');

$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerExceptionHandler();
$error_handler->registerErrorHandler();
$error_handler->registerShutdownFunction();

set_error_handler(array($error_handler, 'handleError'));
set_exception_handler(array($error_handler, 'handleException'));

$client->captureMessage("這里發(fā)生了一個(gè)錯(cuò)誤");

$i = 1 / 0;


運(yùn)行以后, 查看web端, 就會看到傳輸回來的錯(cuò)誤了。

-----
![](https://cache.yisu.com/upload/information/20200309/32/29755.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI