mfks17's blog(Life is Good !!)

趣味や思った事を書いていくと思います

Ubuntu12.04LTSにfluentdをインストールする

今回は、ずいぶん乗り遅れましたが、fluentdubuntuにインストールしていきたいと思います。
説明は必要ないかと思いますがfluentdは、Webアプリ、サーバ、ApacheのアクセスログなどをJSON形式で吐いて、メールしたり、ファイルにしたり、他のfluentdに投げたりするとても便利なツールです。

アーキテクチャや実際の構成など、こちらのスライドがわかりやすかったです。

では、張り切ってインストールしていきます。

参考サイト様

やることは至ってシンプルでコマンド一発です。

$ curl -L http://toolbelt.treasure-data.com/sh/install-ubuntu-precise.sh | sh

以下ログです。

$ curl -L http://toolbelt.treasure-data.com/sh/install-ubuntu-precise.sh | sh  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 483 100 483 0 0 353 0 0:00:01 0:00:01 --:--:-- 2427
This script requires superuser access to install apt packages.
You will be prompted for your password by sudo.
[sudo] password for typosterr: 
無視 http://jp.archive.ubuntu.com precise InRelease
無視 http://jp.archive.ubuntu.com precise-updates InRelease                                                                          
無視 http://jp.archive.ubuntu.com precise-backports InRelease                                                                        
ヒット http://jp.archive.ubuntu.com precise Release.gpg                                                                              
ヒット http://jp.archive.ubuntu.com precise-updates Release.gpg                                                                      
ヒット http://jp.archive.ubuntu.com precise-backports Release.gpg                            
ヒット http://jp.archive.ubuntu.com precise Release                                          
ヒット http://jp.archive.ubuntu.com precise-updates Release                                                                          
ヒット http://jp.archive.ubuntu.com precise-backports Release                                                                        
ヒット http://jp.archive.ubuntu.com precise/main Sources                                                                             
ヒット http://jp.archive.ubuntu.com precise/restricted Sources                                                                       
ヒット http://jp.archive.ubuntu.com precise/universe Sources                                                                         
ヒット http://jp.archive.ubuntu.com precise/multiverse Sources                                                                       
ヒット http://jp.archive.ubuntu.com precise/main amd64 Packages                                                                      
ヒット http://jp.archive.ubuntu.com precise/restricted amd64 Packages                                                      
ヒット http://jp.archive.ubuntu.com precise/universe amd64 Packages                                                        
ヒット http://jp.archive.ubuntu.com precise/multiverse amd64 Packages                                                      
ヒット http://jp.archive.ubuntu.com precise/main i386 Packages                                                             
ヒット http://jp.archive.ubuntu.com precise/restricted i386 Packages                                                       
ヒット http://jp.archive.ubuntu.com precise/universe i386 Packages                                                         
ヒット http://jp.archive.ubuntu.com precise/multiverse i386 Packages                                                       
ヒット http://jp.archive.ubuntu.com precise/main TranslationIndex                                                          
ヒット http://jp.archive.ubuntu.com precise/multiverse TranslationIndex                                                    
無視 http://packages.treasure-data.com lucid InRelease                                                                     
無視 http://packages.treasure-data.com precise InRelease                                                                   
無視 http://security.ubuntu.com precise-security InRelease                                                                 
ヒット http://jp.archive.ubuntu.com precise/restricted TranslationIndex                      
ヒット http://jp.archive.ubuntu.com precise/universe TranslationIndex                        
ヒット http://jp.archive.ubuntu.com precise-updates/main Sources                             
ヒット http://jp.archive.ubuntu.com precise-updates/restricted Sources                       
ヒット http://jp.archive.ubuntu.com precise-updates/universe Sources                         
ヒット http://jp.archive.ubuntu.com precise-updates/multiverse Sources                                                     
ヒット http://jp.archive.ubuntu.com precise-updates/main amd64 Packages                                                    
ヒット http://jp.archive.ubuntu.com precise-updates/restricted amd64 Packages                                              
ヒット http://jp.archive.ubuntu.com precise-updates/universe amd64 Packages                                                
ヒット http://jp.archive.ubuntu.com precise-updates/multiverse amd64 Packages                                              
ヒット http://jp.archive.ubuntu.com precise-updates/main i386 Packages                                                     
ヒット http://jp.archive.ubuntu.com precise-updates/restricted i386 Packages                                               
ヒット http://jp.archive.ubuntu.com precise-updates/universe i386 Packages                                                 
ヒット http://jp.archive.ubuntu.com precise-updates/multiverse i386 Packages                                               
ヒット http://jp.archive.ubuntu.com precise-updates/main TranslationIndex                                                  
ヒット http://jp.archive.ubuntu.com precise-updates/multiverse TranslationIndex                                            
ヒット http://jp.archive.ubuntu.com precise-updates/restricted TranslationIndex                                            
ヒット http://jp.archive.ubuntu.com precise-updates/universe TranslationIndex                                              
ヒット http://jp.archive.ubuntu.com precise-backports/main Sources                                                         
ヒット http://jp.archive.ubuntu.com precise-backports/restricted Sources                                                   
無視 http://ppa.launchpad.net precise InRelease                                                                            
無視 http://ppa.launchpad.net precise InRelease                                                                            
ヒット http://jp.archive.ubuntu.com precise-backports/universe Sources                                                     
ヒット http://jp.archive.ubuntu.com precise-backports/multiverse Sources                     
ヒット http://jp.archive.ubuntu.com precise-backports/main amd64 Packages                    
ヒット http://jp.archive.ubuntu.com precise-backports/restricted amd64 Packages              
ヒット http://jp.archive.ubuntu.com precise-backports/universe amd64 Packages                
ヒット http://jp.archive.ubuntu.com precise-backports/multiverse amd64 Packages                                            
ヒット http://jp.archive.ubuntu.com precise-backports/main i386 Packages                                                   
ヒット http://jp.archive.ubuntu.com precise-backports/restricted i386 Packages                                             
ヒット http://jp.archive.ubuntu.com precise-backports/universe i386 Packages                                               
ヒット http://jp.archive.ubuntu.com precise-backports/multiverse i386 Packages                                             
ヒット http://jp.archive.ubuntu.com precise-backports/main TranslationIndex                                                
ヒット http://jp.archive.ubuntu.com precise-backports/multiverse TranslationIndex                                          
ヒット http://jp.archive.ubuntu.com precise-backports/restricted TranslationIndex            
ヒット http://jp.archive.ubuntu.com precise-backports/universe TranslationIndex              
ヒット http://jp.archive.ubuntu.com precise/main Translation-ja                              
ヒット http://jp.archive.ubuntu.com precise/main Translation-en                                                            
ヒット http://jp.archive.ubuntu.com precise/multiverse Translation-ja                                                      
ヒット http://jp.archive.ubuntu.com precise/multiverse Translation-en                        
ヒット http://jp.archive.ubuntu.com precise/restricted Translation-ja                        
ヒット http://jp.archive.ubuntu.com precise/restricted Translation-en                        
ヒット http://jp.archive.ubuntu.com precise/universe Translation-ja                          
ヒット http://jp.archive.ubuntu.com precise/universe Translation-en                          
ヒット http://jp.archive.ubuntu.com precise-updates/main Translation-ja                      
ヒット http://jp.archive.ubuntu.com precise-updates/main Translation-en                      
ヒット http://jp.archive.ubuntu.com precise-updates/multiverse Translation-ja                
無視 http://packages.treasure-data.com lucid Release.gpg                                     
ヒット http://jp.archive.ubuntu.com precise-updates/multiverse Translation-en                
ヒット http://jp.archive.ubuntu.com precise-updates/restricted Translation-en                
ヒット http://jp.archive.ubuntu.com precise-updates/universe Translation-ja                  
ヒット http://jp.archive.ubuntu.com precise-updates/universe Translation-en                  
ヒット http://jp.archive.ubuntu.com precise-backports/main Translation-en                    
ヒット http://security.ubuntu.com precise-security Release.gpg                               
ヒット http://jp.archive.ubuntu.com precise-backports/multiverse Translation-en              
ヒット http://jp.archive.ubuntu.com precise-backports/restricted Translation-en              
ヒット http://jp.archive.ubuntu.com precise-backports/universe Translation-en                
無視 http://ppa.launchpad.net precise Release.gpg                                            
無視 http://packages.treasure-data.com precise Release.gpg                                   
ヒット http://security.ubuntu.com precise-security Release     
ヒット http://packages.treasure-data.com lucid Release                                
ヒット http://ppa.launchpad.net precise Release.gpg            
ヒット http://security.ubuntu.com precise-security/main Sources
取得:1 http://packages.treasure-data.com precise Release [2,377 B]
無視 http://ppa.launchpad.net precise Release                                                  
ヒット http://security.ubuntu.com precise-security/restricted Sources
ヒット http://security.ubuntu.com precise-security/universe Sources
ヒット http://security.ubuntu.com precise-security/multiverse Sources
ヒット http://security.ubuntu.com precise-security/main amd64 Packages
ヒット http://security.ubuntu.com precise-security/restricted amd64 Packages
ヒット http://security.ubuntu.com precise-security/universe amd64 Packages
ヒット http://security.ubuntu.com precise-security/multiverse amd64 Packages
ヒット http://security.ubuntu.com precise-security/main i386 Packages
ヒット http://security.ubuntu.com precise-security/restricted i386 Packages
ヒット http://security.ubuntu.com precise-security/universe i386 Packages
無視 http://packages.treasure-data.com lucid/contrib Sources/DiffIndex
無視 http://packages.treasure-data.com lucid/contrib amd64 Packages/DiffIndex                
無視 http://packages.treasure-data.com lucid/contrib i386 Packages/DiffIndex                 
無視 http://packages.treasure-data.com lucid/contrib TranslationIndex                        
ヒット http://ppa.launchpad.net precise Release                                              
ヒット http://security.ubuntu.com precise-security/multiverse i386 Packages                                         
無視 http://packages.treasure-data.com precise/contrib TranslationIndex                      
ヒット http://security.ubuntu.com precise-security/main TranslationIndex                     
ヒット http://security.ubuntu.com precise-security/multiverse TranslationIndex
ヒット http://security.ubuntu.com precise-security/restricted TranslationIndex
ヒット http://security.ubuntu.com precise-security/universe TranslationIndex
無視 http://ppa.launchpad.net precise/main TranslationIndex    
ヒット http://security.ubuntu.com precise-security/main Translation-en
ヒット http://security.ubuntu.com precise-security/multiverse Translation-en
ヒット http://security.ubuntu.com precise-security/restricted Translation-en
ヒット http://ppa.launchpad.net precise/main Sources           
ヒット http://ppa.launchpad.net precise/main amd64 Packages    
ヒット http://ppa.launchpad.net precise/main i386 Packages     
無視 http://ppa.launchpad.net precise/main TranslationIndex    
ヒット http://security.ubuntu.com precise-security/universe Translation-en                   
取得:2 http://packages.treasure-data.com precise/contrib amd64 Packages [446 B]              
取得:3 http://packages.treasure-data.com precise/contrib i386 Packages [449 B]
ヒット http://packages.treasure-data.com lucid/contrib Sources 
ヒット http://packages.treasure-data.com lucid/contrib amd64 Packages                
ヒット http://packages.treasure-data.com lucid/contrib i386 Packages
無視 http://packages.treasure-data.com lucid/contrib Translation-ja_JP
無視 http://packages.treasure-data.com lucid/contrib Translation-ja
無視 http://packages.treasure-data.com lucid/contrib Translation-en
無視 http://packages.treasure-data.com precise/contrib Translation-ja_JP
無視 http://packages.treasure-data.com precise/contrib Translation-ja
無視 http://packages.treasure-data.com precise/contrib Translation-en
エラー http://ppa.launchpad.net precise/main Sources            
  404 Not Found
