「Fluentd」:修訂間差異

出自Gea-Suan Lin's Wiki
跳至導覽 跳至搜尋
Gslin留言 | 貢獻
Gslin留言 | 貢獻
 
(未顯示同一使用者於中間所作的 16 次修訂)
第1行: 第1行:
'''Fluent'''是一套Log處理軟體。
'''Fluent'''是一套Log處理軟體。
== 簡介 ==
我是拿來跑server端(接收端)而非client端(發送端)。


== 安裝 ==
== 安裝 ==
在[[Ubuntu]]上安裝:
<syntaxhighlight lang="bash">
curl -L https://packages.treasuredata.com/GPG-KEY-td-agent | gpg --dearmor | sudo tee /usr/share/keyrings/fluent-lts-archive-keyring.gpg > /dev/null; echo "Types: deb\nURIs: https://packages.treasuredata.com/lts/5/ubuntu/$(lsb_release -cs)/\nSuites: jammy\nComponents: contrib\nSigned-By: /usr/share/keyrings/fluent-lts-archive-keyring.gpg" | sudo tee /etc/apt/sources.list.d/fluent-lts.sources; sudo apt update; sudo apt install -y td-agent
</syntaxhighlight>
另外安裝fluent-plugin-slack:
<syntaxhighlight lang="bash">
sudo fluent-gem install fluent-plugin-slack
</syntaxhighlight>
== 設定 ==
我是透過[[nginx]]包裝成HTTPS服務,另外進行帳號密碼的管制(HTTP Authentication),主要的重點是:
<syntaxhighlight lang="nginx">
    location / {
        auth_basic "Restricted Content";
        auth_basic_user_file /srv/fluent.example.com/.htpasswd;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8888/;
    }
</syntaxhighlight>
接著在<code>/etc/flient/fluent.conf</code>內的設定比較簡單:
<syntaxhighlight lang="apache">
#
<source>
  @type http
  port 8888
  bind 127.0.0.1
  add_remote_addr true
</source>
<match *>
  @type copy
  <store>
    @type file
    path /var/log/fluent/
  </store>
  <store>
    @type slack
    channel fluentd
    flush_interval 5s
    message_keys log
    parse none
    title_keys REMOTE_ADDR
    title %s
    webhook_url https://hooks.slack.com/services/...
  </store>
</match>
</syntaxhighlight>
另外建立<code>/var/log/fluent</code>,要設為<code>_fluentd</code>這個使用者:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
curl https://packages.treasuredata.com/GPG-KEY-td-agent | sudo apt-key add -; echo "deb http://packages.treasuredata.com/4/ubuntu/$(lsb_release -cs)/ $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/treasure-data.list; sudo apt update; sudo apt install -y td-agent
sudo mkdir /var/log/fluent; sudo chown _flientd:_fluentd /var/log/fluent
</syntaxhighlight>
</syntaxhighlight>



於 2024年7月30日 (二) 01:23 的最新修訂

Fluent是一套Log處理軟體。

簡介

我是拿來跑server端(接收端)而非client端(發送端)。

安裝

Ubuntu上安裝:

curl -L https://packages.treasuredata.com/GPG-KEY-td-agent | gpg --dearmor | sudo tee /usr/share/keyrings/fluent-lts-archive-keyring.gpg > /dev/null; echo "Types: deb\nURIs: https://packages.treasuredata.com/lts/5/ubuntu/$(lsb_release -cs)/\nSuites: jammy\nComponents: contrib\nSigned-By: /usr/share/keyrings/fluent-lts-archive-keyring.gpg" | sudo tee /etc/apt/sources.list.d/fluent-lts.sources; sudo apt update; sudo apt install -y td-agent

另外安裝fluent-plugin-slack:

sudo fluent-gem install fluent-plugin-slack

設定

我是透過nginx包裝成HTTPS服務,另外進行帳號密碼的管制(HTTP Authentication),主要的重點是:

    location / {
        auth_basic "Restricted Content";
        auth_basic_user_file /srv/fluent.example.com/.htpasswd;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8888/;
    }

接著在/etc/flient/fluent.conf內的設定比較簡單:

#
<source>
  @type http
  port 8888
  bind 127.0.0.1
  add_remote_addr true
</source>

<match *>
  @type copy
  <store>
    @type file
    path /var/log/fluent/
  </store>
  <store>
    @type slack
    channel fluentd
    flush_interval 5s
    message_keys log
    parse none
    title_keys REMOTE_ADDR
    title %s
    webhook_url https://hooks.slack.com/services/...
  </store>
</match>

另外建立/var/log/fluent,要設為_fluentd這個使用者:

sudo mkdir /var/log/fluent; sudo chown _flientd:_fluentd /var/log/fluent

相關連結

外部連結