ELK 由 ElasticSearch、Logstash 和 Kiabana 三个开源工具组成。
1. elasticsearch(es):它是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。
2. logstash:简单说是一个日志收集工具, 可以定义从哪里获取数据, 并且可以简单处理数据, 最后可以定义将数据输出到哪里, 一般输出到es。
3. kibana:其实就是一个数据展示界面, 并且可以分析数据, 例如从es中读取数据进行展示分析。es自己也带有简单的展示http://127.0.0.1:9200/_plugin/head/(得安装head插件)。
0. 软件套件版本
JDK:jdk-8u65-linux-x64.tar.gz
E:elasticsearch-2.2.0.tar.gz
L:logstash-all-plugins-2.2.0.tar.gz
K:kibana-4.4.1-linux-x64.tar.gz
1. 安装JDK
mkdir /usr/local/java
cd /usr/local/java
wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65-linux-x64.tar.gz”
tar -zxvf jdk-8u65-linux-x64.tar.gz -C .
vim /etc/profile
添加JAVA环境变量如下:
export JAVA_HOME=/usr/local/java/jdk1.8.0_65
export PATH= $PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH
重启机器或执行命令:
source /etc/profile
查看结果:
java -version
java version “1.8.0_65”
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
2. 安装elasticsearch
cd /usr/local
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.2.0/elasticsearch-2.2.0.tar.gz
tar -zxvf /home/jackgao/elasticsearch-2.2.0.tar.gz -C .
其中,
root@jackgao-virtual-machine:/usr/local# elasticsearch-2.2.0/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:285)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
root@jackgao-virtual-machine:/usr/local#
root用户启动失败,故得用普通用户启动,普通用户运行后还是有错误,还需在root用户下修改文件的用户为普通用户:
chown -R jackgao /usr/local/elasticsearch-2.2.0/
再运行就可以了:
./elasticsearch
安装head插件:
sudo elasticsearch/bin/plugin install mobz/elasticsearch-head
结果如下:
jackgao@jackgao-virtual-machine:/usr/local/elasticsearch-2.2.0/bin$ ./plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head…
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip …
Downloading …………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………….DONE
Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksums if available …
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
Installed head into /usr/local/elasticsearch-2.2.0/plugins/head
jackgao@jackgao-virtual-machine:/usr/local/elasticsearch-2.2.0/bin$
访问url:
http://localhost:9200/_plugin/head/
3. 安装logstash
cd /usr/local
wget https://download.elastic.co/logstash/logstash/logstash-2.2.0.tar.gz
tar -zxvf /home/jackgao/logstash-2.2.0.tar.gz -C .
cd logstash-2.2.0/bin/
./logstash -e ‘input { stdin { } } output { stdout {} }’ &
或
./logstash -f config/hello_search.conf
若运行错误,则还需再该用户下添加JAVA环境变量:
vim .bashrc
source .bashrc
4. 安装kibana
cd /usr/local
wget https://download.elastic.co/kibana/kibana/kibana-4.4.1-linux-x64.tar.gz
tar -zxvf /home/jackgao/kibana-4.4.1-linux-x64.tar.gz -C .
启动kibana:
bin/kibana
web访问:http://localhost:5601/
5. 测试
需先运行elasticsearch!再来运行logstash和kibana。
参考链接:
1. !Linux日志分析ELK环境搭建:
http://www.cnblogs.com/lixuwu/p/6116513.html
2. ELK在linux部署安装(一):
http://blog.csdn.net/loophome/article/details/52317209
3. 开源实时日志分析ELK平台部署:
http://www.tuicool.com/articles/QFvARfr
4. linux 部署ELK 日志分析系统与简单测试:
http://blog.csdn.net/gamer_gyt/article/details/52654263
5. 开源实时日志分析ELK平台部署:
http://www.tuicool.com/articles/QFvARfr