From 548f01850f807472b11e6a6159a13550885f7142 Mon Sep 17 00:00:00 2001 From: Wang Date: Fri, 26 Jul 2024 10:34:35 +0800 Subject: [PATCH] Add Kibana component for Elasticsearch (#1710) ### What problem does this PR solve? Add Kibana component for Elasticsearch ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: Theta Wang (ncu) --- docker/.env | 2 ++ docker/docker-compose-admin-tool.yml | 33 ++++++++++++++++++++++++++++ docker/docker-compose.yml | 5 +++-- docker/init-kibana.sh | 30 +++++++++++++++++++++++++ docker/service_conf.yaml | 4 ++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 docker/docker-compose-admin-tool.yml create mode 100755 docker/init-kibana.sh diff --git a/docker/.env b/docker/.env index 36985f5c7..568b5ee6c 100644 --- a/docker/.env +++ b/docker/.env @@ -10,6 +10,8 @@ ELASTIC_PASSWORD=infini_rag_flow # Port to expose Kibana to the host KIBANA_PORT=6601 +KIBANA_USER=rag_flow +KIBANA_PASSWORD=infini_rag_flow # Increase or decrease based on the available host memory (in bytes) diff --git a/docker/docker-compose-admin-tool.yml b/docker/docker-compose-admin-tool.yml new file mode 100644 index 000000000..1d52891af --- /dev/null +++ b/docker/docker-compose-admin-tool.yml @@ -0,0 +1,33 @@ +services: + kibana: + image: kibana:${STACK_VERSION} + container_name: ragflow-kibana + environment: + ELASTICSEARCH_USERNAME: ${KIBANA_USER} + ELASTICSEARCH_PASSWORD: ${KIBANA_PASSWORD} + ELASTICSEARCH_HOSTS: "http://es01:9200" + ports: + - ${KIBANA_PORT}:5601 + depends_on: + es01: + condition: service_healthy + kibana-user-init: + condition: service_completed_successfully + + networks: + - ragflow + kibana-user-init: + image: appropriate/curl + depends_on: + es01: + condition: service_healthy + volumes: + - ./init-kibana.sh:/app/init-kibana.sh + environment: + - ELASTIC_PASSWORD=${ELASTIC_PASSWORD} + - KIBANA_USER=${KIBANA_USER} + - KIBANA_PASSWORD=${KIBANA_PASSWORD} + command: /bin/sh -c "sh /app/init-kibana.sh" + networks: + - ragflow + restart: 'no' diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 97a1cb5c3..f1d5fb006 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,7 +1,8 @@ include: - path: ./docker-compose-base.yml env_file: ./.env - + - path: ./docker-compose-admin-tool.yml + env_file: ./.env services: ragflow: depends_on: @@ -27,4 +28,4 @@ services: - MACOS=${MACOS} networks: - ragflow - restart: always + restart: always \ No newline at end of file diff --git a/docker/init-kibana.sh b/docker/init-kibana.sh new file mode 100755 index 000000000..1e5ca6907 --- /dev/null +++ b/docker/init-kibana.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# 等待 Elasticsearch 啟動 +until curl -u "elastic:${ELASTIC_PASSWORD}" -s http://es01:9200 >/dev/null; do + echo "等待 Elasticsearch 啟動..." + sleep 5 +done + + +echo "使用者: elastic:${ELASTIC_PASSWORD}" + + + +PAYLOAD="{ + \"password\" : \"${KIBANA_PASSWORD}\", + \"roles\" : [ \"kibana_admin\",\"kibana_system\" ], + \"full_name\" : \"${KIBANA_USER}\", + \"email\" : \"${KIBANA_USER}@example.com\" +}" +echo "新用戶帳戶: $PAYLOAD" + +# 創建新用戶帳戶 +curl -X POST "http://es01:9200/_security/user/${KIBANA_USER}" \ +-u "elastic:${ELASTIC_PASSWORD}" \ +-H "Content-Type: application/json" \ +-d "$PAYLOAD"s + +echo "新用戶帳戶已創建" + +exit 0 diff --git a/docker/service_conf.yaml b/docker/service_conf.yaml index 778f0f0c1..a3538429c 100644 --- a/docker/service_conf.yaml +++ b/docker/service_conf.yaml @@ -17,6 +17,10 @@ es: hosts: 'http://es01:9200' username: 'elastic' password: 'infini_rag_flow' +kibana: + hosts: 'http://${host}:6601' + username: 'rag_flow' + password: 'infini_rag_flow' redis: db: 1 password: 'infini_rag_flow'