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 ...
随机推荐
- Extjs相关知识
1.链接 1.1.零散知识链接 https://blog.csdn.net/zhaojianrun/article/details/70141071 https://www.cnblogs.com/p ...
- global的使用
对于一个全局变量,你的函数里如果只使用到了它的值,而没有对其赋值(指a = XXX这种写法)的话,就不需要声明global. 相反,如果你对其赋了值的话,那么你就需要声明global.声明global ...
- CentOS7.5 GlusterFS 分布式文件系统集群环境搭建
环境准备: 系统版本:CentOS Linux release 7.5.1804 (Core) glusterfs:3.6.9 userspace-rcu-master: 硬件资源: 10.200.2 ...
- 基于wepy和云开发的动漫资讯小程序----233次元
233次元小程序 # 233次元小程序 项目描述- 基于微信小程序的动漫咨询小程序,采用`wepy`框架开发:- 后台数据采用小程序的云开发存储: 线上体验 部分截图 ...
- run in thread
def run_in_thread(runnable, is_daemon=True): server_thread = Thread(target=runnable) server_thread.s ...
- 从零开始mycat实验环境搭建
版本说明 本机: jdk 8 使用IntelliJ IDEA调试MyCAT 1.6 release 主机一:droplet CentOS 7.5 x86_64 MyCAT 1.6 release O ...
- 分布式之redis核心知识盘点?
考虑到绝大部分写业务的程序员,在实际开发中使用redis的时候,只会setvalue和getvalue两个操作,对redis整体缺乏一个认知.又恰逢博主某个同事下周要去培训redis,所以博主斗胆以r ...
- 《深入理解java虚拟机》读书笔记——java内存区域和内存溢出异常
几种内存溢出异常: 堆溢出 原因:创建过多对象,并且GC Roots到对象之间有可达路径. 分两种情况: Memory Leak:无用的对象没有消除引用,导致无用对象堆积.例如<Effictiv ...
- jtable时间编辑器
最近在做一个项目,很烦,用的swing,但是不管怎样也还是啃下来了,但是碰到一个问题,要在jtable里编辑时用一个时间选择器,因为走了许多弯路,找到挺多jar包,耗时较久,所以记录一下,便于以后查阅 ...
- python大法好——多线程
Python 多线程 多线程类似于同时执行多个不同程序,多线程运行有如下优点: 使用线程可以把占据长时间的程序中的任务放到后台去处理. 用户界面可以更加吸引人,这样比如用户点击了一个按钮去触发某些事件 ...