Last active
January 31, 2016 12:07
-
-
Save masayuki5160/4965afa92d9adc2e3061 to your computer and use it in GitHub Desktop.
elasticsearchをちゃんとさわってみたときの作業ログ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
stdin { } | |
} | |
filter { | |
grok { | |
match => { "message" => "%{COMBINEDAPACHELOG}" } | |
} | |
date { | |
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] | |
locale => "en" | |
} | |
mutate { | |
replace => { "type" => "apache_access" } | |
} | |
} | |
output { | |
# stdout { codec => rubydebug } | |
elasticsearch { host => '172.17.4.199' } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
============================== | |
Elasticsearch] | |
-- 1.x系と2.x系がある | |
-- EC2上でテスト | |
============================== | |
********************************* | |
* Elasticsearchのインストール | |
********************************* | |
$wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.4.noarch.rpm | |
$sudo yum install elasticsearch-1.7.4.noarch.rpm | |
* Elasticsearch起動 | |
$sudo service elasticsearch start | |
* logの確認 | |
$tail -f /var/log/elasticsearch/elasticsearch.log | |
* kuromojiの追加(日本語検索用のプラグイン) | |
$sudo /usr/share/elasticsearch/bin/plugin install elasticsearch/elasticsearch-analysis-kuromoji/2.6.0 | |
$sudo service elasticsearch restart | |
********************************* | |
* Elasticsearch動作テスト | |
********************************* | |
-- データ登録 | |
$curl -XPUT http://localhost:9200/mytest/test/1 -d ' | |
{ | |
"title" : "hogehoge", | |
"text" : "fugafuga" | |
}' | |
-- データ検索 | |
$curl -XGET 'localhost:9200/mytest/test/1?pretty=true' | |
-- kuromojiのテスト | |
$curl -XPUT 'http://localhost:9200/kuromoji_test/' -d' | |
{ | |
"index":{ | |
"analysis":{ | |
"tokenizer" : { | |
"kuromoji" : { | |
"type" : "kuromoji_tokenizer" | |
} | |
}, | |
"analyzer" : { | |
"analyzer" : { | |
"type" : "custom", | |
"tokenizer" : "kuromoji" | |
} | |
} | |
} | |
} | |
}' | |
- kuromojiに文字列をなげる(形態素解析の結果確認) | |
$curl -XPOST 'http://localhost:9200/kuromoji_test/_analyze?analyzer=analyzer&petty' -d '私はビールが大好きです' | |
- kuromojiで日本語の検索可能かのテスト | |
$curl -XPUT http://localhost:9200/mytest/test/1 -d ' | |
{ | |
"title" : "テストだよ", | |
"text" : "イケてるサービス作ろうze!" | |
}' | |
$curl -XPUT http://localhost:9200/mytest/test/2 -d ' | |
{ | |
"title" : "テストだよ2", | |
"text" : "ビールうましうまし" | |
}' | |
$ curl -XGET http://localhost:9200/mytest/test/_search -d ' | |
{ | |
"query": { | |
"match":{"text":"イケてる"} | |
} | |
}' | |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
+ 以下検索結果 | |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
$ curl -XGET http://localhost:9200/mytest/test/_search -d ' | |
> { | |
> "query": { | |
> "match":{"text":"イケてる"} | |
> } | |
> }' | |
{"took":58,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.16608897,"hits":[{"_index":"mytest","_type":"test","_id":"1","_score":0.16608897,"_source": | |
{ | |
"title" : "テストだよ", | |
"text" : "イケてるサービス作ろうze!" | |
}}]}} | |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
********************************* | |
* logstashのセットアップ(ストリーミング用) | |
********************************* | |
$wget https://download.elastic.co/logstash/logstash/packages/centos/logstash-1.5.3-1.noarch.rpm | |
$sudo rpm -ivh logstash-1.5.3-1.noarch.rpm | |
- バージョン、インストール確認 | |
$/opt/logstash/bin/logstash --version | |
- パスを通す | |
$export PATH=$PATH:/opt/logstash/bin | |
- Logstashの実行 | |
inputとしてTwitterを指定. 全てのtweetを対象に、"aws"というキーワードで取得. | |
$logstash -e 'input { | |
twitter { | |
consumer_key => "*******************" | |
consumer_secret => "*******************" | |
oauth_token => "*******************" | |
oauth_token_secret => "*******************" | |
keywords => ["aws"] | |
full_tweet => true | |
}} | |
output { | |
elasticsearch | |
{ host => localhost | |
port => "9200" | |
protocol => "http" | |
index => "twitter" | |
document_type => "stream" | |
} | |
stdout { } }' | |
********************************* | |
* Kibana4のインストール | |
********************************* | |
- 起動まで | |
$wget https://download.elastic.co/kibana/kibana/kibana-4.1.4-linux-x64.tar.gz | |
$tar xvfz kibana-4.1.4-linux-x64.tar.gz | |
$cd kibana-4.1.4-linux-x64 | |
$sudo ./bin/kibana | |
- 管理画面へのアクセス | |
ブラウザよりhttp://EC2のIPアドレス:5601/へアクセス | |
------------------- | |
-- 参考 | |
------------------- | |
EC2インスタンスにelasticsearchをインストールする | |
http://qiita.com/monhan/items/2926c0b1e50366b7cf49 | |
Logstash + Elasticsearch + Kibana4でTwitterを可視化する | |
http://dev.classmethod.jp/cloud/aws/twitter-visualize-using-elastic/ | |
logstash便利そうだ
/opt/logstash/bin/logstash -f apache-import.conf < "ログのパス"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yumですんなりはいるんかい
15分で作る、Logstash+Elasticsearchによるログ収集・解析環境
http://knowledge.sakura.ad.jp/tech/2736/