Centos 7 通過 targz 文件安裝 Elastic Search 服務

来源:https://www.cnblogs.com/milton/archive/2023/06/08/17461658.html
-Advertisement-
Play Games

區別於通過發行版自帶的倉庫, 介紹如何通過 targz 文件安裝 Elastic Search 服務, 使用的 Linux 為 Centos 7 ...


區別於通過發行版自帶的倉庫, 介紹如何通過 targz 文件安裝 Elastic Search 服務, 使用的 Linux 為 Centos 7

下載

https://www.elastic.co/downloads/elasticsearch

選擇 Linux x86_64, 下載 elasticsearch-8.8.0-linux-x86_64.tar.gz

安裝

解壓到 /opt/elasticsearch, 並加上軟鏈

tar xvf elasticsearch-8.8.0-linux-x86_64.tar.gz 

cd /opt/
sudo mkdir elasticsearch
cd elasticsearch/
sudo mv ~/backup/elasticsearch-8.8.0 .
sudo chown -R milton:milton elasticsearch-8.8.0/
sudo ln -s elasticsearch-8.8.0 latest

這個版本的 Elastic Search 自帶 JVM, 版本為 openjdk version "20.0.1" 2023-04-18

配置

可能需要修改的配置

# Use a descriptive name for your cluster:
#cluster.name: my-application
# Use a descriptive name for the node:
node.name: centos7001
# Add custom attributes to the node:
#node.attr.rack: r1
# Path to directory where to store the data (separate multiple locations by comma):
path.data: /home/milton/es_run/data
# Path to log files:
path.logs: /home/milton/es_run/logs
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
network.host: 192.168.9.10
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#http.port: 9200
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#discovery.seed_hosts: ["centos7001"]
# Bootstrap the cluster using an initial set of master-eligible nodes:
cluster.initial_master_nodes: ["centos7001"]
# For more information, consult the discovery and cluster formation module documentation.
# Allow wildcard deletion of indices:
#action.destructive_requires_name: false
xpack.security.enabled: false
  • cluster.name: my-application 集群名稱
  • node.name 要改成當前伺服器的hostname
  • path.data: /somew/data 數據路徑
  • path.logs: /somewhere/logs 日誌路徑
  • network.host: 192.168.123.123 監聽的網口, 預設只監聽127.0.0.1
  • http.port: 9200 監聽的埠, 預設為9200
  • discovery.seed_hosts: ["192.168.123.123"] 集群主機列表, 和下麵的cluster.initial_master_nodes必須寫一個, 不然啟動會報錯. 如果只是單節點, 這行可以註釋掉
  • cluster.initial_master_nodes: ["centos7001"] 啟動時初始化的參與選主的node 對應的 hostname, 要能解析為IP

node.name 和 cluster.initial_master_nodes, 可以填IP也可以填hostname, 但是要一致

系統配置

以下的配置用於解決下麵的問題

  1. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
  2. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
  3. the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
  4. Transport SSL must be enabled if security is enabled. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]

1. max file descriptors 65535

修改/etc/security/limits.conf (或者 /etc/security/limits.d/20-nproc.conf), 增加或修改為以下內容

*          soft    nofile    65535
*          hard    nofile    65535
*          soft    nproc     65535
*          hard    nproc     65535
root       soft    nproc     unlimited

需要重啟, 用 ulimit -n 檢查

2. vm.max_map_count 262144

修改/etc/sysctl.conf 或者 /etc/sysctl.d/99-sysctl.conf文件,增加或修改為以下內容

vm.max_map_count=262144

3. the default discovery settings are unsuitable for production use

需要配置 discovery.seed_hosts,discovery.seed_providers,cluster.initial_master_nodes中的至少一個參數

  • discovery.seed_hosts: 集群主機列表
  • discovery.seed_providers: 基於配置文件配置集群主機列表
  • cluster.initial_master_nodes: 啟動時初始化的參與選主的node

修改配置文件 config/elasticsearch.yml, 配置以下兩項

discovery.seed_hosts: ["127.0.0.1"]
cluster.initial_master_nodes: ["node-1"]

4. Transport SSL must be enabled if security is enabled

修改配置文件 config/elasticsearch.yml, 增加

xpack.security.enabled: false

5. WARN: This node is a fully-formed single-node cluster

如果在日誌中看到類似這樣的錯誤

