elasticsearch , logstash , kibana
Author : Janloong Do_O
版本 : elk 5.6
elasticsearch 安装参考本博另一博文
bin/elasticsearch-plugin intall x-pack
获取用户地理位置和浏览器信息的插件
sudo bin/elasticsearch-plugin install ingest-geoip
sudo bin/elasticsearch-plugin install ingest-user-agent
配置文件修改
elasticsearch/config/jvm.options
-Xms 2g
-Xmx 2g
为logstash 安装 x-pack 时 需要开启自动创建所有功能否则会导致部分配置失效
按照官方的说法 如果不确定其余额外的配置如何配置时可以设置为
action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*,.*,*
安装
wget https://artifacts.elastic.co/downloads/logstash/logstash-5.6.3.tar.gz
启动
bin/logstsh -f sample.conf
插件
logstash-plugin install x-pack (不确定是否需要)
sample.conf
input {
stdin{
type => "syslog"
}
}
filter {
#定义数据的格式
grok {
match => { "message" => "%{DATA:timestamp}|%{IP:serverIp}|%{IP:clientIp}|%{DATA:logSource}|%{DATA:userId}|%{DATA:reqUrl}|%{DATA:reqUri}|%{DATA:refer}|%{DATA:device}|%{DATA:textDuring}|%{DATA:duringTime:int}||"}
}
#定义时间戳的格式
date {
match => [ "timestamp", "yyyy-MM-dd-HH:mm:ss" ]
locale => "cn"
}
#定义客户端的IP是哪个字段(上面定义的数据格式)
geoip {
source => "clientIp"
}
}
output {
elasticsearch {
hosts => "http://127.0.0.1:9200"
user => "loong"
password => "loong"
index => "logstash-nginx-access-%{+YYYY.MM.dd}"
}
stdout {
codec => rubydebug
}
}
安装
wget https://artifacts.elastic.co/downloads/kibana/kibana-5.6.3-linux-x86_64.tar.gz
bin/kibana-plugin install x-pack
配置
config/kibana.yml
server.host: "127.0.0.1"
elasticsearch.url: "http://127.0.0.1:9200"
##elasticsearch 的用户密码配置
elasticsearch.username: "elastic"
elasticsearch.password: "changeme"
启动
bin/kibana
Beats的组成
(1)Packetbeat 网络流量监控采集
(2)Topbeat 类似linux top的监控采集
(3)Filebeat 文件log的监控采集
(4)WinlogBeat windows系统的log监控采集
(5)自定义beat ,如果上面的指标不能满足需求,elasticsarch公司鼓励开发者
使用go语言,扩展实现自定义的beats指标,只需要按照模板,实现监控的输入,日志,输出等即可
filebeat
安装
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.6.3-amd64.deb
sudo dpkg -i filebeat-5.6.3-amd64.deb
配置
/etc/filebeat/filebeat.yml
template json 加载
output to elasticesearch
修改配置文件
output.elasticsearch:
hosts: ["localhost:9200"]
template.name: "filebeat"
template.path: "filebeat.template.json"
template.overwrite: false
output to logstash
if disable automatic template loading,need do this:
curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/_template/filebeat' -d@/etc/filebeat/filebeat.template.json
启动
sudo /etc/init.d/filebeat start
filebeat本身的日志可用如下的命令查询
tail -f /var/log/filebeat/filebeat
filebeat.sh -h 命令提示列表
指定配置文件
filebeat.sh -c [file]
设置elastic密码
curl -XPUT 'localhost:9200/_xpack/security/user/elastic/_password?pretty' -H 'Content-Type: application/json' -d'
{
"password": "elasticpassword"
}
'
同步更新kibana.yml
elasticsearch.password: kibanapassword
设置kibana密码
curl -XPUT 'localhost:9200/_xpack/security/user/kibana/_password?pretty' -H 'Content-Type: application/json' -d'
{
"password": "kibanapassword"
}
'
设置logstash_system 密码
curl -XPUT 'localhost:9200/_xpack/security/user/logstash_system/_password?pretty' -H 'Content-Type: application/json' -d'
{
"password": "logstashpassword"
}
'
当时用logstash_system 用户使用 monitor 时要设置elastic的密码
logstash.yml
xpack.monitoring.elasticsearch.password: logstashpassword
logstash_system 用户在旧版升级到新版时 出于安全 默认是关闭的 可以通过以下开启
curl -XPUT 'localhost:9200/_xpack/security/user/logstash_system/_enable?pretty'
当更改默认内置用户的密码时 需要更改默认设置 elasticsearch.yml
xpack.security.authc.accept_default_password false
elasticsearch
-> kibana
在kibana.yml文件中配置:
elasticsearch.username: “elastic”
elasticsearch.password: “changeme”
logstash
-> elasticsearch
自定义配置文件中 sample.conf
elasticsearch {
user =>""
password => ""
}
elasticsearch.yml 证书文件存放地址和密码,证书地址必须存放在es的config文件域下
xpack.ssl.key: /home/es/config/x-pack/node01.key
xpack.ssl.certificate: /home/es/config/x-pack/node01.crt
xpack.ssl.certificate_authorities: [ "/home/es/config/x-pack/ca.crt" ]
网络传输层开启ssl
xpack.security.transport.ssl.enabled: true
http层开启ssl
xpack.security.http.ssl.enabled: true
重启所有elastic 节点
可以开启事件追踪记录 es.yml,日志在es/logs/elasticsearch_access.log
xpack.security.audit.enabled: true
1、Filebeat(采集数据)+Elasticsearch(建立索引)+Kibana(展示)
2、Filebeat(采集数据)+Logstash(过滤)+Elasticsearch(建立索引)+Kibana(展示)
3、Filebeat(采集数据)+Kafka/Redis/File/Console(数据传输)+应用程序(处理,存储,展示)
4、Filebeat(采集数据)+Logstash(过滤)+Kafka/Redis/File/Console(数据传输)+应用程序(处理,存储,展示)
注:Redis/File/Console如何判断增量是一个问题
./elasticsearch &
./logshtash -f /confg
nohup ./kibana &
'http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}'
https://basemap.nationalmap.gov/arcgis/services/USGSTopo/MapServer/WMSServer
5.6升级6.1记录参考本博另一博文
elasticsearch
x-pack
logstash
input
logstash-input-beats
logstash-input-jdbc
fillter
logstash-filter-geoip
output
logstash-output-elasticsearch
logstash-output-stdout
kibana
x-pack
1. 问题
java.lang.IllegalArgumentException: unknown setting [xpack.security.user] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
添加xpack-transport 依赖
xpack 下使用Java transportclient 时 应使用
PreBuiltXPackTransportClient
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
而不是非xpack的类
参考资料
elastic官方参考文档
elk环境配置