wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.0.rpm
wget https://artifacts.elastic.co/downloads/logstash/logstash-5.6.0.rpm
wget https://artifacts.elastic.co/downloads/kibana/kibana-5.6.0-x86_64.rpm
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.2-x86_64.rpm
rpm -ivh elasticsearch-5.6.0.rpm
rpm -ivh logstash-5.6.0.rpm
rpm -ivh kibana-5.6.0-x86_64.rpm
rpm -ivh filebeat-6.2.2-x86_64.rpm # filebeat 收集日志
/etc/elasticsearch/elasticsearch.yml
cluster.name: erp #指定个集群名字,等下会用到
node.name: node0 #节点名称也指定下
path.data: /opt/data #指定ela生成数据的存放路径(注意读写权限问题)
path.logs: /opt/data/logs #指定ela执行日志的存放路径,好排查问题
network.host: *.*.*.* #指定监听地址
http.port: 9200 #指定端口
# 设置集群节点发现与沟通
transport.host: "**.**.**.**"
discovery.zen.ping.unicast.hosts: ["**.**.**.**"]
discovery.zen.minimum_master_nodes: 2 #(N/2)+1
service elasticsearch start/stop/restart
/usr/share/logstash/bin/system-install /etc/logstash/startup.options sysv
service logstash start/stop/restart
/etc/logstash/conf.d/ 下添加单独业务日志配置,如 nginx-access.conf somebusserv.conf
# 基本格式 输入过滤输出
input {
}
filter {
}
output {
}
# 获取本机的文件 打到本机 es
input {
file {
path => "/www/busservlib/Log/**/*.log"
start_position => "beginning"
sincedb_path => "/www/busservlib/elk_progress"
type => "file"
# 多行合并
codec=> multiline {
pattern => "^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\|"
negate => true
what => "previous"
# 多行日志 可以避免不处理最后一条日志
auto_flush_interval => 1
}
}
}
filter {
if [type] == "file" {
grok {
match => {
"message" => "(?m)(?<log_time>[^\|]+)\|(?<function>[^\|]+)\|(?<log_level>[^\|]+)\|(?<title>[^\|]+)(\|(?<description>.+))?"
}
}
}
}
output {
if [type] == "file" {
elasticsearch {
action => "index"
hosts => "*.*.*.*:30005"
index => "busserv"
}
}
}
# 从 filebeat 获取 打到 本机 es
input {
beats {
port => 30006
type => "remote"
}
}
filter {
if [type] == "remote" {
grok {
match => {
"message" => "(?m)(?<log_time>[^\|]+)\|(?<function>[^\|]+)\|(?<log_level>[^\|]+)\|(?<title>[^\|]+)(\|(?<description>.+))?"
}
}
}
}
output {
if [type] == "remote" {
elasticsearch {
action => "index"
hosts => "*.*.*.*:30005"
index => "remote-busserv"
}
}
}
详细的配置另查阅
server.port: 5601
server.host: "*.*.*.*"
server.name: "*.*.*.*"
elasticsearch.url: "http://*.*.*.*:9200"
service kibana start/stop/restart
/usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
/usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
/etc/filebeat/filebeat.yml
filebeat.prospectors:
- type: log
enabled: true
paths:
- /www/busservlib/Log/**/*.log
exclude_files: ['^/www/busservlib/Log/Schema']
multiline.pattern: '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\|'
multiline.negate: true
multiline.match: after
multiline.timeout: 5s
# try to optimize
harvester_buffer_size: 409600
# 初始化不收集之前的日志
#tail_files: true
# 一天前的日志忽略之后从 registry_file 删除
close_inactive: 10m
clean_inactive: 26h
ignore_older: 25h
output:
logstash:
hosts: ["*.*.*.*:30006"]
work: 2
service filebeat start/stop/restart
ignore_older 会在首次启动时就生效,在要收集新的一个日志目录的时候比较有用,相当于指定多少日期前日志不收集(目录中的文件)
tail_files 启动之后 新文件出现只读取出现以后的内容,如果是新的日志目录,可以指定是否收集此文件之前的内容(文件中的内容)