随笔 - 59  文章 - 20  评论 - 61  阅读 - 84921

Asp.Net Core使用Exceptionless日志服务1-搭建Exceptionless容器

Asp.Net Core使用Exceptionless日志服务1-搭建Exceptionless容器

内容摘自网络:Exceptionless是一款日志记录框架,它开源、免费、提供管理界面、易于安装和使用。ExceptionLess底层采用ElasticSearch作为日志存储,提供了快速、丰富的查询API,方便我们进行系统集成。

主要参考:NLog整合Exceptionless - yi念之间 - 博客园 (cnblogs.com)

工作的起点,是去GitHub下载docker compose脚本文件,基于这份文件修改。

https://github.com/exceptionless/Exceptionless/blob/main/docker/docker-compose.dev.yml

本文主要描述在搭建Exceptiness容器中遇到的问题及处理方法。

 

下载exceptionless镜像非常慢

阿里云已经提供了docker镜像下载加速器,但是我拉取exceptionless镜像慢到无法忍受。后来增加了国内容器镜像地址得以解决:

vi /etc/docker/daemon.json

增加国内镜像地址

"registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com", "https://mirror.baidubce.com", "https://ustc-edu-cn.mirror.aliyuncs.com"],

重载daemon.json

systemctl daemon-reload

重启docker服务

systemctl restart docker

docker info检查daemon.json是否正确。

 

Socket Permission denied错误

网上的文章大部分是照搬默认的exceptionless端口5000:80,我要改到8810,所以我的docker compose配置是这样的

    ports:

      - 8810:80

      - 8811:443

创建exceptionless容器创建失败,提示错误:

app_1            | System.Net.Sockets.SocketException (13): Permission denied

尝试了多次修改,最后发现指定ASPNETCORE环境参数可以解决这个报错。

      ASPNETCORE_URLS: http://*:8810;https://*:8811

      ASPNETCORE_HTTPS_PORT: 8811

    ports:

#      - 8810:80

#      - 8811:443

      - 8810:8810

      - 8811:8811

 

SSL证书配置错误

网上的文章大部分介绍使用http端口,我用https端口,要配置SSL证书和密码。如果docker compose配置不对,创建exceptionless容器会报错:

app_1            | [04:55:19 FTL] Job host terminated unexpectedly

app_1            | System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

app_1            | To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.

正确配置ASPNETCORE环境变量的密码,SSL证书文件路径,并映射宿主机的pfx证书文件目录pfxpath到容器里边的https目录,pfxpath下边放置aspnetapp.pfx证书文件。

      ASPNETCORE_Kestrel__Certificates__Default__Password: password(这里替换为pfx证书密码)

    volumes:

      -/pfxpath:/https

 

映射宿主机目录读写权限错误

为了保留容器退出之后的日志数据,我在宿主机创建了映射目录appdataesdata7创建exceptionless容器会报错:

elasticsearch_1  | "stacktrace": ["org.elasticsearch.bootstrap.StartupException: ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];",

elasticsearch_1  | "at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:173) ~[elasticsearch-7.17.8.jar:7.17.8]",

elasticsearch_1  | "Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes",

elasticsearch_1  | ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];

exceptionless_elasticsearch_1 exited with code 1

百度查了一下,都说是打开全部目录权限,测试可行。

# chmod 777 appdata/

# chmod 777 esdata7/

 

exceptionless镜像8.0预览版本有问题,改用7.2.1发布版

exceptionless容器跑起来之后,创建组织xxx,无法保存,在阿里云控制台可以看到错误:

app_1            | Original: [ElasticsearchClientException] Request failed to execute. Call: Status code 400 from: PUT /prod-organizations/_doc/63ddfba91e6a6e001958c046?op_type=create&refresh=false. ServerError: Type: illegal_argument_exception Reason: "no write index is defined for alias [prod-organizations]. The write index may be explicitly disabled using is_write_index=false or the alias points to multiple indices without one being designated as a write index"

app_1            | Server Error (Index=): no write index is defined for alias [prod-organizations]. The write index may be explicitly disabled using is_write_index=false or the alias points to multiple indices without one being designated as a write index

app_1            | [400] PUT /prod-organizations/_doc/63ddfba91e6a6e001958c046?op_type=create&refresh=false

app_1            | {"id":"63ddfba91e6a6e001958c046","name":"xxx","plan_id":"EX_UNLIMITED","plan_name":"Unlimited","plan_description":"Unlimited","billing_change_date":"2023-02-04T06:31:05.6725457Z","billing_changed_by_user_id":"63ddf9e41e6a6e001958c044","billing_status":0,"billing_price":0.0,"max_events_per_month":-1,"bonus_events_per_month":0,"retention_days":180,"is_suspended":false,"has_premium_features":true,"max_users":-1,"max_projects":-1,"usage":[{"date":"2023-02-01T00:00:00Z","limit":-1,"total":0,"blocked":0,"discarded":0,"too_big":0}],"created_utc":"2023-02-04T06:31:05.672944Z","updated_utc":"2023-02-04T06:31:05.672944Z","is_deleted":false}

我不知道怎么解决这个问题,考虑到最新版8.0.0-pre41  3.1.10是预览版,我改用最后一个正式发行版7.2.1,测试可以创建组织。修改docker compose文件拉取的exceptionless镜像版本:

    image: exceptionless/exceptionless:7.2.1

 

配置exceptionless邮箱

