1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

td-agent + CentOS6.5

Posted at

環境

OS: CentOS6.5

Rubyのアップデート

既存のRubyを削除する手順なのでRubyを使っているスクリプト類がないことをご確認ください。
Ruby1系から2系へのアップデートなので動かなくなるスクリプトがある可能性があります。

CentOSの6.5のRubyのバージョンは1.8.x系なので以下の方法でアップデートしておきます。
最新版は2.2系ですが、個人的にまだ怖いので2.1系を入れておきます。

$ sudo yum update
$ sudo yum -y install gcc zlib-devel openssl-devel sqlite sqlite-devel # 必要パッケージのインストール
$ sudo yum -y remove ruby # 既存のrubyの削除
$ which ruby
/usr/bin/which: no ruby in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/opsadmin/bin)
$ cd /usr/local/src
$ sudo wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz
$ sudo tar zxvf ruby-2.1.5.tar.gz
$ cd ruby-2.1.5
$ sudo ./configure
$ sudo make
$ sudo make install # /usr/local/binにインストールされます。
$ which ruby
/usr/local/bin/ruby
$ ruby --version
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
$

td-agentのInstall

インストールの前に以下を確認してください。
http://docs.fluentd.org/ja/articles/before-install

以下のコマンドでインストールすることができます。

$ curl -L http://toolbelt.treasuredata.com/sh/install-redhat.sh | sh
$ td-agent --version
td-agent 0.10.55
$ 

td-agentの設定

以下apache2のアクセスログをTreasureDataに転送する設定となります。
apache2というDBのaccessというテーブルにデータを入れる設定が以下となります。

アクセスログの形式は以下となります。

::1 - - [22/Jan/2015:10:46:21 +0900] "GET / HTTP/1.1" 403 4954 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
/etc/td-agent/td-agent.conf
# Tailing the Appache Log
<source>
  type tail
  path /var/log/httpd/access_log
  pos_file /var/log/td-agent/apache2-access.pos
  tag td.apache2.access
  format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/
time_format %d/%b/%Y:%H:%M:%S %z
</source>

# Treasure Data Input and Output
<match td.*.*>
  type tdlog
  apikey ${your_api_key} # TreasureDataのAPI-Key
  auto_create_table
  buffer_type file
  buffer_path /var/log/td-agent/buffer/td
  endpoint ybi.jp-east.idcfcloud.com
  flush_interval 10s
  use_ssl true
</match>

以下sourceタグ内のformatとtime_formatの意味です。

  • format: ログの正規表現を記載
  • time_format: 時刻のformatを記載

(?<host>[^ ]*)の意味は次の先頭が空白となるブロックまでの部分をhostというタグ名に紐付けるという意味です。

TreasureDataに入れたくないデータについては(?<xxxx>)を付けずに単純に[^${区切り文字}]*のようにすれば読み飛ばすことができます。

参考になるサイト

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?