エラー http://ppa.launchpad.net precise/main amd64 Packages
  404 Not Found
エラー http://ppa.launchpad.net precise/main i386 Packages
  404 Not Found
無視 http://ppa.launchpad.net precise/main Translation-ja_JP
無視 http://ppa.launchpad.net precise/main Translation-ja
無視 http://ppa.launchpad.net precise/main Translation-en
無視 http://ppa.launchpad.net precise/main Translation-ja_JP
無視 http://ppa.launchpad.net precise/main Translation-ja
無視 http://ppa.launchpad.net precise/main Translation-en
3,272 B を 5秒 で取得しました (617 B/s)
W: http://ppa.launchpad.net/brianmercer/php5/ubuntu/dists/precise/main/source/Sources の取得に失敗しました 404 Not Found

W: http://ppa.launchpad.net/brianmercer/php5/ubuntu/dists/precise/main/binary-amd64/Packages の取得に失敗しました 404 Not Found

W: http://ppa.launchpad.net/brianmercer/php5/ubuntu/dists/precise/main/binary-i386/Packages の取得に失敗しました 404 Not Found

E: いくつかのインデックスファイルのダウンロードに失敗しました。これらは無視されるか、古いものが代わりに使われます。
パッケージリストを読み込んでいます… 完了
依存関係ツリーを作成しています                
状態情報を読み取っています… 完了
以下の特別パッケージがインストールされます:

  libcap2 libopts25 libssl0.9.8 ntp

