td-agent3(Fluentd v1.0)에서 BigQuery에 로그를 저장합니다. 2018-03-07
내용
htps : // 기주 b. 코 m / 카이젠 p ぁ t ぉ rm / f 을 참고로 td-agent3
( Fluentd v1.0
)에서 BigQuery
에 로그를 저장하는 설정을 합니다.
준비
td-agent3
( Fluentd v1.0
) 설치가 완료된 것으로 합니다.fluent-plugin-bigquery 설치
fluent-plugin-bigquery
라는 플러그인이 필요하므로 설치합니다. /opt/td-agent/embedded/bin/fluent-gem
에 있습니다. 설치
$ sudo /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-bigquery
... 表示が多いので詳細は割愛
Done installing documentation for uber, declarative, declarative-option, representable, retriable, mime-types-data, mime-types, little-plugger, logging, jwt, memoist, os, signet, googleauth, google-api-client, fluent-plugin-bigquery after 159 seconds
16 gems installed
조금 시간이 걸립니다.
확인
$ /opt/td-agent/embedded/bin/fluent-gem list fluent-plugin-bigquery
*** LOCAL GEMS ***
fluent-plugin-bigquery (1.2.0)
[email protected] 설치(2018-03-07 시점)
$ sudo /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-bigquery
... 表示が多いので詳細は割愛
Done installing documentation for uber, declarative, declarative-option, representable, retriable, mime-types-data, mime-types, little-plugger, logging, jwt, memoist, os, signet, googleauth, google-api-client, fluent-plugin-bigquery after 159 seconds
16 gems installed
$ /opt/td-agent/embedded/bin/fluent-gem list fluent-plugin-bigquery
*** LOCAL GEMS ***
fluent-plugin-bigquery (1.2.0)
@type bigquery_insert
@type bigquery_load
를 이용하고 싶습니다만, 사용할 수 있는 것은 v2.0.0부터와 같습니다.
위의 단계로 설치하면 v1.2.0이므로 한 번에 v2.0.0을 설치합니다.
추가
htps : / / 루 바이 게 ms. rg / 게 ms / f ぅ 엔 tp ぅ 긴 - 비 g 쿠 ry / ぇ r 시온 s / 2.0.0. 베타
젬에는 2.0.0.beta가 있습니다. 여기를 설치하면 다음 GitHub에서 설치할 필요가 없습니다.
GitHub에서 설치할 준비
$ sudo /opt/td-agent/embedded/bin/fluent-gem install --no-document specific_install
Fetching: specific_install-0.3.3.gem (100%)
Successfully installed specific_install-0.3.3
1 gem installe
GitHub에서 최신 fluent-plugin-bigquery 설치
$ sudo /opt/td-agent/embedded/bin/fluent-gem specific_install https://github.com/kaizenplatform/fluent-plugin-bigquery.git
/usr/bin/git
git installing from https://github.com/kaizenplatform/fluent-plugin-bigquery.git
Cloning into '/tmp/d20180307-1588-1vvfhc6'...
remote: Counting objects: 2133, done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 2133 (delta 60), reused 94 (delta 39), pack-reused 2008
Receiving objects: 100% (2133/2133), 461.14 KiB | 0 bytes/s, done.
Resolving deltas: 100% (799/799), done.
Checking connectivity... done.
WARNING: open-ended dependency on rake (>= 0, development) is not recommended
if rake is semantically versioned, use:
add_development_dependency 'rake', '~> 0'
WARNING: open-ended dependency on rr (>= 0, development) is not recommended
if rr is semantically versioned, use:
add_development_dependency 'rr', '~> 0'
WARNING: open-ended dependency on test-unit (>= 0, development) is not recommended
if test-unit is semantically versioned, use:
add_development_dependency 'test-unit', '~> 0'
WARNING: open-ended dependency on test-unit-rr (>= 0, development) is not recommended
if test-unit-rr is semantically versioned, use:
add_development_dependency 'test-unit-rr', '~> 0'
WARNING: open-ended dependency on google-api-client (>= 0.11.0) is not recommended
if google-api-client is semantically versioned, use:
add_runtime_dependency 'google-api-client', '~> 0.11', '>= 0.11.0'
WARNING: open-ended dependency on googleauth (>= 0.5.0) is not recommended
if googleauth is semantically versioned, use:
add_runtime_dependency 'googleauth', '~> 0.5', '>= 0.5.0'
WARNING: open-ended dependency on multi_json (>= 0) is not recommended
if multi_json is semantically versioned, use:
add_runtime_dependency 'multi_json', '~> 0'
WARNING: See http://guides.rubygems.org/specification-reference/ for help
Successfully built RubyGem
Name: fluent-plugin-bigquery
Version: 2.0.0.beta
File: fluent-plugin-bigquery-2.0.0.beta.gem
Successfully installe
확인
$ /opt/td-agent/embedded/bin/fluent-gem list fluent-plugin-bigquery
*** LOCAL GEMS ***
fluent-plugin-bigquery (2.0.0.beta, 1.2.0)
설정 예(bigquery_insert)
auth_method
에 json_key
를 사용합니다 /etc/td-agent/td-agent.conf
# <source> についての詳細は割愛
<source>
@type tail
path /var/log/apache2/access.log
tag apache.access
pos_file /var/log/td-agent/apache-access-log.pos
format apache2
keep_time_key true
</source>
# <match> の内容が本題
<match apache.access>
@type bigquery_insert
auth_method json_key
json_key /tmp/json_key.json
project PROJECT_NAME
dataset DATASET_NAME
auto_create_table true
table apache_access_%Y%m%d
<buffer time>
@type file
path /var/log/td-agent/bigquery
timekey 1d
</buffer>
<inject>
time_key time
time_type string
time_format %Y-%m-%d %H:%M:%S
</inject>
schema [
{"name": "time", "type": "TIMESTAMP"},
{"name": "host", "type": "STRING"},
{"name": "user", "type": "STRING"},
{"name": "method", "type": "STRING"},
{"name": "path", "type": "STRING"},
{"name": "code", "type": "INTEGER"},
{"name": "size", "type": "INTEGER"},
{"name": "referer", "type": "STRING"},
{"name": "agent", "type": "STRING"}
]
</match>
동작 확인
위의 설정 예에서
td-agent
를 시작하여 로그 (/var/log/td-agent/td-agent.log
)를 확인하십시오.특히 문제가 없는 것 같으면
$ while true; do curl localhost > /dev/null && sleep 1; done
등으로 액세스 로그를 출력하여 BigQuery에 로그가 쌓여 있는지 확인합니다.
BigQuery 상태 확인
#standardSQL
SELECT
*
FROM
DATASET_NAME.apache_access_20180307
ORDER BY
time DESC
설정 예(bigquery_load)
auth_method
에 json_key
를 사용합니다 flush_XXX
의 defalut 값을 참고로 하면서 설정해, 어느 간격으로 정기적으로 보내도록(듯이) 합니다/etc/td-agent/td-agent.conf
# <source> についての詳細は割愛
<source>
@type tail
path /var/log/apache2/access.log
tag apache.access
pos_file /var/log/td-agent/apache-access-log.pos
format apache2
keep_time_key true
</source>
# <match> の内容が本題
<match apache.access>
@type bigquery_load
auth_method json_key
json_key /tmp/json_key.json
project PROJECT_NAME
dataset DATASET_NAME
auto_create_table true
table apache_access_%Y%m%d
<buffer time>
@type file
path /var/log/td-agent/bigquery
timekey 1d
flush_at_shutdown true
flush_interval 25
</buffer>
<inject>
time_key time
time_type string
time_format %Y-%m-%d %H:%M:%S
</inject>
schema [
{"name": "time", "type": "TIMESTAMP"},
{"name": "host", "type": "STRING"},
{"name": "user", "type": "STRING"},
{"name": "method", "type": "STRING"},
{"name": "path", "type": "STRING"},
{"name": "code", "type": "INTEGER"},
{"name": "size", "type": "INTEGER"},
{"name": "referer", "type": "STRING"},
{"name": "agent", "type": "STRING"}
]
</match>
동작 확인
bigquery_insert
때처럼BigQuery 상태 확인
bigquery_insert
때와 다르지 않으므로 자세한 내용은 할애 flush_XXX
간격으로 어느 정도 쌓여서 보내졌습니다 요약
td-agent3
( Fluentd v1.0
)에서 BigQuery
에 로그를 저장할 수 있습니다.
기타
오류가 발생했습니다.
[error]: #0 Permission denied @ rb_sysopen - /var/log/apache2/access.log
같은 오류가 발생하면 chmod합니다.
$ sudo chmod -R 755 /var/log/apache2/
오류가 발생한 2
fluent-plugin-bigquery
또한 오류가 발생했지만 베타 버전이므로 신경 쓰지 않기로 결정했습니다.
오류가 나왔지만 똑같이 움직였다.
Reference
이 문제에 관하여(td-agent3(Fluentd v1.0)에서 BigQuery에 로그를 저장합니다. 2018-03-07), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/abetomo/items/e4f6c38bcf4807fbacbc
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
오류가 발생했습니다.
[error]: #0 Permission denied @ rb_sysopen - /var/log/apache2/access.log
같은 오류가 발생하면 chmod합니다.
$ sudo chmod -R 755 /var/log/apache2/
오류가 발생한 2
fluent-plugin-bigquery
또한 오류가 발생했지만 베타 버전이므로 신경 쓰지 않기로 결정했습니다.오류가 나왔지만 똑같이 움직였다.
Reference
이 문제에 관하여(td-agent3(Fluentd v1.0)에서 BigQuery에 로그를 저장합니다. 2018-03-07), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/abetomo/items/e4f6c38bcf4807fbacbc텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)