跳到主要內容

Elasticsearch


Elasticsearch Install

Dockerfile


FROM elastic/elasticsearch:7.2.0


Build Image Shell Script


docker build -t myelasticsearch .


Prepare yours ES config



copy elasticsearch.yml jvm.options log4j2.properties to /es/conf/path


Docker start Shell Script


# 由於沒有安全保護,因此設計上希望 ES 不對外,使用 --network 串在已建立的 docker network 中

docker run -it -d --name myelasticsearch --restart=unless-stopped --network=my-dev_mydemonet -v /es/conf/path:/usr/share/elasticsearch/config -v /es/data/path:/usr/share/elasticsearch/data -v /es/plugin/path:/usr/share/elasticsearch/plugins  -e "discovery.type=single-node" -p 9300:9300 -p 9200:9200 myelasticsearch


安裝中文分詞
參考來源


docker exec -it myelasticsearch sh elasticsearch-plugin install analysis-smartcn


補充


定時刪除Index Shell Script
由於架構中 ES 屬於 短期、快速 查詢使用,僅保留七日的紀錄,因此需準備一組 Script 每日清理過期 Index
可以使用任何排程工具執行以下 Script



idx_date=$(date +%Y.%m.%d -d "$DATE - 7 day")
echo "curl -XDELETE http://localhost:9200/fluentd.nginx.web.access-${idx_date}"
curl -XDELETE http://localhost:9200/fluentd.nginx.web.access-${idx_date}


ES 基礎指令
CRUD 交由程式處理



# 查詢 ES Index List
$>curl http://localhost:9200/_cat/indices?v

# 刪除 ES Index
$>curl -XDELETE http://localhost:9200/${index name}

# 新增 ES Index
$>curl -XPUT http://localhost:9200/${index name}



留言

這個網誌中的熱門文章

FluentD 實作 Error Log

FluentD 實作 Error Log 本篇將介紹使用 DotNet 專案 log4net 套件,紀錄的 log 針對 Error Level 的訊息透過FluentD 提取出來 在紀錄中 增加 trace ID 設入 MongoDB , 及加入 Slack 通知 延伸閱讀 FluentD 參數說明 FluentD 實作 Nginx Access Log FluentD 實作 Nginx Access Log 補充 log4net <?xml version="1.0" encoding="utf-8" ?> <configuration> <log4net> <appender name="All" type="log4net.Appender.RollingFileAppender"> <file value="/var/log/my.log" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <datePattern value="yyyy-MM-dd" /> <maximumFileSize value="5MB" /> <maxSizeRollBackups value="10" /> <staticLogFileName value="true" /> <PreserveLogFileNameExtension value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="[%date] [...

Grafana Dashboard 建立

建立自己的 Dashboard # 由於 intelligent sense 相當不錯,輸入關鍵字他會帶出 metric label # 另外可參考 https://prometheus.io/docs/prometheus/latest/querying/basics/ Prometheus Query # 或是直接拿其他已建立的Dashboard 可複製到新的 Dashboard ex: node_memory_MemTotal_bytes # 取伺服器記憶體容量資料 # 過濾條件在{}加入 ex: node_memory_MemTotal_bytes{instance="${server 1}:9100"} # 要取特定伺服器資料 # Setting 中設定 Variables ex: node_memory_MemTotal_bytes{instance=~"$node"} # 變數名稱 node 建立 Alert .Visualization 必須是Graph

DotNet Core 專案部署腳本

DotNet core SDK 首先在 Server 上準備編譯環境 Dockerfile #2.2 3.0 3.1 FROM mcr.microsoft.com/dotnet/core/sdk:3.1 RUN mkdir /web WORKDIR /web build docker image shell script docker build -t dotnetcoresdk:3.1 . start docker container shell script docker run -it -d \ --name dotnet-core-sdk-3.1 \ -v /opt/web:/web \ dotnetcoresdk:3.1 Jenkins Execute shell script on remote hosting using ssh #切換至專案目錄 cd /opt/web/project/path #取得最新版本 git pull #切換至專案目錄 && 刷新 Dotnet Library docker exec -i dotnet-core-sdk-3.1 bash -c "cd project/path && dotnet restore" #切換至專案目錄 && 刪除上一次編譯的檔案 && 編譯 docker exec -i dotnet-core-sdk-3.1 bash -c "cd project/path && rm -rf bin/Release && dotnet publish -c Release" #docker-compose.yml 參 DotNet core Runtime Section #!--rmi all 將原本執行的容器關閉並移除Image docker-compose down --rmi all #將新版程式包入 Image 並開始容器 docker-compose up -d DotNet core Runtime 專案中包含 Dockerfile & docker-compose.yml d...