提案パッケージ:

  ntp-doc

以下のパッケージが新たにインストールされます:

  libcap2 libopts25 libssl0.9.8 ntp td-agent

アップグレード: 0 個、新規インストール: 5 個、削除: 0 個、保留: 8 個。
15.0 MB のアーカイブを取得する必要があります。
この操作後に追加で 54.4 MB のディスク容量が消費されます。
警告: 以下のパッケージは認証されていません!

  td-agent

取得:1 http://jp.archive.ubuntu.com/ubuntu/ precise-updates/universe libssl0.9.8 amd64 0.9.8o-7ubuntu3.1 [861 kB]
取得:2 http://jp.archive.ubuntu.com/ubuntu/ precise/main libcap2 amd64 1:2.22-1ubuntu3 [12.0 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu/ precise/main libopts25 amd64 1:5.12-0.1ubuntu1 [59.9 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu/ precise-updates/main ntp amd64 1:4.2.6.p3+dfsg-1ubuntu3.1 [612 kB]
取得:5 http://packages.treasure-data.com/debian/ lucid/contrib td-agent amd64 1.1.11-1 [13.4 MB]
15.0 MB を 9秒 で取得しました (1,515 kB/s)                                                                                           
パッケージを事前設定しています …
以前に未選択のパッケージ libssl0.9.8 を選択しています。
(データベースを読み込んでいます ... 現在 57537 個のファイルとディレクトリがインストールされています。)
(.../libssl0.9.8_0.9.8o-7ubuntu3.1_amd64.deb から) libssl0.9.8 を展開しています…
以前に未選択のパッケージ libcap2 を選択しています。
(.../libcap2_1%3a2.22-1ubuntu3_amd64.deb から) libcap2 を展開しています…
以前に未選択のパッケージ libopts25 を選択しています。
(.../libopts25_1%3a5.12-0.1ubuntu1_amd64.deb から) libopts25 を展開しています…
以前に未選択のパッケージ ntp を選択しています。
(.../ntp_1%3a4.2.6.p3+dfsg-1ubuntu3.1_amd64.deb から) ntp を展開しています…
以前に未選択のパッケージ td-agent を選択しています。
(.../td-agent_1.1.11-1_amd64.deb から) td-agent を展開しています…
ureadahead のトリガを処理しています …
ureadahead will be reprofiled on next reboot
man-db のトリガを処理しています …
libssl0.9.8 (0.9.8o-7ubuntu3.1) を設定しています …
libcap2 (1:2.22-1ubuntu3) を設定しています …
libopts25 (1:5.12-0.1ubuntu1) を設定しています …
ntp (1:4.2.6.p3+dfsg-1ubuntu3.1) を設定しています …

 * Starting NTP server ntpd [ OK ] 