[2023-06-09T07:29:43,781][WARN ][o.e.c.c.Coordinator      ] [centos7001] This node is a fully-formed single-node cluster with cluster UUID [6ejfGD71SVe6OpypK-1HmA], but it is configured as if to discover other nodes and form a multi-node cluster via the [discovery.seed_hosts=[192.168.123.123]] setting. Fully-formed clusters do not attempt to discover other nodes, and nodes with different cluster UUIDs cannot belong to the same cluster. The cluster UUID persists across restarts and can only be changed by deleting the contents of the node's data path(s). Remove the discovery configuration to suppress this message.

說明這是一個單節點的ES, 但是配置文件中配置其去發現另一個節點. 需要將 discovery.seed_hosts 中設置的節點去掉

運行

直接運行, 這樣會將日誌直接輸出到控制台

/opt/elasticsearch/latest/bin/elasticsearch

後臺運行, 在命令後加 -d -p pid-file, 在輸出一段控制台日誌後, 如果沒有報錯, 會轉入後臺運行

/opt/elasticsearch/latest/bin/elasticsearch -d -p /opt/elasticsearch/latest/logs/pid

停止

根據記錄的 pid 停止, 啟動時記錄用的哪個文件, 這裡就用對應的文件

pkill -F /opt/elasticsearch/latest/logs/pid

使用

ES與關係型資料庫的名詞對應關係

服務檢查

瀏覽器打開 http://192.168.123.123:9200/ 能看到ES的輸出, 就說明運行成功

{
  "name" : "centos70",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "_na_",
  "version" : {
    "number" : "8.8.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "c01029875a091076ed42cdb3a41c10b1a9a5a22f",
    "build_date" : "2023-05-23T17:16:07.179039820Z",
    "build_snapshot" : false,
    "lucene_version" : "9.6.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

查詢集群運行狀況

curl -XGET "127.0.0.1:9200/_cat/health?v"

查詢集群所有索引

$ curl -XGET "192.168.123.123:9200/_cat/indices?v"
health status index        uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   commodity002 XIrCTL_XQq2vteuEflY6vA   1   1          0            0       247b           247b
yellow open   commodity001 Z-LKjzsuR8uMLgVlYYALEw   1   1          0            0       247b           247b
yellow open   commodity004 sSxEiwNBSvernMH6EYsEvw   1   1          0            0       247b           247b
yellow open   commodity003 JSRUndkHQ8mQVdTkN9eCPw   1   1          0            0       247b           247b

按記錄數量排序, 欄位可以從上面結果的表頭中取

curl -XGET "127.0.0.1:9200/_cat/indices?v&s=docs.count"

按存儲空間排序

curl -XGET "127.0.0.1:9200/_cat/indices?v&s=store.size"

創建索引

不帶參數, ?pretty用於格式化響應的json

curl -X PUT "localhost:9200/commodity?pretty"

帶參數

curl -H 'Content-Type: application/json' -X PUT 'http://192.168.123.123:9200/commodity007?pretty' \
--data '{
    "settings": {
        "number_of_shards": 3,
        "number_of_replicas": 2
    }
}'

帶索引欄位,

curl -H 'Content-Type: application/json' -X PUT 'http://192.168.123.123:9200/commodity008?pretty' \
--data '{
  "settings": {
    "number_of_shards": 2,
    "number_of_replicas": 1
  },
  "mappings": {
    "properties": {
      "name":{
        "type": "text"
      },
      "studymodel":{
        "type": "keyword"
      },
      "price":{
        "type": "double"
      },
      "timestamp": {
         "type": "date",
         "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
      },
      "pic":{
        "type":"text",
        "index": false
      }
    }
  }
}'

對於嵌套存在的欄位, mappings是可以用層級的, 例如對 type1下的obj1的索引

{
  "mappings": {
    "type1": {
      "properties": {
        "obj1": {
          "type": "nested"
        }
      }
    }
  }
}

查看索引欄位及設置

curl -X GET 'http://192.168.123.123:9200/commodity008?pretty'

往索引寫入內容

通過路徑指定 _id = 1, 對同一個 _id可以再次調用進行更新, 結果中的_version會遞增

curl --location --request PUT 'http://192.168.123.123:9200/commodity008/_doc/1?pretty' \
--header 'Content-Type: application/json' \
--data '{
    "name": "commodity008001",
    "studymodel": "202306",
    "price": 123.12,
    "timestamp": "2023-05-25 19:11:35",
    "pic": "23/06/01/a123b1fde0428.jpg"
}'

查詢

