分类目录

链接

2023 年 2 月
 12345
6789101112
13141516171819
20212223242526
2728  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > DevOps, Docker, JAVA, 云计算, 分布式, 大数据, 微服务, 系统架构 > 正文
linux快速搭建轻量级efk日志系统

一、前言

为什么要用EFK(or ELK):

 

EFK 中的F是 filebeat还是fluentd?

单机推荐用filebeat,非常轻量级,占用内存为10M

 

二、安装过程

首先,通过docker-compose安装最方便,这里是yml文件:

注意1:es, kibana, filebeat版本最好一致

注意2:物理机最低内存2G才能安装(es大概800M,kibana 200M, filebeat 100M), 实在不行加swap!

 

  1. version : '3'
  2. services:
  3.  
  4.   es:
  5.     container_name: es
  6.     image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
  7.     ports:
  8.       - "9200:9200"
  9.     environment:
  10.       - node.name=es
  11.       - http.host=0.0.0.0
  12.       - transport.host=127.0.0.1
  13.       - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  14.       - bootstrap.memory_lock=true
  15.       - discovery.type=single-node  
  16.       - xpack.security.enabled=false
  17.       - xpack.security.http.ssl.enabled=false
  18.       - xpack.security.transport.ssl.enabled=false
  19.       - ELASTIC_PASSWORD="123456"
  20.     deploy:
  21.       resources:
  22.         limits:
  23.           memory: 1000m
  24.     volumes:
  25.       - ./efk/es:/home
  26.     restart: always
  27.   kibana:
  28.     image: docker.elastic.co/kibana/kibana:7.2.0
  29.     container_name: kibana
  30.     depends_on: 
  31.       - es
  32.     volumes:
  33.       - ./efk/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml
  34.     environment:
  35.       SERVER_NAME: kibana
  36.       SERVER_HOST: '0.0.0.0'
  37.       ELASTICSEARCH_URL: "http://es:9200"
  38.       ELASTICSEARCH_USERNAME: 'elastic'
  39.       ELASTICSEARCH_PASSWORD: '"123456"'
  40.     ports:
  41.       - 5601:5601
  42.     links: ['es']
  43.     depends_on: ['es']
  44.   filebeat:
  45.     image: docker.elastic.co/beats/filebeat:7.2.0
  46.     container_name: filebeat
  47.     restart: always
  48.     privileged: true
  49.     user: root
  50.     environment:
  51.       - setup.kibana.host=kibana:5601
  52.       - output.elasticsearch.hosts=["es:9200"]
  53.     volumes:
  54.       - /var/lib/docker/containers:/var/lib/docker/containers:ro
  55.       - ./efk/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml
  56.       - /var/run/docker.sock:/var/run/docker.sock:ro
  57.     links: ['es']
  58.     depends_on: ['es']
  59.  
  60.  
  61.  
  62.  

 

下面是用到的:kibana.yml

  1. server.port: 5601
  2. server.host: "0.0.0.0"
  3. server.name: "kibana"
  4. elasticsearch.hosts: ["http://es:9200"]
  5. elasticsearch.ssl.verificationMode: none
  6. #elasticsearch.ssl.certificateAuthorities: ["/data/kibana/config/newfile.crt.pem"]
  7. elasticsearch.preserveHost: true
  8. kibana.index: ".kibana"
  9. i18n.locale: "en"
  10. elasticsearch.username: "elastic"
  11. elasticsearch.password: "123456"

filebeat.yml

  1. processors:
  2.   - add_cloud_metadata: ~
  3.   - add_docker_metadata: ~
  4.   - drop_event:
  5.       when.or:
  6.         - contains:
  7.             container.name: "filebeat"
  8.         - contains:
  9.             container.name: "kibana"
  10.         - contains:
  11.             container.name: "es"
  12. filebeat.inputs:
  13.   - type: docker
  14.     combine_partial: true
  15.     containers:
  16.       path: "/var/lib/docker/containers"
  17.       ids: "*"
  18. filebeat.config:
  19.   modules:
  20.     path: ${path.config}/modules.d/*.yml
  21.     reload.enabled: false
  22. output.elasticsearch:
  23.   hosts: 'es:9200'
  24.   username: "elastic"
  25.   password: "123456"
  26. setup.kibana:
  27.   host: "kibana:5601"

注:docker默认使用j做为日志驱动,记得修改log-driver为Json-fle

修改默认驱动,vi /etc/sysconfig/docker 将journald修改为json-file OPTIONS='--selinux-enabled=false --log-driver=json-file --signature-verification=fal..

重启docker, systemctl restart docker

 

安装好后,登陆kibana,   http://ip:5601

 

 

三、设置es,kibana密码

docke登陆es:

docker exec -it es bash

进入bin,  执行 :

./elasticsearch-setup-passwords interactive

这里会设置六个账号的密码:elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.

es修改密码在安装es的机器上,执行命令如下:(将密码设置为:12456)

curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'

校验设置的新密码是否有问题:(输入你的新密码)

curl <span class="token operator">-</span>u elastic <span class="token lifetime-annotation symbol">'http://ip:9200/_xpack/security/_authenticate?pretty</span>'

访问 http://ip:9200,需要输入账号密码才可以访问

四 、常见错误

 

错误一:Kibana did not load properly. Check the server output for more information.

错误二:

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval'

 

 

 

 

附:

filebeat官方文档:https://www.elastic.co/guide/en/beats/filebeat/7.2/filebeat-input-docker.html

 

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:linux快速搭建轻量级efk日志系统 | Bruce's Blog

发表评论

留言无头像?