https://hub.docker.com/_/elasticsearch/
https://hub.docker.com/_/kibana/
https://www.docker.elastic.co/r/elasticsearch
https://hub.docker.com/r/sebp/elk/
-7.17.10
docker run -d -p 5601:5601 -p 9200:9200 --name es --restart always --network mgr --ip 172.18.0.92 -e TZ='Asia/Shanghai' --ulimit nofile=262144:262144 -v /etc/localtime:/etc/localtime:ro -e "I18N_LOCALE=zh-CN" minimum2scp/es-kibana
docker exec -it es /bin/bash
# docker run elasticsearch
docker run -d --net=host --name elasticsearch --restart=always -v /etc/localtime:/etc/localtime:ro -v /data/site/docker/env/monitor/elasticsearch/elasticsearch-7.ini:/usr/share/elasticsearch/config/elasticsearch.yml:ro -v /data/db/elasticsearch:/usr/share/elasticsearch/data elasticsearch:7.17.13
# 多节点集群
-es01
docker run -d -p 9200:9200 --name es01 --restart=always --network=es -v /etc/localtime:/etc/localtime:ro -v /data/docker/monitor/elasticsearch/elasticsearch-7-1.ini:/usr/share/elasticsearch/config/elasticsearch.yml:ro -v /data/db/elasticsearch-7-1:/usr/share/elasticsearch/data -v /data/file/logs/elasticsearch-7-1:/usr/share/elasticsearch/logs elasticsearch:7.14.4
-es02
docker run -d --name es02 --restart=always --network=es -v /etc/localtime:/etc/localtime:ro -v /data/docker/env/monitor/elasticsearch/elasticsearch-7-2.ini:/usr/share/elasticsearch/config/elasticsearch.yml:ro -v /data/db/elasticsearch-7-2:/usr/share/elasticsearch/data -v /data/file/logs/elasticsearch-7-2:/usr/share/elasticsearch/logs elasticsearch:7.14.1
docker stop es01 es02
chmod -R 777 /data/file/logs/ /data/db/
rm -rf /data/db/elasticsearch-7-1/* /data/db/elasticsearch-7-2/*
rm -rf /data/file/logs/elasticsearch-7-1/* /data/file/logs/elasticsearch-7-2/*
docker rm es01 es02
docker restart es01 es02
# docker run kibana
docker run -d --net=host --name kibana --restart=always -v /etc/localtime:/etc/localtime:ro -v /data/site/docker/env/monitor/kibana/kibana-7.ini:/usr/share/kibana/config/kibana.yml:ro kibana:7.17.13
# elasticsearch-head
https://abc.htmltoo.com/thread-46069.htm
mkdir -p /data/file/logs/elasticsearch && chmod -R 777 /data/file/logs/ /data/db/
rm -rf /data/db/elasticsearch/* /data/file/logs/elasticsearch/*
http://ip:9500
# filebeat: https://www.elastic.co/cn/downloads/beats/filebeat
cd /opt
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.17.10-x86_64.rpm
rpm -vi filebeat-7.17.10-x86_64.rpm
docker exec -it elasticsearch /bin/bash
---Install Elasticsearch GeoIP and user agent plugins
bin/elasticsearch-plugin install ingest-geoip
bin/elasticsearch-plugin install ingest-user-agent
---修改
chmod -R 777 /etc/filebeat/
---配置.其他人不能写
chmod -R 755 /etc/filebeat/
#Kibana server is not ready yet
-elasticsearch.url改为正确的链接, 改成了docker内部的IP, ip address , docker0
172.17.0.1
---调试模式下采用:终端启动(退出终端或ctrl+c会退出运行)
./filebeat -e -c filebeat.yml
---线上环境配合error级别使用:以后台守护进程启动启动filebeats
nohup /usr/share/filebeat/bin/filebeat -e -c /etc/filebeat/filebeat.yml &
---停止运行FileBeat进程
ps -ef | grep filebeat
Kill -9 线程号
---卸载filebeat
yum -y remove filebeat
---Start Filebeat
service filebeat start
service filebeat stop
service filebeat restart
service filebeat status
==========时间===========
1.高级设置
- > Date format -> YYYY-MM-DD HH:mm:ss
-> dateFormat:tz -> Asia/Shanghai
-> dateFormat:dow -> Monday
# elasticsearch:7.14.1
----安装中文分词插件: https://github.com/medcl/elasticsearch-analysis-ik/releases
bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.14.1/elasticsearch-analysis-ik-7.14.1.zip
----测试ik分词器:
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_analyze?pretty' -d '{
"analyzer" : "ik_max_word",
"text": "中华人民共和国国歌"
}'
curl localhost:9200 # 测试
---elasticsearch查看所有index:
curl 'localhost:9200/_cat/indices?v'
vim /data/docker/monitor/elasticsearch/elasticsearch-7.ini
cluster.name: "cluster" node.name: "node-1" network.host: "0.0.0.0" cluster.initial_master_nodes: - node-1 discovery.seed_hosts: - 39.101.166.123 http.cors.enabled: "true" http.cors.allow-origin: “*” #账号授权 http.cors.allow-headers: "Authorization" xpack.security.enabled: "true" xpack.security.transport.ssl.enabled: "true"
docker restart elasticsearch
docker exec -it elasticsearch /bin/bash
---执行设置用户名和密码的命令,这里需要为4个用户分别设置密码,elastic, kibana, logstash_system,beats_system
bin/elasticsearch-setup-passwords interactive
-:y
-:elastic:elastic, kibana:kibana, logstash_system:logstash_system,beats_system : beats_system
---修改密码命令如下
curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'
vim /data/docker/monitor/kibana/kibana-7.ini
server.name: kibana server.host: "0.0.0.0" elasticsearch.hosts: "http://39.101.166.123:9200" monitoring.ui.container.elasticsearch.enabled: true i18n.locale: "zh-CN" kibana.index: ".kibana" monitoring.cluster_alerts.email_notifications.email_address: "522588122@qq.com" xpack.security.encryptionKey: "98XVHeRM9KqGpghV2YXHiS4K1b4ZdULn" xpack.reporting.encryptionKey: "RrqAFUSwBztgdzsKgHnFyREv04mUyWOF" xpack.encryptedSavedObjects.encryptionKey: "YKFEDUnqfXx5Iea4X5PeIZyz60z1tAGs" xpack.reporting.capture.browser.chromium.disableSandbox: "true" xpack.security.enabled: "true" monitoring.enabled: "false" xpack.graph.enabled: "false" xpack.watcher.enabled: "false" xpack.reporting.enabled: "false" #账号授权 elasticsearch.username: "elastic" elasticsearch.password: "elastic"
---在程序中可以使用如下格式指定用户名密码
http://username:password@localhost:9200
vim /etc/filebeat/filebeat.yml
#=========================== Filebeat inputs ============================= filebeat.inputs: - type: log enabled: true paths: - /www/wwwlogs/*.log #keys_under_root可以让字段位于根节点,默认为false json.key_under_root: true #对于同名的key,覆盖原有key值 json.overwrite_keys: true #选择额外的字段进行输出 fields: ip: b.htmltoo.com #如果值为ture,那么fields存储在输出文档的顶级位置 fields_under_root: true #添加标签,用过过滤 #tags: ["nginx"] #指定Filebeat忽略指定时间段以外修改的日志内容,比如2h(两个小时)或者5m(5分钟) ignore_older: 96h #如果在制定时间没有被读取,将关闭文件句柄 close_inactive: 48h #支持正则 include_lines执行完毕之后会执行exclude_lines。 #导出那些所有包含ERR,WARN,err,warn,failed的行: #include_lines: ['^ERR', '^WARN'] #include_lines: [".*ERR.*",".*WARN.*",".*err.*",".*warn.*",".*failed.*"] #支持正则 排除匹配的行,如果有多行,合并成一个单一行来进行过滤, #删除INFO开头,带有INFO的行 #exclude_lines: ['^INFO'] #exclude_lines: ["^INFO", ".*INFO.*","^DEBUG", ".*DEBUG.*"] #设置删除不必要的字段 processors: - drop_fields: fields: ["@timestamp", "prospector.type", "input.type", "beat.hostname", "beat.version", "beat.name", "host.name", "offset", "agent.ephemeral_id", "agent.id", "agent.name", "ecs.version", "log.offset", "agent.type", "agent.version"] #提取多行日志 multiline.pattern: ^\[ multiline.negate: true multiline.match: after #==================== output.elasticsearch: hosts: ["b.htmltoo.com:9200"] setup.kibana: host: "b.htmltoo.com:5601"
cat filebeat-0.yml
###################### Filebeat Configuration Example #########################
# This file is an example configuration file highlighting only the most common
# options. The filebeat.reference.yml file from the same directory contains all the
# supported options with more comments. You can use it as a reference.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/filebeat/index.html
# For more available modules and options, please see the filebeat.reference.yml sample
# configuration file.
# ============================== Filebeat inputs ===============================
filebeat.inputs:
# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.
- type: log
# Change to true to enable this input configuration.
enabled: false
# Paths that should be crawled and fetched. Glob based paths.
paths:
- /var/log/*.log
#- c:\programdata\elasticsearch\logs\*
# Exclude lines. A list of regular expressions to match. It drops the lines that are
# matching any regular expression from the list.
#exclude_lines: ['^DBG']
# Include lines. A list of regular expressions to match. It exports the lines that are
# matching any regular expression from the list.
#include_lines: ['^ERR', '^WARN']
# Exclude files. A list of regular expressions to match. Filebeat drops the files that
# are matching any regular expression from the list. By default, no files are dropped.
#exclude_files: ['.gz$']
# Optional additional fields. These fields can be freely picked
# to add additional information to the crawled log files for filtering
#fields:
# level: debug
# review: 1
### Multiline options
# Multiline can be used for log messages spanning multiple lines. This is common
# for Java Stack Traces or C-Line Continuation
# The regexp Pattern that has to be matched. The example pattern matches all lines starting with [
#multiline.pattern: ^\[
# Defines if the pattern set under pattern should be negated or not. Default is false.
#multiline.negate: false
# Match can be set to "after" or "before". It is used to define if lines should be append to a pattern
# that was (not) matched before or after or as long as a pattern is not matched based on negate.
# Note: After is the equivalent to previous and before is the equivalent to to next in Logstash
#multiline.match: after
# ============================== 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
# ======================= Elasticsearch template setting =======================
setup.template.settings:
index.number_of_shards: 1
#index.codec: best_compression
#_source.enabled: false
# ================================== General ===================================
# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
#name:
# The tags of the shipper are included in their own field with each
# transaction published.
#tags: ["service-X", "web-tier"]
# Optional fields that you can specify to add additional information to the
# output.
#fields:
# env: staging
# ================================= 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:
# =================================== Kibana ===================================
# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:
# Kibana Host
# Scheme and port can be left out and will be set to the default (http and 5601)
# In case you specify and additional path, the scheme is required: http://localhost:5601/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
#host: "localhost:5601"
# Kibana Space ID
# ID of the Kibana Space into which the dashboards should be loaded. By default,
# the Default Space will be used.
#space.id:
# =============================== Elastic Cloud ================================
# These settings simplify using Filebeat with the Elastic Cloud (https://cloud.elastic.co/).
# The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options.
# You can find the `cloud.id` in the Elastic Cloud web UI.
#cloud.id:
# The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
#cloud.auth:
# ================================== Outputs ===================================
# Configure what output to use when sending the data collected by the beat.
# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["localhost:9200"]
# Protocol - either `http` (default) or `https`.
#protocol: "https"
# Authentication credentials - either API key or username/password.
#api_key: "id:api_key"
#username: "elastic"
#password: "changeme"
# ------------------------------ Logstash Output -------------------------------
#output.logstash:
# The Logstash hosts
#hosts: ["localhost:5044"]
# Optional SSL. By default is off.
# List of root certificates for HTTPS server verifications
#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
# Certificate for SSL client authentication
#ssl.certificate: "/etc/pki/client/cert.pem"
# Client Certificate Key
#ssl.key: "/etc/pki/client/cert.key"
# ================================= Processors =================================
processors:
- add_host_metadata:
when.not.contains.tags: forwarded
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
# ================================== Logging ===================================
# Sets log level. The default log level is info.
# Available log levels are: error, warning, info, debug
#logging.level: debug
# At debug level, you can selectively enable logging only for some components.
# To enable all selectors use ["*"]. Examples of other selectors are "beat",
# "publish", "service".
#logging.selectors: ["*"]
# ============================= X-Pack Monitoring ==============================
# Filebeat can export internal metrics to a central Elasticsearch monitoring
# cluster. This requires xpack monitoring to be enabled in Elasticsearch. The
# reporting is disabled by default.
# Set to true to enable the monitoring reporter.
#monitoring.enabled: false
# Sets the UUID of the Elasticsearch cluster under which monitoring data for this
# Filebeat instance will appear in the Stack Monitoring UI. If output.elasticsearch
# is enabled, the UUID is derived from the Elasticsearch cluster referenced by output.elasticsearch.
#monitoring.cluster_uuid:
# Uncomment to send the metrics to Elasticsearch. Most settings from the
# Elasticsearch output are accepted here as well.
# Note that the settings should point to your Elasticsearch *monitoring* cluster.
# Any setting that is not set is automatically inherited from the Elasticsearch
# output configuration, so if you have the Elasticsearch output configured such
# that it is pointing to your Elasticsearch monitoring cluster, you can simply
# uncomment the following line.
#monitoring.elasticsearch:
# ============================== Instrumentation ===============================
# Instrumentation support for the filebeat.
#instrumentation:
# Set to true to enable instrumentation of filebeat.
#enabled: false
# Environment in which filebeat is running on (eg: staging, production, etc.)
#environment: ""
# APM Server hosts to report instrumentation results to.
#hosts:
# - http://localhost:8200
# API Key for the APM Server(s).
# If api_key is set then secret_token will be ignored.
#api_key:
# Secret token for the APM Server(s).
#secret_token:
# ================================= Migration ==================================
# This allows to enable 6.7 migration aliases
#migration.6_to_7.enabled: truecat /etc/filebeat/filebeat.yml
# ref: https://my.oschina.net/openplus/blog/1589846
filebeat.prospectors:
- type: log
enabled: true
paths:
- /data/web/qianbitou.cn/gaea-beta/frontend/runtime/logs/app.log
- /data/web/qianbitou.cn/gaea-beta/backend/runtime/logs/app.log
- /tmp/test/test.log
tail_files: true
document_type: beta_runtime_log
exclude_lines: ['\$_COOKIE', '\$_SESSION', '\$_SERVER', '\$_FILES']
multiline:
charset: "utf8"
pattern: \[error\]
negate: true
match: after
# flush_pattern: \{main\}
flush_pattern: ^\]
# flush_pattern: ^\$_COOKIE
# what: "previous"
# max_lines: 50
output.elasticsearch:
hosts: ["127.0.0.1:9200"]
username: "elastic"
password: "qianbitou2018"
index: "beta-log-%{+YYYY.MM.dd}"
setup.template.enabled: true
setup.template.name: "beta-log-%{+yyyy.MM.dd}"
setup.template.pattern: "beta-log-*"
setup.template.path: "${path.config}/filebeat.template.json"
setup.template.overwrite: false
setup.template.settings:
index.number_of_shards: 1
index.number_of_replicas: 0
# index.ttl.interval: 3d
setup.kibana:
host: "127.0.0.1:5601"
username: "kibana"
assword: "qianbitou2018"#Elasticsearch-6: https://abc.htmltoo.com/thread-46050.htm