Elasticsearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特色有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。java
Logstash 主要是用来日志的搜集、分析、过滤日志的工具,支持大量的数据获取方式。通常工做方式为c/s架构,client端安装在须要收集日志的主机上,server端负责将收到的各节点日志进行过滤、修改等操做在一并发往elasticsearch上去。node
Kibana 也是一个开源和免费的工具,Kibana能够为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,能够帮助汇总、分析和搜索重要数据日志。linux
主机名 | IP地址 | 所需软件 |
---|---|---|
node-1 | 192.168.144.114 | jdk八、elasticsearch2.4.六、logstash2.1.三、kibana-4.3.1-linux-x64.tar.gz |
node-2 | 192.168.144.117 | jdk八、elasticsearch2.4.6 |
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearchgithub
vim elasticsearch.repobootstrap
[elasticsearch-2.x] name=Elasticsearch repository for 2.x packages baseurl=http://packages.elastic.co/elasticsearch/2.x/centos gpgcheck=1 gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch enable=1
yum install elasticsearch -yvim
yum install java -y (1.8版本)centos
java -versionrestful
vim /etc/elasticsearch/elasticsearch.yml网络
17行 集群名称 cluster.name: yun 23行 节点名称 node.name: linux-node1 33行 工做目录 path.data: /data/es-data //这两个目录建议更改,若采用默认格式,版本更新可能会被默认删除 path.logs: /var/log/elasticsearch/ //建立这两个目录后,注意目录属主属组权限 43行 防止交换swap分区 bootstrap.memory_lock: true 54行 监听网络 network.host: 0.0.0.0 58行 端口 http.port: 9200 69行 单播列表自动发现机制 discovery.zen.ping.unicast.hosts: ["127.0.0.1", "192.168.144.117"] //一个本地IP,一个节点2IP
mkdir -p /data/es-data
chown -R elasticsearch:elasticsearch /data/es-data/
systemctl start elasticsearch.service
netstat -ntap | grep 9200
在打开防止交换分区功能后,在es启动日志中可观察到以下信息:
vim /var/log/elasticsearch/abner.log
... [2018-08-19 22:01:12,224][WARN ][bootstrap ] These can be adjusted by modifying /etc/security/limits.conf, for example: # allow user 'elasticsearch' mlockall elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited ...
vim /etc/security/limits.conf
//末尾插入 # allow user 'elasticsearch' mlockall elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited * soft nofile 65535 * hard nofile 65535 //需重启生效
/usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
/usr/share/elasticsearch/bin/plugin list
/usr/share/elasticsearch/plugins/head
cat /etc/elasticsearch/elasticsearch.yml | grep -v "^#" | grep -v "^$"
cluster.name: yun //注意:统一群集下,使用的群集名称需相同 node.name: node-2 path.data: /data/es-data path.logs: /var/log/elasticsearch bootstrap.memory_lock: true network.host: 0.0.0.0 http.port: 9200 discovery.zen.ping.unicast.hosts: ["192.168.144.117", "192.168.144.114"]
mkdir -p /data/es-data 建立工做目录
chown -R elasticsearch:elasticsearch /data/es-data/
systemctl start elasticsearch.service
netstat -ntap | grep 9200
/usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
http://192.168.144.114:9200/_plugin/kopf/#!/cluster
为了试验方便起见,本次logstash服务部署在es节点1上。而且将收集到的日志传递给es进行处理。
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
vim /etc/yum.repos.d/logstash.repo
[logstash-2.1] name=Logstash repository for 2.1.x packages baseurl=http://packages.elastic.co/logstash/2.1/centos gpgcheck=1 gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch enable=1
yum install logstash -y
ln -s /opt/logstash/bin/logstash /usr/bin/
vim file.conf
input { file { path => "/var/log/httpd/access_log" type => "accesslog" start_position => "beginning" } file { path => "/var/log/httpd/error_log" type => "errorlog" start_position => "beginning" } } output { if [type] == "accesslog" { elasticsearch { hosts => ["192.168.144.114:9200"] //将日志收集数据传递给es index => "access-%{+YYYY.MM.dd}" } } if [type] == "errorlog" { elasticsearch { hosts => ["192.168.144.114:9200"] index => "error-%{+YYYY.MM.dd}" } } }
wget https://download.elastic.co/kibana/kibana/kibana-4.3.1-linux-x64.tar.gz
tar zxvf kibana-4.3.1-linux-x64.tar.gz -C /opt/
mv kibana-4.3.1-linux-x64/ /usr/local/
mv kibana-4.3.1-linux-x64/ kibana
vim /usr/local/kibana/config/kibana.yml
//2行 server.port: 5601 //5行 server.host: "0.0.0.0" //12行 ES地址 elasticsearch.url: "http://192.168.175.132:9200" //20行 kibana.index: ".kibana"
yum install screen -y
screen 换屏操做
/usr/local/kibana/bin/kibana
ctrl+a+d