首页 > 解决方案 > Fluentd 环境变量未在进程中提取

问题描述

我正在使用 FluentD ( td-agent3) + Elastic Beanstalk ( ruby 2.6)。我使用环境变量FLUENTD_HOST来设置主机 ip,但是当我启动 Fluentd 时,主机不存在。

要启动服务,我使用:sudo systemctl start td-agent.service.

但是,一旦服务启动,该host字段为"".

2020-09-30 21:34:39 +0000 [warn]: #0 detached forwarding server 'dg-fluentd-1' host="" port=24224 phi=16.030025667476114 phi_threshold=16

配置文件

# /etc/td-agent/td-agent.conf

<source>
    type debug_agent
    bind 127.0.0.1
    port 24230
</source>

<source>
    @type tail
    path /var/log/secure
    pos_file /var/log/td-agent/secure.log.pos
    tag system.web.access
    format syslog
</source>

<source>
    @type tail
    path /var/log/nginx/*.log
    pos_file /var/log/td-agent/nginx.log.pos
    tag system.web.nginx
    format nginx
</source>

# ------ Destination directives

<match system.**>
  @type forward
  send_timeout 10s
  recover_wait 10s

  <server>
    name dg-fluentd-1
    host "#{ENV['FLUENTD_HOST']}"
    port 24224
    heartbeat_type tcp
  </server>

  <secondary>
    @type file
    path /var/log/td-agent/forward-failed.log
    compress gzip
  </secondary>
</match>

## match tag=debug.** and dump to console
<match debug.**>
    type stdout
</match>
# /usr/lib/systemd/system/td-agent.service

[Unit]
Description=td-agent: Fluentd based data collector for Treasure Data
Documentation=https://docs.treasuredata.com/articles/td-agent
After=network-online.target
Wants=network-online.target

[Service]
User=root
Group=td-agent
LimitNOFILE=65536
Environment=LD_PRELOAD=/opt/td-agent/embedded/lib/libjemalloc.so
Environment=GEM_HOME=/opt/td-agent/embedded/lib/ruby/gems/2.4.0/
Environment=GEM_PATH=/opt/td-agent/embedded/lib/ruby/gems/2.4.0/
Environment=FLUENT_CONF=/etc/td-agent/td-agent.conf
Environment=FLUENT_PLUGIN=/etc/td-agent/plugin
Environment=FLUENT_SOCKET=/var/run/td-agent/td-agent.sock
Environment=TD_AGENT_LOG_FILE=/var/log/td-agent/td-agent.log
Environment=TD_AGENT_OPTIONS=
EnvironmentFile=-/etc/sysconfig/td-agent
PIDFile=/var/run/td-agent/td-agent.pid
RuntimeDirectory=td-agent
Type=forking
ExecStart=/opt/td-agent/embedded/bin/fluentd --log $TD_AGENT_LOG_FILE --daemon /var/run/td-agent/td-agent.pid $TD_AGENT_OPTIONS
ExecStop=/bin/kill -TERM ${MAINPID}
ExecReload=/bin/kill -HUP ${MAINPID}
Restart=always
TimeoutStopSec=120

[Install]
WantedBy=multi-user.targe
# /etc/sysconfig/td-agent

export FLUENTD_HOST="<my-ip>"

我试过设置Environment=TD_AGENT_OPTIONS="--use-v1-config",但没有选择环境变量。

我也试过更新相同的设置/etc/init.d/td-agent,也没有运气。

任何想法或想法表示赞赏!

标签: environment-variablesamazon-elastic-beanstalkfluentd

解决方案


推荐阅读