发布于: 2022-05-28 13:59:59

ELK

ElasticSearch

# 下载4个包
# https://mirrors.huaweicloud.com/elasticsearch/6.8.1/?C=N&O=D
# https://mirrors.huaweicloud.com/filebeat/6.8.1/?C=N&O=D
# https://mirrors.huaweicloud.com/logstash/6.8.1/?C=N&O=D
# https://mirrors.huaweicloud.com/kibana/6.8.1/?C=N&O=D

# 解压缩4个包

# 安装ik中文分词插件
$ bin/elasticsearch-plug*** install ik安装包地址

# 启动es
$ bin/elasticsearch

# 测试一下logstash能用不,允许Logstash最基本的管道:
#(tips:选项 -e 的意思是允许从命令行指定配置)
$ bin/logstash -e 'input { stdin {} } output { stdout {} }'

# 启动以后,下面我们在命令行下输入"hello world" 会返回输入的信息到控制台

# 在filebeat目录下配置filebeat.yml
# 进入filebeat目录
$ cd ./filebeat-x.x.x

# 备份filebeat.yml文件
$ cp filebeat.yml filebeat.default.yml

# 编辑filebeat.yml文件
$ vim filebeat.yml
filebeat.inputs:
- type: log
 paths:
   - /www/wwwlogs/*.log #需要配置的日志路径

output.logstash:
 hosts: ["localhost:5044"]#如果是logstash与filebeat不在同一主机需要设置ip
 
# 配置logstash文件 pipeline.conf ,通常Logstash管理有三部分(输入、过滤器、输出)
$ vim first-pipeline.conf
#输入
input {
beats { #意思是用Beats输入插件
 port => "5044" #监听5044端口有没有信息推送过来,有的话就output到配置的程序里
}
}

#过滤
filter {#grok filter 过滤器插件解析日志
grok {
 match => { "message" => "%{COMBINEDAPACHELOG}" }
}
geoip {
 source => "clientip"
}
}

#输出
#output {
# stdout { codec => rubydebug } #输出到控制台
#}
output {
elasticsearch {
 hosts => [ "localhost:9200" ]
}
}
# 检查pipeline.conf文件是否编辑错误
#--config.test_and_exit选项的意思是解析配置文件并报告任何错误
$ bin/logstash -f first-pipeline.conf --config.test_and_exit
#--config.reload.automatic选项的意思是启用自动配置加载,以至于每次你修改完配置文件以后无需停止然后重启Logstash
$ bin/logstash -f first-pipeline.conf --config.reload.automatic

#启动filebeat
$ ./filebeat -e -c filebeat.yml -d "publish"

# 删除filebeat注册信息并重启
$ rm data/registr
$ ./filebeat -e -c filebeat.yml -d "publish"

# CURL
# 查看es所有索引
$ curl 'localhost:9200/_cat/indices?v'

$ curl -XPUT -u elastic:changeme 'http://localhost:9200/_xpack/security/user/elastic/_password'  -H 'content-Type:application/json' -d '{"password" : “chenyang” }'



延伸阅读
    发表评论