Docker安装ELK

导读:本篇文章讲解 Docker安装ELK,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

写在最前

ELK = Elasticsearch、Logstash 和 Kibana。

安装环境

安装 ELK

准备工作

es 的数据挂载目录需要全权限

mkdir /opt/mingyue/elk/elasticsearch/data
chmod 777 /opt/mingyue/elk/elasticsearch/data

新建 logstash.conf

vim /opt/mingyue/elk/logstash/pipeline/logstash.conf

input {
  tcp {
    mode => "server"
    host => "0.0.0.0"
    port => 4560
    codec => json_lines
  }
}
output {
  elasticsearch {
    hosts => "es:9200"
    index => "mall-%{type}-%{+YYYY.MM.dd}"
  }
}

新建 docker-compose.yaml 文件

version: '3'
services:
  elasticsearch:
    image: elasticsearch:7.17.2
    container_name: elasticsearch-dev
    networks:
      - host
    environment:
      - "cluster.name=elasticsearch" #设置集群名称为elasticsearch
      - "discovery.type=single-node" #以单一节点模式启动
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m" #设置使用jvm内存大小
    volumes:
      - /opt/mingyue/elk/elasticsearch/plugins:/usr/share/elasticsearch/plugins #插件文件挂载
      - /opt/mingyue/elk/elasticsearch/data:/usr/share/elasticsearch/data #数据文件挂载
    ports:
      - 9200:9200
  kibana:
    image: kibana:7.17.2
    container_name: kibana-dev
    networks:
      - host
    links:
      - elasticsearch:es #可以用es这个域名访问elasticsearch服务
    depends_on:
      - elasticsearch #kibana在elasticsearch启动之后再启动
    environment:
      - "elasticsearch.hosts=http://es:9200" #设置访问elasticsearch的地址
    ports:
      - 5601:5601
  logstash:
    image: logstash:7.17.2
    container_name: logstash-dev
    networks:
      - host
    volumes:
      - /opt/mingyue/elk/logstash/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf #挂载logstash的配置文件
    depends_on:
      - elasticsearch #kibana在elasticsearch启动之后再启动
    links:
      - elasticsearch:es #可以用es这个域名访问elasticsearch服务
    ports:
      - 4560:4560
networks:
  host:

启动

docker-compose up -d --build

安装插件

ik 分词器

# 进入容器
docker exec -it elasticsearch /bin/bash

# 在线下载并安装
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.2/elasticsearch-analysis-ik-7.17.2.zip

离线包下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases

logstash-codec-json_lines 插件

# 进入容器
docker exec -it logstash /bin/bash

# 安装插件
logstash-plugin install logstash-codec-json_lines

查看

  • elasticsearch

    访问:http://ip:9200

    {
        "name": "2cdc361205b1",
        "cluster_name": "elasticsearch",
        "cluster_uuid": "atvLu5B0RFuVctvzx1aNdQ",
        "version": {
            "number": "7.17.2",
            "build_flavor": "default",
            "build_type": "docker",
            "build_hash": "de7261de50d90919ae53b0eff9413fd7e5307301",
            "build_date": "2022-03-28T15:12:21.446567561Z",
            "build_snapshot": false,
            "lucene_version": "8.11.1",
            "minimum_wire_compatibility_version": "6.8.0",
            "minimum_index_compatibility_version": "6.0.0-beta1"
        },
        "tagline": "You Know, for Search"
    }
    
  • kibana

    访问:http://ip:5601

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/78324.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!