主要参考ExceptionLess的安装、配置、使用 - 程序设计实验室 - 博客园 (cnblogs.com)

有坑的地方就是EX_ConnectionStrings__Email变量的邮箱地址需要对@符号进行转义,用%40代替@符号

Exceptionless 5.x 无法正常发送邮件的问题解决 - EdisonZhou - 博客园 (cnblogs.com)

 

appjob服务都配置了邮箱,以及服务器URL

#注意端口号跟app修改后的保持一致,必须是外网可访问地址,验证用户邮箱会访问这里

      EX_BaseURL: https://www.myweb.cn:8811

      EX_ConnectionStrings__Email: smtps://test_service%40qq.com:passwordxxxx@smtp.exmail.qq.com:465

      EX_SmtpFrom: test_service@qq.com

 

登录exceptionless服务器,在账号管理页面,发送验证邮件,服务端日志提示已经发送了邮件,但是我没有收到。后来注解了EX_SmtpFrom测试报错,再取消注解测试又可以发邮件了。

jobs_1           | [01:45:21 INF] Sent message: to=test_user@qq.com subject=Exceptionless Account Confirmation

jobs_1           | [01:45:21 INF] Auto completed MailMessage queue entry: 73722e0d842e410dab7d3d7c9d23077e

 

docker compose脚本

修改后的docker compose脚本如下:

 

复制代码
version: '3.7'

services:
  app:
    container_name: exceptionless
    depends_on:
      - elasticsearch
      - redis
#    build:
#      context: .
#      target: app
#    image: exceptionless/app:latest
    image: exceptionless/exceptionless:7.2.1
    environment:
      EX_AppMode: Production
#注意端口号跟app修改后的保持一致,必须是外网可访问地址,验证用户邮箱会访问这里
      EX_BaseURL: https://www.myweb.cn:8811
      EX_ConnectionStrings__Cache: provider=redis
      EX_ConnectionStrings__Elasticsearch: server=http://elasticsearch:9200
      EX_ConnectionStrings__Email: smtps://test_service%40qq.com:passwordxxxx@smtp.exmail.qq.com:465
      EX_SmtpFrom: test_service@qq.com
      EX_ConnectionStrings__MessageBus: provider=redis
      #EX_ConnectionStrings__Metrics: provider=statsd;server=statsd;
      EX_ConnectionStrings__Queue: provider=redis
      EX_ConnectionStrings__Redis: server=redis,abortConnect=false
      #ASPNETCORE_URLS: http://+;https://+
      #ASPNETCORE_HTTPS_PORT: 5001
      ASPNETCORE_Kestrel__Certificates__Default__Password: password(这里替换为pfx证书密码)
      ASPNETCORE_Kestrel__Certificates__Default__Path: /https/aspnetapp.pfx
      #如果要设定端口,必须在这里指定,否则报错System.Net.Sockets.SocketException (13): Permission denied
      ASPNETCORE_URLS: http://*:8810;https://*:8811
      ASPNETCORE_HTTPS_PORT: 8811
      EX_RunJobsInProcess: 'false'
    ports:
#      - 8810:80
#      - 8811:443
      - 8810:8810
      - 8811:8811
    volumes:
#      - appdata:/app/storage
      - ./appdata:/app/storage
#SSL证书目录
      - ./pfxpath:/https

  jobs:
    container_name: exceptionless_jobs
    depends_on:
      - app
    image: exceptionless/job:7.2.1
#    build:
#      context: .
#      target: job
    environment:
      EX_AppMode: Production
#注意端口号跟app修改后的保持一致,必须是外网可访问地址,验证用户邮箱会访问这里
      EX_BaseURL: https://www.myweb.cn:8811
      EX_ConnectionStrings__Cache: provider=redis
      EX_ConnectionStrings__Elasticsearch: server=http://elasticsearch:9200
      #EX_ConnectionStrings__Email: smtp://localhost:1025
      EX_ConnectionStrings__Email: smtps://test_service%40qq.com:passwordxxxx@smtp.exmail.qq.com:465
      EX_SmtpFrom: test_service@qq.com
      EX_ConnectionStrings__MessageBus: provider=redis
      #EX_ConnectionStrings__Metrics: provider=statsd;server=statsd;
      EX_ConnectionStrings__Queue: provider=redis
      EX_ConnectionStrings__Redis: server=redis,abortConnect=false
      EX_ConnectionStrings__Storage: provider=folder;path=/app/storage
    volumes:
#      - appdata:/app/storage
      - ./appdata:/app/storage

  elasticsearch:
    container_name: elasticsearch
    image: exceptionless/elasticsearch:7.17.8
    environment:
      discovery.type: single-node
      xpack.security.enabled: 'false'
      ES_JAVA_OPTS: -Xms1g -Xmx1g
    ports:
      - 9200:9200
      - 9300:9300
    volumes:
#      - esdata7:/usr/share/elasticsearch/data
      - ./esdata7:/usr/share/elasticsearch/data

  redis:
    container_name: redis
    image: redis:6.0-alpine
    ports:
      - 6379:6379
复制代码

 

 

使用简介

访问自建exceptionless主页,用自己邮箱注册账号,然后新建组织,新建项目。选择项目类型为Asp.Net Core,复制ApiKey给项目备用。

邀请其他注册用户到本组织:【设置】-【组织管理】,选择组织进行【修改】,在【用户管理】页面,【邀请用户】

 

posted on   SunnyTrudeau  阅读(252)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

点击右上角即可分享
微信分享提示