td-agent (1.1.11-1) を設定しています …
システムユーザ `td-agent' (UID 106) を追加しています…
新しいグループ `td-agent' (GID 112) を追加しています…
新しいユーザー `td-agent' (UID 106) をグループ `td-agent' に追加しています…
ホームディレクトリ `/home/td-agent' を作成しません。
Installing default conffile /etc/td-agent/td-agent.conf …

 * Starting td-agent td-agent [ OK ] 

libc-bin のトリガを処理しています …
ldconfig deferred processing now taking place

あっさり入りました。もう動いてるようです。
起動や停止のコマンドは以下のようになってます。

$ /etc/init.d/td-agent start
$ /etc/init.d/td-agent stop
$ /etc/init.d/td-agent restart

fluentdのコマンドツール群が

/usr/lib/fluent/ruby/bin/

にあるので、お好きなシェルのリソースファイルにPathを追加しておきます。

$ vi .bashrc
export PATH="/usr/lib/fluent/ruby/bin/:$PATH"

これで以下のコマンドが使えるようになったはずです。

$ ls /usr/lib/fluent/ruby/bin/
b2json        fluent-cat           fluent-post           httparty  mongo-tail        rake  td
bundle        fluent-debug         fluent-scribe-remote  irb       mongo_console     rdoc  testrb
edit_json.rb  fluent-flume-remote  fluentd               j2bson    nokogiri          ri
erb           fluent-gem           gem                   jeweler   prettify_json.rb  ruby

たとえば

$ fluent-gem 
RubyGems is a sophisticated package manager for Ruby.  This is a
basic help message containing pointers to more information.

  Usage:
    gem -h/--help
    gem -v/--version
    gem command [arguments...] [options...]

  Examples:
    gem install rake
    gem list --local
    gem build package.gemspec
    gem help install

  Further help:
    gem help commands            list all 'gem' commands
    gem help examples            show some examples of usage
    gem help platforms           show information about platforms
    gem help            show help on COMMAND
                                   (e.g. 'gem help install')
    gem server                   present a web page at
                                 http://localhost:8808/
                                 with info about installed gems
  Further information:
    http://rubygems.rubyforge.org

ということで、インストールできました。
つぎは、実際にログの出力をやりたいと思います。
まとめサイトがあったので貼っておきますね。

最後までお読みいただき、ありがとうございましたm(_ _)m