Fluentd를 사용하여 Twitter Public streams를 Amazon S3에 저장
이전에는 자작의 Python 스크립트를 상시 실행하고 있었습니다만, 지나치게 복잡해 프로세스가 죽는 것이 다발하는 것과 로컬의 디스크에 계속 모여 있어서 디스크가 박박해 버리는 문제가 발생.
이 근처 제대로 만들면 좋겠지만, Fluentd에는 Public streams에도 Amazon S3에도 액세스할 수 있는 플러그인이 준비되어 있었으므로 그것을 사용해 완전 자동으로 수집을 계속할 수 있도록 설정해 보았습니다.
※순서는 꽤 옛날에 설정한 내용을 기억하면서 쓰고 있으므로 빠져 누출 있을지도 모릅니다. . 그 때는 지적 부탁드립니다
설치
이번에는 CentOS 7에 설치하고 움직여 보았습니다.
#curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh
#sudo /etc/init.d/td-agent start
#sudo /etc/init.d/td-agent status
플러그인 설치
Twitter 및 Amazon S3에 액세스하기 위한 플러그인을 설치합니다.
#sudo td-agent-gem install fluent-plugin-twitter
#sudo /usr/sbin/td-agent-gem install fluent-plugin-s3
td-agent.conf 설정
설정을 td-agent.conf의 줄 끝에 추가
/etc/td-agent/td-agent.conf<source>
type twitter
consumer_key xxxxxxxxxxxxxxxxxxxxxxxxxxx
consumer_secret xxxxxxxxxxxxxxxxxxxxxxxxxxx
oauth_token xxxxxxxxxxxxxxxxxxxxxxxxxxx
oauth_token_secret xxxxxxxxxxxxxxxxxxxxxxxxxxx
tag input.twitter.sampling
timeline sampling
lang ja
output_format nest
</source>
<match input.twitter.sampling>
type copy
<store>
type s3
aws_key_id xxxxxxxxxxxxxxxxxxxxxxxxxxx
aws_sec_key xxxxxxxxxxxxxxxxxxxxxxxxxxx
s3_bucket hogehoge
s3_region ap-northeast-1
s3_enpoint s3-ap-northeast-1.amazonaws.com
path streaming_api_logs/
buffer_path /var/log/td-agent/s3
time_slice_format %Y%m%d%H
s3_object_key_format %{path}%{time_slice}_%{index}_%{hostname}.%{file_extension}
time_slice_wait 5m
buffer_chunk_limit 256M
utc
</store>
</match>
사전에 Twitter와 AWS의 API는 취득해 둡니다.
일본 리전에 버킷을 만들고 버킷에 API에서 액세스 권한을 부여하는 것이 사전에 필요합니다.
동작 결과
제대로 작동하면 1시간마다 Amazon S3로 gz 압축된 파일이 전송됩니다.
때때로 파일명이 _1인 것이 생성됩니다만, 압축전의 파일 사이스가 256MB를 넘었을 경우 자동으로 일련번호로 해 주는 것 같습니다.
데이터는 모아졌습니다만, 앞으로 어떻게 활용해 나갈지는 지금부터 생각합니다
참고
이쪽을 참고로 했습니다.
감사합니다.
fluentd 설치
Reference
이 문제에 관하여(Fluentd를 사용하여 Twitter Public streams를 Amazon S3에 저장), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Dalice/items/28a55c5f82481aebe04f
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
#curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh
#sudo /etc/init.d/td-agent start
#sudo /etc/init.d/td-agent status
Twitter 및 Amazon S3에 액세스하기 위한 플러그인을 설치합니다.
#sudo td-agent-gem install fluent-plugin-twitter
#sudo /usr/sbin/td-agent-gem install fluent-plugin-s3
td-agent.conf 설정
설정을 td-agent.conf의 줄 끝에 추가
/etc/td-agent/td-agent.conf<source>
type twitter
consumer_key xxxxxxxxxxxxxxxxxxxxxxxxxxx
consumer_secret xxxxxxxxxxxxxxxxxxxxxxxxxxx
oauth_token xxxxxxxxxxxxxxxxxxxxxxxxxxx
oauth_token_secret xxxxxxxxxxxxxxxxxxxxxxxxxxx
tag input.twitter.sampling
timeline sampling
lang ja
output_format nest
</source>
<match input.twitter.sampling>
type copy
<store>
type s3
aws_key_id xxxxxxxxxxxxxxxxxxxxxxxxxxx
aws_sec_key xxxxxxxxxxxxxxxxxxxxxxxxxxx
s3_bucket hogehoge
s3_region ap-northeast-1
s3_enpoint s3-ap-northeast-1.amazonaws.com
path streaming_api_logs/
buffer_path /var/log/td-agent/s3
time_slice_format %Y%m%d%H
s3_object_key_format %{path}%{time_slice}_%{index}_%{hostname}.%{file_extension}
time_slice_wait 5m
buffer_chunk_limit 256M
utc
</store>
</match>
사전에 Twitter와 AWS의 API는 취득해 둡니다.
일본 리전에 버킷을 만들고 버킷에 API에서 액세스 권한을 부여하는 것이 사전에 필요합니다.
동작 결과
제대로 작동하면 1시간마다 Amazon S3로 gz 압축된 파일이 전송됩니다.
때때로 파일명이 _1인 것이 생성됩니다만, 압축전의 파일 사이스가 256MB를 넘었을 경우 자동으로 일련번호로 해 주는 것 같습니다.
데이터는 모아졌습니다만, 앞으로 어떻게 활용해 나갈지는 지금부터 생각합니다
참고
이쪽을 참고로 했습니다.
감사합니다.
fluentd 설치
Reference
이 문제에 관하여(Fluentd를 사용하여 Twitter Public streams를 Amazon S3에 저장), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Dalice/items/28a55c5f82481aebe04f
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
<source>
type twitter
consumer_key xxxxxxxxxxxxxxxxxxxxxxxxxxx
consumer_secret xxxxxxxxxxxxxxxxxxxxxxxxxxx
oauth_token xxxxxxxxxxxxxxxxxxxxxxxxxxx
oauth_token_secret xxxxxxxxxxxxxxxxxxxxxxxxxxx
tag input.twitter.sampling
timeline sampling
lang ja
output_format nest
</source>
<match input.twitter.sampling>
type copy
<store>
type s3
aws_key_id xxxxxxxxxxxxxxxxxxxxxxxxxxx
aws_sec_key xxxxxxxxxxxxxxxxxxxxxxxxxxx
s3_bucket hogehoge
s3_region ap-northeast-1
s3_enpoint s3-ap-northeast-1.amazonaws.com
path streaming_api_logs/
buffer_path /var/log/td-agent/s3
time_slice_format %Y%m%d%H
s3_object_key_format %{path}%{time_slice}_%{index}_%{hostname}.%{file_extension}
time_slice_wait 5m
buffer_chunk_limit 256M
utc
</store>
</match>
제대로 작동하면 1시간마다 Amazon S3로 gz 압축된 파일이 전송됩니다.
때때로 파일명이 _1인 것이 생성됩니다만, 압축전의 파일 사이스가 256MB를 넘었을 경우 자동으로 일련번호로 해 주는 것 같습니다.
데이터는 모아졌습니다만, 앞으로 어떻게 활용해 나갈지는 지금부터 생각합니다
참고
이쪽을 참고로 했습니다.
감사합니다.
fluentd 설치
Reference
이 문제에 관하여(Fluentd를 사용하여 Twitter Public streams를 Amazon S3에 저장), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Dalice/items/28a55c5f82481aebe04f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)