当前位置:首页 > 踩坑记录 > 记一次“机智如我”的部署Exceptionless中遇到的各种坑

记一次“机智如我”的部署Exceptionless中遇到的各种坑

txtName4年前 (2020-06-12)踩坑记录1865

由于不想每次都在项目发生异常的时候登录服务器查看日志,尤其是项目多的时候,根据以往的了解最终选择使用轻量级的日志框架Exceptionless(Windows环境)。

然后随便打开了一个部署教程开始搞

OK,现在下载ES,地址:Elasticsearch-7.7.1   其他版本下载

因为ES是由Java开发的,so..还要JDK,由于没有Oracle账号也不想登录,就百度了某下载站的链接。地址:某下载站JDK1.8   官方JDK下载地址

安装JDK...

解压ES...运行ES目录/bin/elasticsearch.bat 就能启动ES,如果想把ES安装成服务的话可以用命令行在ES的bin目录里运行cmd,elasticsearch-service.bat install

image.png


默认地址是:http://localhost:9200,能看到下面这个结果就说明ES已经跑起来了


image.png


由于ES我是部署在内网服务器上的,想要本机也能访问到需要修改配置文件,我就去找config/elasticsearch.yml这个配置文件。

大概观察了一下知道要修改成这样

network.host: 0.0.0.0

以为好了的时候发现又出了其他错误,去看了ES的启动日志发现有这么一行

[2020-06-12T17:06:25,430][ERROR][o.e.b.Bootstrap] [WIN-JUS4E3TPC8V] node validation exception

[1] bootstrap checks failed

[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

根据我蹩脚的英文看出来 discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes 这3个参数至少要配置一个,然后又去看了配置文件。。。

# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.

尝试把discovery.seed_hosts: ["host1", "host2"]取消注释然后重启ES服务果然可以内网访问了。。


下来从Github上下载了最新版6.0的源码开始部署。地址:Exceptionless-6.0.0   Github项目地址

很熟练的用VS打开然后发现配置文件竟然不是常见的appsettings.json而是appsettings.yml,感觉有点像Docker里的配置方式

首先把 Elasticsearch的配置解除注释,然后F5运行

image.png

跑起来了啦!然后打开 https://localhost:5001,然鹅

image.png


这是什么鬼,登录页面呢,和网上看的不一样啊。。

一顿百度发现还需要一个前端项目叫 ExceptionlessUI,赶紧回去再看下Github

image.png


醉醉的。。

一样到Realease页面下载,地址:ExceptionlessUI-2.9.0

以前学习过一点点VUE,so..NodeJs和VSCode都有

然后又轻车熟路的用VSCode直接打开,在下面的终端进入src目录后直接输入 npm install,安装依赖包

眼看依赖包安装完成,然后输入 npm run build,提示没有这个命令。。FK!

观察了一下项目结构发现和VUE项目有些略微的差别,又是一番百度后发现是AngularJS项目,要用Grunt。。没听说过啊。。

再次百度。。

npm install -g grunt-cli

下来 grunt --version 检查版本已确认是否安装成功

然后直接输入 grunt就开始打包项目啦,完了和VUE一样会有个dist目录,这里面就是打包后的文件

打包之前记得修改app.config.js,把BASE_URL修改成你Exceptionless项目的地址

(function () {
  'use strict';

  angular.module('app.config', [])
    .constant('BASE_URL''https://localhost:5001')
    .constant('EXCEPTIONLESS_API_KEY')
    .constant('EXCEPTIONLESS_SERVER_URL')
    .constant('FACEBOOK_APPID')
    .constant('GITHUB_APPID')
    .constant('GOOGLE_APPID')
    .constant('INTERCOM_APPID')
    .constant('LIVE_APPID')
    .constant('SLACK_APPID')
    .constant('STRIPE_PUBLISHABLE_KEY')
    .constant('SYSTEM_NOTIFICATION_MESSAGE')
    .constant('USE_HTML5_MODE'false)
    .constant('USE_SSL'false)
    .constant('ENABLE_ACCOUNT_CREATION'true);
}());


然后把dist目录里的东西全都复制到Exceptionless项目的wwwroot目录,如果单独运行这个前端项目的话会出现跨域问题,还要改源码麻烦

然后删除Exceptionless.Web.csproj里的这些内容,不然编译报错

  <ItemGroup>

    <EmbeddedResource Include="wwwroot\docs.css" />

  </ItemGroup>

重新启动Exceptionless后还是空白页,习惯性的F12查看了一下

发现jquery和lodashjs这俩加载不出来。。老外的项目用的cds好多国内访问要么速度慢要么访问不到

我百度了国内的jscdn替换,在index.html里,然后重新打包替换。。

        <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
        <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700" />
        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js" data-concat="false" data-remove="false"></script>
        <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" data-concat="false" data-remove="false"></script>
        <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.15/lodash.min.js" data-concat="false" data-remove="false"></script>

再次运行还是白页,发现是什么CSP给拦截了。。。

image.png


还好当时大概看了看源码,知道在哪里修改

在 Starup.cs 里找到这些,每块下面都添加一行 .From("https://cdn.bootcdn.net");


image.png

然后就好啦!!!

image.pngimage.png

下来创建组织和项目

image.png


创建好后选择 ASP.NET Core,记住密钥


image.png


下来在Api项目里装NuGet包 Exceptionless.AspNetCore并设置

ExceptionlessClient.Default.Configuration.ApiKey = "NfNJLgde2pIJHS1F3aLEoEuPUqnIQ1JZagLxnPYl";
ExceptionlessClient.Default.Configuration.ServerUrl = "https://localhost:5001";
app.UseExceptionless();


测试一下异常代码

[HttpGet]
public IActionResult Get()
{
    try
    {
        string str = null;
        var length = str.Length;
    }
    catch (Exception ex)
    {
        ex.ToExceptionless().Submit();
    }

    return Ok();
}


image.png


可以看到已经有日志过来啦!

image.png


既然本地成功了我就要发布到内网测试,总不能每次本机都要运行这个吧。。

又是一顿熟练的操作后发布到了内网服务器的IIS里,替换APIKey继续尝试,然后怎么都不行,日志接收不到

没办法只能打开 stdoutLogEnabled="true" 输出日志查看,果然发现一条异常信息

[18:25:26 ERR] Error enqueuing event post.

System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.

   at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count)

   at Microsoft.AspNetCore.Server.IIS.Core.WrappingStream.Read(Byte[] buffer, Int32 offset, Int32 count)

   at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize)

   at System.IO.Stream.CopyTo(Stream destination)

   at Foundatio.Storage.InMemoryFileStorage.ReadBytes(Stream input)

   at Foundatio.Storage.InMemoryFileStorage.SaveFileAsync(String path, Stream stream, CancellationToken cancellationToken)

   at Exceptionless.Core.Services.EventPostService.EnqueueAsync(EventPost data, Stream stream, CancellationToken cancellationToken) in D:\Projects\Exceptionless-6.0.0\src\Exceptionless.Core\Services\EventPostService.cs:line 35

   at Exceptionless.Web.Controllers.EventController.PostAsync(String projectId, Int32 apiVersion, String userAgent) in D:\Projects\Exceptionless-6.0.0\src\Exceptionless.Web\Controllers\EventController.cs:line 1039


