以往我们在开发的时候并没有太关注日志链接。直到有一天应用出现异常,我们才想起了“日志”。太晚了。我们做运维和开发,除了消防,还需要防火,所以一些防范意识也很重要。ELK的安装比较简单,但后期也需要优化,适当考虑运维人力。如果你觉得可以折腾和坚持,你可以试试。如果ELK环境已经存在,可以直接跳过,进入框架日志配置环节。点击进入:中文地址前提条件:Java8sudoadd-apt-repository-yppa:webupd8team/javasudoapt-getupdatesudoapt-get-yinstalloracle-java8-installer简单安装elasticsearch下载地址:elasticsearchdownloadzip或者其他都可以.解压压缩包。执行:运行前请配置好系统参数。有一定的要求。如果启动失败,请仔细注意错误信息并进行相应调整。bin/elasticsearch验证:curlhttp://localhost:9200/安装kibana下载地址:kibana设置elasticsearchurl地址,就是localhost:9200(默认)运行:./bin/kibana打开:http://localhost:5601访问面板安装logstash下载地址:logstash配置文件:config/logstash.conf可参考:input{file{type=>"fastd"path=>["logfilepath"]}}filter{json{source=>"message"}}output{#stdout{codec=>ruby??debug}elasticsearch{action=>"index"hosts=>"127.0.0.1:9200"index=>"fastd"}}运行:bin/logstash-fconfig/logstash.confstdout作为标准输出,收集到的数据可以通过stdout{codec=>ruby??debug}进行调试。处理php应用日志(FastD3.2的新特性)幸运的是,我们有这样的需求,也可以总结我们的工作经验,形成最终的解决方案与大家分享。!!版本3.1处理方案创建一个新格式的日志文件。然后按照步骤进行处理(命名空间自定义,在日志配置中加入第四个参数)。getName(),get_local_ip(),null,null,self::V1);}}配置app.php[[\Monolog\Handler\StreamHandler::class,'info.log',\FastD\Logger\Logger::INFO,\FastD\Logger\Formatter\StashFormatter::class,],],//code...];日志会随着配置进行生成,结果如下:{"@timestamp":"2017-09-12T15:47:37.189080+08:00","@version":1,"host":"10.1.81.60","message":"sprintf():参数太少","type":"fast-d","channel":"fast-d","level":"ERROR","msg":"sprintf():参数太少","code":0,"file":"/Users/janhuang/Documents/htdocs/me/fastd/fastd/vendor/fastd/routing/src/RouteDispatcher.php","line":78,"trace":["#0[内部函数]:FastD\\Application->FastD\\{closure}(2,'sprintf():Too...','/Users/janhuang...',78,Array)","#1/Users/janhuang/Documents/htdocs/me/fastd/fastd/vendor/fastd/routing/src/RouteDispatcher.php(78):sprintf('Middleware%si...')","#2/Users/janhuang/Documents/htdocs/me/fastd/fastd/vendor/fastd/routing/src/RouteDispatcher.php(60):FastD\\Routing\\RouteDispatcher->callMiddleware(对象(FastD\\Routing\\Route),对象(FastD\\Http\\ServerRequest))”,"#3/Users/janhuang/Documents/htdocs/me/fastd/fastd/src/Application.php(142):FastD\\Routing\\RouteDispatcher->dispatch(Object(FastD\\Http\\ServerRequest))","#4/Users/janhuang/Documents/htdocs/me/fastd/fastd/src/Application.php(205):FastD\\Application->handleRequest(Object(FastD\\Http\\ServerRequest))","#5/Users/janhuang/Documents/htdocs/me/fastd/fastd/tests/app/web/index.php(15):FastD\\Application->run()","#6{main}"]}忽略上面的日志内容,如果程序能看懂的话,可以配置logstash推送到elasticsearch.config/logstash.conf。需要根据业务场景进行配置。现在显示最简单的配置input{file{type=>"fastd"path=>["logfilepath"]}}filter{json{source=>"message"}}output{elasticsearch{action=>"index"hosts=>"127.0.0.1:9200"index=>"fastd"}}配置无误后,开始收集日志。弹性搜索。如果觉得ELK会卡顿或者性能有问题,可以尝试结合kafka进行优化。打开:http://127.0.0.1:5601/,可以看到刚才php应用产生的日志。综上所述,如果php应用出现问题,在第一时间无法发现异常的情况下,日志可能是一个很好的切入点。当机器越来越多,应用越来越多时,日志可能会消耗大量的人力。这个时候我们就要想办法,一方面要解决人手问题,另一方面要提高申请的质量。
