日志搜集系统搭建
基于7.17.16版本
ps: 项目是toB的,日志量不大
7.17.16版本。8.x版本需要JDK11
elastic.co/downloads/past-releases
java8
elastic 软件不能以root用户启动,需要创建用户
sudo useradd elastic
#给此用户设置密码
sudo passwd elastic
#授权
chown -R elastic /usr/local/kw-microservices/elastic/elasticsearch
chown -R elastic /usr/local/kw-microservices/elastic/kibana
略
修改config/elasticsearch.yml中参数
#默认只能被本机访问
#修改config/elasticsearch.yml中参数
network.host: 0.0.0.0
#开启远程连接之后,就默认以生产模式启动,是集群的,需要修改
#修改为
cluster.initial_master_nodes: ["node-1"]
#修改为
discovery.seed_hosts: ["127.0.0.1:9300"]
#切换回root
vim /etc/sysctl.conf
#修改为
vm.max_map_count=262144
#执行
sysctl -p
sysctl -a|grep vm.max_map_count
vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65537
# 不配置 启动报错 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
#需要重新登陆一下,查看是否生效
ulimit -H -n
#说明: soft nofile表示软限制,hard nofile表示硬限制。两行语句表示,es用户的软限制为65535,硬限制为65537,即表示es用户能打开的最大文件数量为65537,不管它开启多少个shell
jvm.options
默认4G,也可以不改,看硬件配置。
-Xms1g
-Xmx1g
修改kibana.yml
#允许远程访问
server.host: "0.0.0.0"
#es地址
elasticsearch.hosts: ["http://localhost:9200"]
#指定语言 en、zh-CN,推荐使用英文
i18n.locale: "zh-CN"
# ============================== Filebeat inputs ===============================
filebeat.inputs:
- type: log
paths:
- /Users/kw/Downloads/all.log
fields:
app: admin-service
env: dev
# ============================== Filebeat modules ==============================
filebeat.config.modules:
# Glob pattern for configuration loading
path: ${path.config}/modules.d/*.yml
# Set to true to enable config reloading
reload.enabled: false
# Period on which files under path should be checked for changes
#reload.period: 10s
# ================================== Outputs ===================================
output.redis:
hosts: ["localhost"]
password: "123456"
key: "filebeat"
db: 0
timeout: 5
# ================================= Processors =================================
processors:
- drop_fields:
fields: ["log","host","input","agent","ecs"]
ignore_missing: false
# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.
input {
redis {
id => "kw_localhost"
#消息被消费完,key会丢失,有消息进来会重新创建key
key => "filebeat"
host => "localhost"
password => "123456"
port => 6379
db => "0"
data_type => "list"
}
}
filter {
grok {
#匹配日志中的时间,并存储到一个字段中log_timestamp
#TIMESTAMP_ISO8601 为grok中的一种时间匹配模式,具体要看自己的时间格式
match => { "message" => "%{TIMESTAMP_ISO8601:log_timestamp}" }
}
date {
match => ["log_timestamp", "yyyy-MM-dd HH:mm:ss.SSS"] #匹配timestamp字段
target => "@timestamp" #将匹配到的数据写到@timestamp字段中
}
#需要删除字段
mutate {
remove_field => ["log_timestamp"]
}
}
output {
#stdout {}
elasticsearch {
hosts => ["localhost:9200"]
index => "backend-%{[fields][app]}-%{+YYYY.MM.dd}"
}
}
./filebeat -e -c 指定配置文件
./filebeat test config -e -c filebeat.yml
#test config: 这是filebeat的一个子命令,用于测试配置文件是否正确。
#-e: 这个参数表示如果遇到任何错误,立即退出。
#-c 这个参数指定了要测试的配置文件的路径。在这个例子中,配置文件是filebeat.yml,并且它应该在当前目录下
#后台启动
nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 &
#查看
jobs
#查看进程
ps -ef|grep filebeat|grep -v grep
#调为前台进程 ctrl c关闭进程 或者 直接kill -9 pid
fg %1
#解压即可
tar -zxvf
#启动
./bin/logstash -f 指定配置文件
#检测配置是否正确
./bin/logstash -t -f 指定配置文件
#后台启动,使用nohup
#bin目录 启动
./elasticsearch
#后台启动nohup
#bin目录 启动
./kibana
#后台启动nohup
有错误信息,但不影响使用。
报如下错误,下载插件失败,需要科学上网,重启即可
Error: Failed to download https://storage.googleapis.com/headless_shell/chromium-38c7255-locales-linux_x64.zip: Error: Unable to download https://storage.googleapis.com/headless_shell/chromium-38c7255-locales-linux_x64.zip: Error: read ECONNRESET
linux报这个错
org.elasticsearch.ElasticsearchException: not all primary shards of [.geoip_databases] index are active
不解决得话,head插件,head这里点不了
#能启动,但报错如下:(百度说,这是个bug)
[node-1] error updating geoip database [GeoLite2-Country.mmdb]
java.net.SocketException: Connection reset
#解决 elasticsearch.yml增加配置
#关闭geoip数据库的更新
ingest.geoip.downloader.enabled: false
启动报错
ElasticsearchException[Failure running machine learning native code. This could be due to running on an unsupported OS or distribution, missing OS libraries, or a problem with the temp directory. To bypass this problem by running Elasticsearch without machine learning functionality set [xpack.ml.enabled: false].]
#解决 elasticsearch.yml增加配置
xpack.ml.enabled: false