docker-compose一鍵安裝elasticsearch和kibana

安裝步驟:

一、容器編排腳本

在你的目錄新建個文件夾 創(chuàng)建 docker-compose.yml


version: "3.1"

# 服務配置

services:

  elasticsearch:

    container_name: elasticsearch-8.8.1

    image: docker.elastic.co/elasticsearch/elasticsearch:8.8.1

    # 用來給容器root權限(不安全)可移除

    privileged: true

    # 在linux里ulimit命令可以對shell生成的進程的資源進行限制

    ulimits:

      memlock:

        soft: -1

        hard: -1

    environment:

      - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"

      - "http.host=0.0.0.0"

      - "node.name=elastic01"

      - "cluster.name=cluster_elasticsearch"

      - "discovery.type=single-node"

    ports:

      - "9200:9200"

      - "9300:9300"

    volumes:

      # - ./elasticsearch/config:/usr/share/elasticsearch/config

      - ./elasticsearch/data:/usr/share/elasticsearch/data

      - ./elasticsearch/plugin:/usr/share/elasticsearch/plugins

    networks:

      - elastic_net

  kibana:

    container_name: kibana-8.8.1

    image: docker.elastic.co/kibana/kibana:8.8.1

    ports:

      - "5601:5601"

    # volumes:

    #  - ./kibana/config:/usr/share/kibana/config

    networks:

      - elastic_net

# 網(wǎng)絡配置

networks:

  elastic_net:

    driver: bridge

二、容器映射目錄配置

2.1 掛在卷 同步配置


# 啟動服務

docker-compose up -d

# 在docker-compose 目錄中,執(zhí)行容器文件拷貝到宿主機

# 1.創(chuàng)建 kibana 映射目錄

# 2.拷貝 elasticsearch 配置

# 3.拷貝 kibana 配置

mkdir kibana

docker cp elasticsearch-8.8.1:/usr/share/elasticsearch/config ./elasticsearch/config

docker cp kibana-8.8.1:/usr/share/kibana/config ./kibana/config

2.2 elasticsearch配置


# 集群節(jié)點名稱

node.name: "elastic01"

# 設置集群名稱為elasticsearch

cluster.name: "cluster_elasticsearch"

# 網(wǎng)絡訪問限制

network.host: 0.0.0.0

# 以單一節(jié)點模式啟動

discovery.type: single-node

# 是否支持跨域

http.cors.enabled: true

# 表示支持所有域名

http.cors.allow-origin: "*"

# 內(nèi)存交換的選項,官網(wǎng)建議為true

bootstrap.memory_lock: true

# 修改安全配置 關閉 證書校驗

xpack.security.http.ssl:

  enabled: false

xpack.security.transport.ssl:

  enabled: false

2.3 kibana配置


# Default Kibana configuration for docker target

i18n.locale: zh-CN

server.host: "0.0.0.0"

server.shutdownTimeout: "5s"

elasticsearch.hosts: [ "http://elasticsearch:9200" ]

monitoring.ui.container.elasticsearch.enabled: true

#此處為新生成的kibana賬號和密碼

elasticsearch.username: "kibana_system"

elasticsearch.password: "Wgnm5flBNMi*xQW5yHww"

2.4 重啟服務加載配置


# 1\. 首先放開 docker-compose.yml 中的注釋

- ./elasticsearch/config:/usr/share/elasticsearch/config

- ./kibana/config:/usr/share/kibana/config

# 2\. 更新容器

docker-compose up -d

# 3.訪問地址:

elastic:http://localhost:9200

kibana:http://localhost:5601

三、訪問elasticsearch

重置 elastic 用戶密碼


# 重置 elastic 用戶密碼

docker exec -it elasticsearch-8.8.1 /usr/share/elasticsearch/bin/elasticsearch-reset-password -uelastic

# 提示如下 輸入 y:

This tool will reset the password of the [elastic] user to an autogenerated value.

The password will be printed in the console.

Please confirm that you would like to continue [y/N]

# 輸入后顯示結果 xxxxxx 即為密碼

Password for the [elastic] user successfully reset.

New value: xxxxxx

4.3 密碼kibana重置


# 重置 kibana_system 用戶密碼

docker exec -it elasticsearch-8.8.1 /usr/share/elasticsearch/bin/elasticsearch-reset-password -ukibana_system

# 提示如下 輸入 y:

This tool will reset the password of the [kibana_system] user to an autogenerated value.

The password will be printed in the console.

Please confirm that you would like to continue [y/N]

# 輸入后顯示結果 xxxxxx 即為密碼

Password for the [kibana_system] user successfully reset.

New value: xxxxxx

4.4 提示輸入驗證碼


# 驗證碼獲取

docker exec -it kibana-8.8.1 /usr/share/kibana/bin/kibana-verification-code

# 輸入結果

Your verification code is:  xxx xxx

本地測試賬號密碼

本地elasticSearch賬號密碼:

賬號:elastic

密碼:-KNVfdUof92By2WznPsi

本地kibana賬號密碼:

賬號:kibana_system

密碼:Wgnm5flBNMi*xQW5yHww
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容