安裝ELK ,版本如下:
Elasticsearch 2.3.5
Logstash 2.3.4
Kibana 4.5.4
下載地址,請參考官網
一、ES
1、啟動
[root@elasticseach1 bin]# ./elasticsearch start
ERROR: Parameter [start]does not start with --
[root@elasticseach1 bin]# ./elasticsearch
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
解決方法1:
在執行elasticSearch時加上參數-Des.insecure.allow.root=true,完整命令如下:
./elasticsearch -Des.insecure.allow.root=true
解決辦法2:
用vi打開elaticsearch執行文件,在變量ES_JAVA_OPTS使用前添加以下命令:
ES_JAVA_OPTS="-Des.insecure.allow.root=true"

修改后,./elasticsearch 啟動成功
2、修改elasticsearch.yml
cluster.name 和 node.name
以及 network.host 為服務器ip
3、安裝 elasticsearch 的插件head:
安裝:
./elasticsearch/bin/plugin install mobz/elasticsearch-head
訪問:
徹底解決啟動elasticSearch 時,建議不要用root 用戶啟動的warning :
由於ElasticSearch可以接收用戶輸入的腳本並且執行,為了系統安全考慮,
建議創建一個單獨的用戶用來運行ElasticSearch
1、創建elsearch用戶組及elsearch用戶
groupadd elsearch
2、更改elasticsearch文件夾及內部文件的所屬用戶及組為elsearch:elsearch
useradd elsearch -g elsearch -p elasticsearch
3、屏蔽掉 bin/elasticsearch 文件的 ES_JAVA_OPTS="-Des.insecure.allow.root=true"
4、給/elasticsearch/logs 和 data 里面的文件可寫權限 chmod -R 777 logs,chmod -R 777 data
5、切換到elsearch 用戶, su elsearch ,再運行
二、Logstash:
1、bin 目錄下新建 etc 目錄,
vi logstash/etc/logstash_agent.conf
input {
file {
type => "nginx.access"
path =>["/data/nginx/logs/access.log"]
}
}
output {
elasticsearch {
hosts => ["10.100.100.60:9300"]
}
}
2、啟動
[root@elasticseach1 bin]# ./logstash -f etc/logstash_agent.conf
Settings: Default pipeline workers: 2
The server failed to respond with a valid HTTP response {:class=>"Manticore::ClientProtocolException", :level=>:error}
Pipeline main started 報錯
vi logstash/etc/logstash_agent.conf 修改為:
input {
file {
type => "nginx.access"
path =>["/data/nginx/logs/access.log"]
}
}
output {
# stdout{}
elasticsearch {
hosts => ["10.100.100.60:9200"]
index => "test_output-%{type}-%{+YYYY.MM.dd}"
}
}
重新啟動,成功
Settings: Default pipeline workers: 2
Pipeline main started
三、kibana
1、修改kibana.yml 里面的
server.host ,elasticsearch_url 以及 去掉 kibana.index 的注釋
./kibana 啟動
四、kibana 連接es 索引
1、導入json數據到es 中
curl -XPOST '10.100.100.60:9200/shakespeare/_bulk?pretty' --data-binary @shakespeare.json
2、從redis 中導入數據到es
# 10.100.100.60:6379 ,成功
input {
redis {
host => "10.100.100.60"
type => "redis-input"
data_type => "list"
key => "elk_data"
}
}
output {
elasticsearch {
hosts => ["10.100.100.60:9200"]
index => "logstash-%{type}-%{+YYYY.MM.dd}"
}
}
從 兩台redis 里面導數據
input {
redis {
host => "10.100.100.60"
type => "redis-60-input"
data_type => "list"
key => "elk_data"
}
redis {
host => "10.100.100.35"
type => "redis-35-input"
data_type => "list"
key => "elk_data"
}
}
output {
elasticsearch {
hosts => ["10.100.100.60:9200"]
index => "logstash-%{type}-%{+YYYY.MM.dd}"
}
}
要注意 redis 能連接上
以上的服務啟動都不是后台啟動,后台啟動請加上 &