利用docker搭建http服务器_搭建docker镜像仓库

(86) 2024-07-09 21:01:01

一、简介

sentry是一款错误日志收集平台,可以将代码错误信息进行收集。

平常我们开发完成以后,发现问题的手段仅自测-》测试人员-》最后市场反馈。一般我们收到市场反馈的时候已经产生了事故,作为一个合格的程序猿,如果默默等着市场提问题肯定是不够滴!

sentry就非常贴心的帮助我们收集了所有的错误异常(注意不是日志!)
 

利用docker搭建http服务器_搭建docker镜像仓库 (https://mushiming.com/)  第1张

二、安装Sentry

1、安装Docker以及相关依赖

配置yum源

sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin 

2、添加国内镜像

sudo yum install -y yum-utils sudo yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

3、启动Docker后台服务

systemctl start docker 

4、设置开机启动

systemctl enable docker 

5、查看Docker版本

docker --version 

6、查看Docker compose版本

docker compose version 

三、安装git

yum install git 

 下载onpremise

git clone https://github.com/getsentry/onpremise.git 这个是旧的 git https://github.com/getsentry/self-hosted.git 这个是新仓库 两个地址可以拉取,网上大多数都是旧的,后面估计仓库迁移了,但旧的也能用。 

四、给sentry配置https

1、修改nginx.conf

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
                worker_connections 1024;
}



http {
  # set REMOTE_ADDR from any internal proxies
  # see http://nginx.org/en/docs/http/ngx_http_realip_module.html
  set_real_ip_from 127.0.0.1;
  set_real_ip_from 10.0.0.0/8;
  real_ip_header X-Forwarded-For;
  real_ip_recursive on;
 
  # SSL configuration -- change these certs to match yours
  ssl_certificate      /etc/nginx/pinyiche.club_bundle.crt;
  ssl_certificate_key  /etc/nginx/pinyiche.club.key;
 
  # NOTE: These settings may not be the most-current recommended
  # defaults
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:128m;
  ssl_session_timeout 10m;
 
  server {
    listen   80;
    server_name  sentry.pinyiche.club; 
    location / {
      if ($request_method = GET) {
        rewrite  ^ https://$host$request_uri? permanent;
      }
      return 405;
    }
  }
 
  server {
    listen   443 ssl;
    server_name  sentry.pinyiche.club;
    proxy_set_header   Host                 $http_host;
    proxy_set_header   X-Forwarded-Proto    $scheme;
    proxy_set_header   X-Forwarded-For      $remote_addr;
    proxy_redirect     off;
 
    # keepalive + raven.js is a disaster
    keepalive_timeout 0;
 
    # use very aggressive timeouts
    proxy_read_timeout 5s;
    proxy_send_timeout 5s;
    send_timeout 5s;
    resolver_timeout 5s;
    client_body_timeout 5s;
 
    # buffer larger messages
    client_max_body_size 5m;
    client_body_buffer_size 100k;
 
    location /api/store/ {
              proxy_pass http://relay:3000;
     }
     location ~ ^/api/[1-9]\d*/ {
              proxy_pass http://relay:3000;
     }
     location / {
              proxy_pass http://web:9000;
     }

      add_header Strict-Transport-Security "max-age=31536000";
  }
}

为了能加入https要将配置文件放到指定位置

/data/onpremise/nginx

利用docker搭建http服务器_搭建docker镜像仓库 (https://mushiming.com/)  第2张

2、修改 onpremise/sentry/config.yml system.url-prefix 配置,将其设置为我们访问的 Sentry 域名。 url-prefix 组成了项目的 DSN 地址,一定要保证格式正确。

利用docker搭建http服务器_搭建docker镜像仓库 (https://mushiming.com/)  第3张 3、onpremise/sentry/sentry.conf.py 文件下的 SSL/TLS 配置,将原来注释的部分全部打开。

利用docker搭建http服务器_搭建docker镜像仓库 (https://mushiming.com/)  第4张

4、更新配置(会删除容器重新创建)

docker compose down docker compose up -d

五、初始化项目

import * as Sentry from "@sentry/browser"; Sentry.init({ dsn: "https://314a71ddbaa90f3e6d444cb12be449d6@sentry.pinyiche.club:9000/4", integrations: [ new Sentry.BrowserTracing({ tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], }), new Sentry.Replay({ maskAllText: false, blockAllMedia: false, }), ], tracesSampleRate: 1.0, replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1.0, });
THE END

发表回复