百度了以后尝试用以下设置解决

services.Configure<IISServerOptions>(options=> {
    options.AllowSynchronousIO = true;
});

完了接着重试。。然鹅发现这次连日志输出都没有了。。等了几分钟还是没有日志输出就强行把进程结束了,然后发现了有疑似超时卡住的日志

[18:41:46 FTL] Job host terminated unexpectedly

System.OperationCanceledException: The operation was canceled.

   at System.Threading.CancellationToken.ThrowOperationCanceledException()

   at Microsoft.Extensions.Hosting.Internal.Host.StopAsync(CancellationToken cancellationToken)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.WaitForShutdownAsync(IHost host, CancellationToken token)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

   at Exceptionless.Web.Program.Main(String[] args) in D:\Projects\Exceptionless-6.0.0\src\Exceptionless.Web\Program.cs:line 28


下来又尝试用dotnet命令启动看日志输出 dotnet Exceptionless.Web.dll --urls "http://*:8088;"

启动以后发现又是 Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. 这个异常

image.png

心想之前是IIS承载的,现在是Kestrel内核承载,又百度后换了如下更改

services.Configure<KestrelServerOptions>(options=> {

    options.AllowSynchronousIO = true;

});

继续尝试。。

image.png

Error creating the index prod-events-v1-2020.06.12: Original: (400 - ElasticsearchClientException) Request failed to execute. Call: Status code 400 from: PUT /prod-events-v1-2020.06.12. ServerError: Type: mapper_parsing_exception Reason: "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [_size : {enabled=true}]" CausedBy: "Type: mapper_parsing_exception Reason: "Root mapping definition has unsupported parameters:  [_size : {enabled=true}]""

Server: (400) Type: mapper_parsing_exception Reason: "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [_size : {enabled=true}]" CausedBy: "Type: mapper_parsing_exception Reason: "Root mapping definition has unsupported parameters:  [_size : {enabled=true}]""


在本机好好的,怎么放到服务器上就不行了呢???这个问题困扰了我一天多,百度了很久也没有答案,直到我看到一篇帖子说如果报这个错的话需要Mapper-Size插件。。。醉了。。为什么本机没问题。。

Mapper-Size离线下载   Mapper-Size下载页面

下载好以后在ES的plugins里新建一个 mapper-size-7.7.1这个目录,然后把 mapper-size-7.7.1.zip放进去重启ES服务就好了

别像我一样先解压放进去服务起不来,然后把zip放进去一样起不来,最后才想到新建一个目录。。

java.lang.IllegalStateException: Could not load plugin descriptor for plugin directory [mapper-size-7.7.1.zip]

Likely root cause: java.nio.file.NoSuchFileException: D:\Softs\elasticsearch-7.7.1\plugins\mapper-size-7.7.1.zip\plugin-descriptor.properties


最后直接用IIS启动Exceptionless就OK了,一切结束。。。

扫描二维码推送至手机访问。

版权声明:本文由txtName发布,如需转载请注明出处。

本文链接:https://blog.txtname.cn/2020/06/4.html

标签:

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。