TextField
创建索引 可是能够不存储TermQuery
不会将查询分词了,把查询条件当成固定的词条BooleanClause
+ 表明 must - 表明 mustnot 表明 should html
开始看filebeat,被官网带到了Getting started with the Elastic Stack.
node
这个小教程是用metricbeat来采集服务器指标数据,而后用kibana作展现。linux
port:9200
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.1-linux-x86_64.tar.gz
tar -xzvf elasticsearch-7.0.1-linux-x86_64.tar.gz
cd elasticsearch-7.0.1
./bin/elasticsearch
curl http://127.0.0.1:9200
复制代码
port:5601
kibana是专门用于ES的,对数据进行搜索以及可视化。小教程里建议kibana和ES装同一台机器上。git
配置文件里须要配置ES集群的地址 web
curl -L -O https://artifacts.elastic.co/downloads/kibana/kibana-7.0.1-linux-x86_64.tar.gz
tar xzvf kibana-7.0.1-linux-x86_64.tar.gz
cd kibana-7.0.1-linux-x86_64/
./bin/kibana
复制代码
beat是作采集用的,装在服务器上的agent。通常输出到ES
和logstash
,本身自己不能作解析redis
curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.0.1-linux-x86_64.tar.gz
tar xzvf metricbeat-7.0.1-linux-x86_64.tar.gz
复制代码
./metricbeat modules enable system
#============================== Dashboards =====================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here or by using the `setup` command.
#setup.dashboards.enabled: false
# The URL from where to download the dashboards archive. By default this URL
# has a value which is computed based on the Beat name and version. For released
# versions, this URL points to the dashboard archive on the artifacts.elastic.co
# website.
#setup.dashboards.url:
复制代码
./metricbeat setup -e
,-e
是将输出打到stderr
不是syslog
,就是把日志打到控制台能看得见。./metricbeat -e
若是beat采的数须要额外处理那么须要进logstash(其实就是解析) json
curl -L -O https://artifacts.elastic.co/downloads/logstash/logstash-7.0.1.tar.gz
tar -xzvf logstash-7.0.1.tar.gz
复制代码
demo-metrics-pipeline.conf
,监听5044端口input {
beats {
port => 5044
}
}
# The filter part of this file is commented out to indicate that it
# is optional.
# filter {
#
# }
output {
elasticsearch {
hosts => "localhost:9200"
manage_template => false
index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
}
}
复制代码
./bin/logstash -f demo-metrics-pipeline.conf
还得配置beat 让其吐出到logstash 安全
metricbeat采集了cmdline
完整参数 太长了,解析一下它。用grok
ruby
filter {
if [system][process] {
if [system][process][cmdline] {
grok {
match => {
"[system][process][cmdline]" => "^%{PATH:[system][process][cmdline_path]}"
}
remove_field => "[system][process][cmdline]"
}
}
}
}
复制代码
解析这块。grok后面会再写。 bash
/var/log/*.log
filebeat.reference.yml
参考全部配置项filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
复制代码
/var/log/*/*.log
从/var/log
子文件夹中获取全部.log,如今还不支持获取全部层中的全部文件output.elasticsearch:
hosts: ["myEShost:9200"]
复制代码
setup.kibana:
host: "mykibanahost:5601"
复制代码
output.elasticsearch:
hosts: ["myEShost:9200"]
username: "filebeat_internal"
password: "YOUR_PASSWORD"
setup.kibana:
host: "mykibanahost:5601"
username: "my_kibana_user"
password: "YOUR_PASSWORD"
复制代码
./filebeat modules list
File is inactive: /var/log/boot.log. Closing because close_inactive of 5m0s reached. 说明文件没有新东西
data/registry/filebeat/data.json
#这是filebeat.yml 输出到5044端口 默认logstash监听的端口
#----------------------------- Logstash output --------------------------------
output.logstash:
hosts: ["127.0.0.1:5044"]
复制代码
#==================== Elasticsearch template setting ==========================
#默认一个分片 这就是Filebeat在ES中索引只有一个分片缘由
setup.template.settings:
index.number_of_shards: 1
#index.codec: best_compression
#_source.enabled: false
复制代码
用rpm和tar安装目录以及日志的位置不同具体查官方文档。
beat采集日志有的须要用root采
理解这些概念会在配置的时候作出明智的选择
inputs
harvesters
输入和收割机close_inactive
因为有人帮咱们采集好了日志,在kafka中,因此先用logstash对接
# 可以从标准输入中拿数怼到标准输出 -e 是能够直接跟配置 快速测试
cd logstash-7.0.1
bin/logstash -e 'input { stdin { } } output { stdout {} }'
# 结果以下
什么鬼
{
"message" => "什么鬼",
"@version" => "1",
"@timestamp" => 2019-05-07T02:00:39.581Z,
"host" => "node1"
}
复制代码
# logstash管道配置以下 先打印到标准输出上查看
input {
beats {
port => 5044
}
}
# rubydebug 这是用ruby的一个打印库 让输出更好看
output {
stdout { codec => rubydebug }
}
复制代码
bin/logstash -f first-pipeline.conf --config.test_and_exit
这个命令能够看配置文件是否是好使bin/logstash -f first-pipeline.conf --config.reload.automatic
config.reload.automatic
这个选项能自动加载新的配置文件,不用重启logstashgeoip插件
* logstash支持多输入多输出,能够直接对接twitter 就无法实验了。能够直接输出到文件。
geoip {
source => "clientip"
}
{
"ecs" => {
"version" => "1.0.0"
},
"input" => {
"type" => "log"
},
"agent" => {
"ephemeral_id" => "860d92a1-9fdb-4b41-8898-75021e3edaaf",
"version" => "7.0.0",
"hostname" => "node1",
"id" => "c389aa98-534d-4f37-ba62-189148baa6a3",
"type" => "filebeat"
},
"request" => "/robots.txt",
"verb" => "GET",
"host" => {
"hostname" => "node1",
"containerized" => true,
"architecture" => "x86_64",
"os" => {
"kernel" => "3.10.0-693.el7.x86_64",
"codename" => "Maipo",
"family" => "redhat",
"platform" => "rhel",
"version" => "7.4 (Maipo)",
"name" => "Red Hat Enterprise Linux Server"
},
"id" => "b441ff6952f647e7a366c69db8ea6664",
"name" => "node1"
},
"ident" => "-",
"timestamp" => "04/Jan/2015:05:27:05 +0000",
"auth" => "-",
"tags" => [
[0] "beats_input_codec_plain_applied"
],
"referrer" => "\"-\"",
"@version" => "1",
"response" => "200",
"httpversion" => "1.1",
"message" => "218.30.103.62 - - [04/Jan/2015:05:27:05 +0000] \"GET /robots.txt HTTP/1.1\" 200 - \"-\" \"Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)\"",
"clientip" => "218.30.103.62",
"geoip" => {
"region_code" => "BJ",
"latitude" => 39.9288,
"ip" => "218.30.103.62",
"location" => {
"lat" => 39.9288,
"lon" => 116.3889
},
"region_name" => "Beijing",
"longitude" => 116.3889,
"city_name" => "Beijing",
"timezone" => "Asia/Shanghai",
"country_code3" => "CN",
"country_code2" => "CN",
"country_name" => "China",
"continent_code" => "AS"
},
"@timestamp" => 2019-05-07T03:43:18.368Z,
"log" => {
"file" => {
"path" => "/itoa/elastic-stack/test-cas/logstash-demo/logstash-tutorial.log"
},
"offset" => 19301
}
}
复制代码
consumers_thread
配置文件默认没有开启转义,因此`\t`解析不了,须要去配置文件中修改这个配置。
它在关闭前会执行一些操做
不安全的关闭会丢数