docker+efk+.net core部署
部署环境
centos7
本主要利用efk实现日志收集
一、创建docker-compose
es地址:https://www.elastic.co/guide/en/elasticsearch/reference/6.4/docker.html
fluentd地址:https://hub.docker.com/r/fluent/fluentd
kibana地址:https://www.elastic.co/guide/en/kibana/current/docker.html
1、利用xshell+xftp在centos7的/root/test下创建文件夹挂载容器内配置、数据等
fluentd
-config
fluent.conf
-plugins #空文件夹
Dockerfile
docker-compose.yml
fluent.conf #与上面一样
2、创建自己的fluentd镜像 (#因为镜像中不支持es插件输出,以下可以参考上面fluentd地址)
上面目录中的Dockerfile文件如下:
Dockerfile
FROM fluent/fluentd:v1.-onbuild- # Use root account to use apk
USER root # below RUN includes plugin as examples elasticsearch is not required
# you may customize including plugins as you wish
RUN apk add --no-cache --update --virtual .build-deps \
sudo build-base ruby-dev \
&& sudo gem install \
fluent-plugin-elasticsearch \
&& sudo gem sources --clear-all \
&& apk del .build-deps \
&& rm -rf /home/fluent/.gem/ruby/2.5./cache/*.gem USER fluent
fluent.conf 可以根据自己情况设置默认,因为启动fluentd的时候会自己加载/fluentd/etc/fluent.conf这个文件。你可以把它挂在在外面
fluent.conf
<source>
@type forward
port
bind 0.0.0.0
</source> <filter>
@type parser
format json
emit_invalid_record_to_error false
time_format %Y-%m-%dT%H:%M:%S.%L%Z
key_name log
</filter> <match **>
@type elasticsearch
host 192.168.1.157
port
logstash_format true
</match>
cd到 /root/test/fluentd 执行
docker build -t custom-fluentd:latest ./
生成支持es的fluentd镜像完毕
3、利用docker-compose.yml启动
version: '3.4' services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.
container_name: elasticsearch
environment:
discovery.type: "single-node"
http.cors.enabled: "true"
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- "9200:9200"
- "9300:9300" kibana:
image: docker.elastic.co/kibana/kibana:6.4.
container_name: kibana
environment:
SERVER_NAME: kibana
ELASTICSEARCH_HOSTS: http://192.168.1.157:9200 # default is http://elasticsearch:9200
ports:
- "5601:5601"
depends_on:
- elasticsearch fluentd:
image: custom-fluentd
#build:
# context: ./fluentd/
# dockerfile: Dockerfile
container_name: fluentd
ports:
- "24224:24224"
- "24224:24224/udp"
volumes:
- /root/test/fluentd/log:/fluentd/log
- /root/test/fluentd/config:/fluentd/etc
depends_on:
- elasticsearch volumes:
esdata1:
driver: local
输入http://ip:5601查看kibana
输入http://ip:9200查看es
注意:启动过程可能会因为es还没启动好fluentd就启动导致fluentd没连上es可以通过查看日志docker logs fluentd确定是否连上,如果没连上,可以通过wait-for-it.sh或wait-for进行延迟编排,本文不讲
参考地址:https://my.oschina.net/eacdy/blog/1824219
如果还是不行可以把上面的分开一个一个启动
docker-compose -d up
二、.net core 利用serilog日志组件输出到es
1、项目中NuGet
Serilog.AspNetCore
Serilog.Settings.Configuration
Serilog.Sinks.Console
Serilog.Sinks.Elasticsearch
2、Appsetting.json中配置
{
"Serilog": {
"Using": ["Serilog.Sinks.Console"],
"MinimumLevel": "Warning",
"WriteTo": [
{ "Name": "Console" }
],
"Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"],
"Destructure": [
{ "Name": "ToMaximumDepth", "Args": { "maximumDestructuringDepth": } },
{ "Name": "ToMaximumStringLength", "Args": { "maximumStringLength": } },
{ "Name": "ToMaximumCollectionCount", "Args": { "maximumCollectionCount": } }
],
"Properties": {
"Application": "ApplicationName"
}
}
}
3、program.cs中配置
....
using Serilog;
using Serilog.Sinks.Elasticsearch;
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseSerilog((ctx, config)=> {
config.ReadFrom.Configuration(ctx.Configuration);
#if DEBUG
config.WriteTo.Console();
#else
config.WriteTo.Console(new ElasticsearchJsonFormatter());
#endif
});
配置好后可以运行起来,这个时候的控制台输出的日志就已经是es类型格式了
4、编写Dockerfile打包项目镜像
Dockerfile
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE FROM microsoft/dotnet:2.2-sdk AS publish
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /app FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ApplicationName.dll"]
5、利用docker-compose.yml启动项目
docker-compose.yml
ApplicationName:
image: ApplicationName
container_name: ApplicationName
build:
context: ./ApplicationName/
dockerfile: Dockerfile
environment:
- ASPNETCORE_URLS=http://0.0.0.0:80
restart: always
ports:
- "5000:80"
logging:
driver: "fluentd"
options:
fluentd-address: "tcp://192.168.1.157:24224"
其中logging要指定日志输出类型及日志输出到fluentd的地址端口
把docker-compose.yml放在项目根目录下,cd到项目根目录运行
docker-compose -d up
就可以启动完成
在浏览器中输入ip:port即可查看
注意:这里的所有docker-compose.yml都是分开的所以启动后可能会分布在不同的网络中,可以创建一个网络docker network create netname,然后保证他们在同一个网络里面这样就可以直接用容器名来连接而不需要用宿主机的ip
docker+efk+.net core部署的更多相关文章
- 系列13 docker asp.net core部署
一.介绍 本篇完整介绍asp.net core web api如何部署到docker容器中,并通过外部访问web api服务.在编写完成dockerfile之后,可以通过docker [image ...
- Ubuntu & GitLab CI & Docker & ASP.NET Core 2.0 自动化发布和部署(2)
上一篇:Ubuntu & GitLab CI & Docker & ASP.NET Core 2.0 自动化发布和部署(1) 服务器版本 Ubuntu 16.04 LTS. 本 ...
- .net core 部署 docker (CentOS7)
最近研究 docker 在Linux 下部署 .net core 项目,在过程中踩了很多坑,网上的资料对我帮助确实大,但有些问题未指明出来. 特地整理一份在发布文档 本文使用的是 root 账号操作, ...
- 【Step By Step】将Dotnet Core部署到Docker下
一.使用.Net Core构建WebAPI并访问Docker中的Mysql数据库 这个的过程大概与我之前的文章<尝试.Net Core—使用.Net Core + Entity FrameWor ...
- .net core——Docker化开发和部署
原文:.net core--Docker化开发和部署 本篇文章是使用Vs2017生成的Dockerfile进行部署的. 目录 VS2017生成Docker部署项目 Dockerfile内容 在开发服务 ...
- Asp.net Core Jenkins Docker 实现一键化部署
写在前面 在前段时间尝试过用Jenkins来进行asp.net core 程序在IIS上面的自动部署.大概的流程是Jenkins从git上获取代码 最开始Jenkins是放在Ubuntu的Docker ...
- .NET core 部署到Docker +Docker Protainer管理实现
.NET core 部署到Docker +Docker Protainer管理实现 上次说到将.net core的应用程序发布到Linux中(https://www.cnblogs.com/Super ...
- .NET Core部署到linux(CentOS)最全解决方案,高阶篇(Docker+Nginx 或 Jexus)
在前两篇: .NET Core部署到linux(CentOS)最全解决方案,常规篇 .NET Core部署到linux(CentOS)最全解决方案,进阶篇(Supervisor+Nginx) 我们对. ...
- .NET Core部署到linux(CentOS)最全解决方案,入魔篇(使用Docker+Jenkins实现持续集成、自动化部署)
通过前面三篇: .NET Core部署到linux(CentOS)最全解决方案,常规篇 .NET Core部署到linux(CentOS)最全解决方案,进阶篇(Supervisor+Nginx) .N ...
随机推荐
- Git使用,将本地项目推送到GitHub上
首先本地仓库中创建一个项目 ex: proA 在远程github仓库中创建项目 ex: proA 在本地仓库proA下打开terminal 使用命令: 1.git add * 2.git commit ...
- python爬虫学习笔记(一)——环境配置(windows系统)
在进行python爬虫学习前,需要进行如下准备工作: python3+pip官方配置 1.Anaconda(推荐,包括python和相关库) [推荐地址:清华镜像] https://mirrors ...
- sql 查询结果转百分比
select convert(varchar,convert(decimal(10,2),迟到人次*1.0/在校生人数*100))+'%'
- gevent-websocket初识
初试 from flask import Flask, request from geventwebsocket.handler import WebSocketHandler from gevent ...
- LeetCode 797. All Paths From Source to Target
题目链接:https://leetcode.com/problems/all-paths-from-source-to-target/description/ Given a directed, ac ...
- ef6.0+mysql配合使用的问题
折腾了很久由于所用到的各种库版本问题:后来终于组合成了一个可用的:记录下各种库的版本 ef6.0 mysql5.5 mysql-connector-net-6.9.12.msi mysql-for-v ...
- jenkins持续集成部署
用到的技术和工具:git + maven + jdk + jenkins,首先服务器安装git.maven.jdk,这些都不再赘述. 1:开始安装主角jenkins,首先去官网下载war包(https ...
- js异步处理历程
为什么会出现异步: js执行环境是单线程的,异步处理就非常重要. 处理的方法: 方法一:callback hell 解决:解决了异步处理 存在问题:出现多个回调函数嵌套,代码就会比较乱,出现回调地狱现 ...
- Android 开发 监听back并且执行home键功能
方法一: 在activity中重写onBackPressed()方法 ,注意此处一定要注释或者删除 super.onBackPressed();方法 @Override public void onB ...
- Android 开发 音视频从入门到提高 任务列表 转载
<Android 音视频从入门到提高 —— 任务列表> 1. 在 Android 平台绘制一张图片,使用至少 3 种不同的 API,ImageView,SurfaceView,自定义 Vi ...