可以通過URL路徑區分不同索引

  • /_search 所有索引
  • /commodity008/_search commodity008索引
  • /commodity007,commodity008/_search commodity007 和 commodity008
  • /commodity*/_search 以 commodity 開頭的索引

查詢所有索引下的內容

curl -X GET 'http://192.168.123.123:9200/_search?pretty'

查詢一個索引下的內容

curl -X GET 'http://192.168.123.123:9200/commodity008/_search?pretty'

帶條件查詢

curl -H 'Content-Type: application/json' -X GET 'http://192.168.9.10:9200/commodity008/_search?pretty=null' \
--data '{
    "query" : {
        "match" : {
            "name": "commodity008001"
        }
    }
}'

帶偏移和結果數量, 請求加上 from 和 size 參數

{
  "from":10,
  "size":20,
  "query":{
    "match_all": {}
  }
}

排序, 請求加上 sort 參數

{
  "sort":[{"year":"desc"}],
  "query":{
    "match_all": {}
  }
}

限制返回的欄位, 請求加上 _source 欄位

{
  "_source":["title"],
  "query":{
    "match_all": {}
  }
}

結果格式

{
    "took": 422,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 1.0,
        "hits": [
            {
                "_index": "commodity008",
                "_id": "1",
                "_score": 1.0,
                "_source": {
                    "name": "commodity008001",
                    "studymodel": "202307",
                    "price": 123.53,
                    "timestamp": "2023-05-25 19:11:35",
                    "pic": "23/06/01/a123b1fde0428.jpg"
                }
            },
            ...
        ]
    }
}

參考


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • # 安裝指定版本的mysql(安裝mysql5.7) ## 目標:解決需求,安裝mysql5.7 ## 前言: > 安裝軟體的三種方式: > > 1. rpm 安裝 > 2. 源代碼編譯安裝 > 3. yum倉庫安裝 > - 本地光碟 > - 阿裡雲yum源 > - 自建yum倉庫文件夾 > 4. ...
  • # 【Linux基礎】shell編程(一) 變數 [TOC] ## 什麼是shell編程 簡單的命令可以在命令行中直接輸入,但是複雜的命令需要寫在腳本里。例如一個簡單的shell腳本: ```shell #!/bin/bash #輸出一行 echo "Hello World!" ``` \#開始的行 ...
  • # 離線安裝rpm包以及自建yum倉庫 ## 離線安裝rpm - yum支持如下參數 > --downloadnoly 只下載不安裝 > > --downloaddir=directory 下載到指定目錄下 - 因此可以線上下載好需要的rpm包到建立的倉庫,後續離線安裝rpm包 > 創建存放rpm包 ...
  • # 伺服器Ubuntu Server 22.04安裝低版本MySQL5.7 最近在騰訊雲買了個伺服器準備部署我的Django項目,由於需要保證伺服器和本地開發的環境相同,所以要在Ubuntu 22.04安裝一個與本地Windows版本相同的MySQL5.7.36 ## 第一個問題 首次安裝我嘗試使用 ...
  • 我平時經常要看 PDF,但是我看書賊慢,一個 PDF 差不多幾十上百頁,看一遍要花挺長時間。 我記性還不好,看完之後,過些日子就記不清 PDF 是講什麼的了。為了找到 PDF 里的某些信息,又得再花時間。 不過,現在這些問題都不是問題了。 因為我最近發現了一個神器,1 分鐘就能讀完一個 PDF。 上 ...
  • ## 前言 本篇文章主要介紹的關於本人從剛工作到現在使用kafka的經驗,內容非常多,包含了kafka的常用命令,在生產環境中遇到的一些場景處理,kafka的一些web工具推薦等等。由於kafka這塊的記錄以及經驗是從我剛開始使用kafka,從2017年開始,可能裡面有些內容過時,請見諒。溫馨提醒, ...
  • ### 扯淡時間 前段時間,辦了一張流量卡。 有了新的手機號碼那就可以薅一波資本主義的羊毛了,所以我在京東上使用0.1大洋包郵的價格喜提了一個多肉,(在此之前我養過挺多的花,所有的都是忘了澆水被渴死了)此次痛並思痛,一定要讓我0.1大洋的的多肉看到明年的太陽。 ### 思路 > 養花幾乎不用管,只需 ...
  • # 系統架構 **主題topic和分區partition** - topic Kafka中存儲數據的邏輯分類;你可以理解為資料庫中“表”的概念;比如,將app端日誌、微信小程式端日誌、業務庫訂單表數據分別放入不同的topic - partition分區(提升kafka吞吐量) topic中數據的具體 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...