1,安装环境查看
2,下载rmp包
下载地址:https://www.elastic.co/cn/downloads 分别下载最新rmp包
elasticsearch-6.2.4.rpm logstash-6.2.4.rpm kibana-6.2.4-x86_64.rpm
下载rpm包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.rpm wget https://artifacts.elastic.co/downloads/logstash/logstash-6.2.4.rpm wget https://artifacts.elastic.co/downloads/kibana/kibana-6.2.4-x86_64.rpm
3,安装
需要事先安装java
yum -y install java
安装elasticssearch
rpm -ivh elasticsearch-6.2.4.rpm
安装logstash
rpm -ivh logstash-6.2.4.rpm
安装kibana
rpm -ivh kibana-6.2.4-x86_64.rpm
4,配置
修改elasticsearch配置文件/etc/elasticsearch/elasticsearch.yml
cluster.name: myes #集群名字 node.name: node-1 #node名字 path.data: /nas/ELK/es-data #日志数据路径 path.logs: /var/log/elasticsearch #日志路径 bootstrap.memory_lock: false network.host: 192.168.56.12 #本机地址 http.port: 9200 #开启端口9200
修改日志数据文件夹权限(不修改无法启动)
chown -R elasticsearch.elasticsearch /nas/ELK/es-data/
启动
systemctl start elasticsearch systemctl enable elasticsearch
访问测试
搜索测试
curl -i -XGET 'http://192.168.56.12:9200/_count?'
安装head插件
参考:ELK(Elasticsearch6.0及其head插件安装)
打开head插入数据
插入后浏览
暂时未做集群
集群健康状态检查
curl -XGET 'http://192.168.56.12:9200/_cluster/health?pretty=true'
5,logstash实战
logstash用于日志收集
启动(标准输入标准输出模式)启动需要一点点时间
/usr/share/logstash/bin/logstash -e 'input { stdin{} } output { stdout{} }'
以json方式输出
/usr/share/logstash/bin/logstash -e 'input { stdin{} } output { stdout{ codec ==> rubydebug } }'
PS:stdin和stdout和后面{}不能有空格,否则无法运行
输出到es
/usr/share/logstash/bin/logstash -e 'input { stdin{} } output { elasticsearch { hosts => ["192.168.56.12:9200"] index => "logstash-%{+YYYY.MM.dd}" } }'
命令行输入没反应
查看head的web界面
在命令行输出以及输入到es
/usr/share/logstash/bin/logstash -e 'input { stdin{} } output { stdout{ codec => rubydebug } elasticsearch { hosts => ["192.168.56.12:9200"] index => "logstash-%{+YYYY.MM.dd}" } }'
通过配置文件来收集日志
默认配置文件夹为/etc/logstash/conf.d/进入该文件夹编写配置文件demo.conf
input{ stdin{} } filter{ } output{ elasticsearch{ hosts => ["192.168.56.12:9200"] index => "logstach-%{+YYYY.MM.dd}" } stdout{ codec => rubydebug } }
PS:配置文件必须包含input和output filter是可选的,每个里面放置各自的插件,每个插件也有大括号包含。
通过加载配置文件启动
/usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/demo.conf
写一个收集文件日志的文件file.conf
input{ file{ path => ["/var/log/message","/var/log/secure"] type => "system-log" start_position => "beginning" } } filter{ } output{ elasticsearch{ hosts => ["192.168.56.12:9200"] index => "system-log-%{+YYYY.MM}" } }
收集path指定的两个文件日志并且输出至es
在head查看
6,kibana使用
修改配置文件/etc/kibana/kibana.yml
server.port: 5601 server.host: "0.0.0.0" elasticsearch.url: "http://192.168.56.12:9200" kibana.index: ".kibana"
启动
systemctl start kibana
web页面访问http://192.168.56.12:5601
通过索引导入日志
排错
elasticsearch启动报错
解决办法
修改配置文件/etc/elasticsearch/elasticsearch.yml
bootstrap.memory_lock: false