一、安装elasticsearch
下载解压启动
然后编辑ES的配置文件:
vi config/elasticsearch.yml
修改以下配置项:
cluster.name=es_cluster node.name=node0 path.data=/tmp/elasticsearch/data path.logs=/tmp/elasticsearch/logs #当前hostname或IP,我这里是centos2 network.host=centos2 network.port=9200
其他的选项保持默认,然后启动ES:可以看到,它跟其他的节点的传输端口为9300,接受HTTP请求的端口为9200。
./elasticsearch -d -p pidfile
设置集群名节点名
./elasticsearch --cluster.name my_cluster_name --node.name my_node_name
然后可以打开页面localhost:9200
安装Head插件(Optional):
./bin/plugin install mobz/elasticsearch-head
刚刚安装的head插件,它是一个用浏览器跟ES集群交互的插件,可以查看集群状态、集群的doc内容、执行搜索和普通的Rest请求等。现在也可以使用它打开localhost:9200/_plugin/head页面来查看ES集群状态.
二、安装Logstash
其实它就是一个收集器而已,我们需要为它指定Input和Output(当然Input和Output可以为多个)。由于我们需要把Java代码中Log4j的日志输出到ElasticSearch中,因此这里的Input就是Log4j,而Output就是ElasticSearch。
下载解压:
tar -zxvf logstash-2.1.1.tar.gz cd logstash-2.1.1
编写配置文件(名字和位置可以随意,这里我放在config目录下,取名为log4j_to_es.conf):
mkdir config vi config/file_to_es.conf
# For detail structure of this file # Set: https://www.elastic.co/guide/en/logstash/current/configuration-file-structure.html input { # For detail config for log4j as input, # See: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-log4j.html file { path => "/home/elk/files/*" } } filter { #Only matched data are send to output. } output { # For detail config for elasticsearch as output, # See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html elasticsearch { action => "index" #The operation on ES hosts => "112.74.95.112:9200" #ElasticSearch host, can be array. index => "ec" #The index to write data to, can be any string. } }
启动它(使用-f指定配置文件)
./bin/logstash agent -f config/file_to_es.conf
三、安装Kibana
下载解压配置Kibana:
tar -zxvf kibana-4.3.0-linux-x86.tar.gz cd kibana-4.3.0-linux-x86 vi config/kibana.yml
修改以下几项(由于是单机版的,因此host的值也可以使用localhost来代替,这里仅仅作为演示):
server.port: 5601 server.host: “centos2” elasticsearch.url: http://centos2:9200 kibana.index: “.kibana”
启动kibana:
./bin/kibana
用浏览器打开该地址: http://n1.louyj.top:5601 , 接下来就能看到ES中的数据了
No Leanote account? Sign up now.