将博客搬至CSDN

橙三吉。 提交于 2019-11-28 18:41:26
mkdir -p /srv/volume/fluentd/
cd /srv/volume/fluentd/
mkdir -p plugins/
cat > Dockerfile << 'EOF'
FROM fluent/fluentd:v1.2.5-debian-onbuild

ENV TZ=Asia/Shanghai
RUN apt-get update \
        && apt-get -y install tzdata \
        && apt-get -y install curl \
        && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
        && echo $TZ > /etc/timezone

RUN buildDeps="sudo make gcc g++ libc-dev ruby-dev" \
 && apt-get update \
 && apt-get install -y --no-install-recommends $buildDeps \
 && sudo gem install \
        fluent-plugin-elasticsearch \
 && SUDO_FORCE_REMOVE=yes \
    apt-get purge -y --auto-remove \
                  -o APT::AutoRemove::RecommendsImportant=false \
                  $buildDeps \
 && rm -rf /var/lib/apt/lists/* \
           /home/fluent/.gem/ruby/2.3.0/cache/*.gem

COPY fluent.conf /fluentd/etc/fluent.conf
EOF

cat > fluent.conf << 'EOF'
<source>
  @type tcp
  tag windows
  format none
  port 8888
  bind 0.0.0.0
</source>

<source>
  @type forward
  port  24224
  bind 0.0.0.0
</source>

<filter windows.**>
  @type parser
  format json
#  time_format %Y-%m-%dT%H:%M:%S.%L%Z
  key_name message
  reserve_data false
  suppress_parse_error_log true
  ignore_key_not_exist true
  replace_invalid_sequence true
</filter>

<filter docker.**>
  @type parser
  format json
#  time_format %Y-%m-%dT%H:%M:%S.%L%Z
  key_name log
  reserve_data false
  suppress_parse_error_log true
  ignore_key_not_exist true
  replace_invalid_sequence true
</filter>

<filter docker.nginx.**>
  type record_transformer
  enable_ruby true
  <record>
    "@timestamp"  ${Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%z")}
  </record>
</filter>

<match windows.**>
  @type elasticsearch
  hosts 10.1.1.225:9200
  user elastic
  password 'qwe123!@#'
  
  target_index_key @target_index
  index_name default_index
  type_name fluentd

  include_tag_key true
  tag_key DockerName

  flush_interval 1s
  request_timeout 15s
  reload_connections false
  reconnect_on_error true
  resurrect_after 5s

  buffer_type memory
  num_threads 2
</match>


<match docker.**>
  @type elasticsearch
  hosts 10.1.1.225:9200
  user elastic
  password 'qwe123!@#'

  target_index_key @target_index
  index_name default_index
  type_name fluentd

  include_tag_key true
  tag_key DockerName

  flush_interval 1s
  request_timeout 15s
  reload_connections false
  reconnect_on_error true
  resurrect_after 5s

  buffer_type memory
  num_threads 2
</match>


<match **>
  @type elasticsearch
  hosts 10.1.1.225:9200
  user elastic
  password 'qwe123!@#'
  
  logstash_format true
  logstash_prefix unknown
  logstash_dateformat %Y.%m.%d
  
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z
  
  target_index_key @target_index
  index_name default_index
  type_name fluentd

  include_tag_key true
  tag_key DockerName

  flush_interval 1s
  request_timeout 15s
  reload_connections false
  reconnect_on_error true
  resurrect_after 5s

  buffer_type memory
  num_threads 2
</match>
EOF

docker build --no-cache --pull -t fluentd/yujianbo:20180829 ./

docker rm -f pilipa-inside-fluentd
docker run -d \
        --name pilipa-inside-fluentd \
        --env FLUENTD_CONF=fluent.conf \
        -v /srv/fluentd/fluent.conf:/fluentd/etc/fluent.conf \
        -p 8888:8888 \
        -p 24224:24224 \
fluentd/yujianbo:20180829
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!