安裝ELK ,版本以下:
Elasticsearch 2.3.5
Logstash 2.3.4
Kibana 4.5.4
下載地址,請參考官網
1、ES
一、啓動
[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 啓動成功
二、修改elasticsearch.yml
cluster.name 和 node.name
以及 network.host 爲服務器ip
三、安裝 elasticsearch 的插件head:
安裝:
./elasticsearch/bin/plugin install mobz/elasticsearch-head
訪問:
完全解決啓動elasticSearch 時,建議不要用root 用戶啓動的warning :
因爲ElasticSearch能夠接收用戶輸入的腳本而且執行,爲了系統安全考慮,
建議建立一個單獨的用戶用來運行ElasticSearch
一、建立elsearch用戶組及elsearch用戶
groupadd elsearch
二、更改elasticsearch文件夾及內部文件的所屬用戶及組爲elsearch:elsearch
useradd elsearch -g elsearch -p elasticsearch
三、屏蔽掉 bin/elasticsearch 文件的 ES_JAVA_OPTS="-Des.insecure.allow.root=true"
四、給/elasticsearch/logs 和 data 裏面的文件可寫權限 chmod -R 777 logs,chmod -R 777 data
五、切換到elsearch 用戶, su elsearch ,再運行
2、Logstash:
一、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"]
}
}
二、啓動
[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
3、kibana
一、修改kibana.yml 裏面的
server.host ,elasticsearch_url 以及 去掉 kibana.index 的註釋
./kibana 啓動
4、kibana 鏈接es 索引
一、導入json數據到es 中
curl -XPOST '10.100.100.60:9200/shakespeare/_bulk?pretty' --data-binary @shakespeare.json
二、從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 能鏈接上
以上的服務啓動都不是後臺啓動,後臺啓動請加上 &