ELK學習002:Elasticsearch 7.x 的安裝及配置


Elasticsearch 的安裝與啟動

1.1 下載 Elasticsearch 7.6.0

下載地址:https://www.elastic.co/cn/downloads/elasticsearch

下載對應需要的 ES 。我這邊是 Linux 的系統。另外 ES 支持 Docker 方式啟動。另外,ES 7.x 不需要本地 JDK 環境支持:

  • ES 5,安裝需要 JDK 8 以上
  • ES 6.5,安裝需要 JDK 11 以上
  • ES 7.2.1,內置了 JDK 12

1.2 啟動 Elasticsearch 7.6.0

[root@localhost ~]# su elsearch                      # 切換用戶
[elsearch@localhost ~]# cd elasticsearch-7.6.0/    
[elsearch@localhost ~]# bin/elasticsearch           # 正常啟動命令
[elsearch@localhost ~]# bin/elasticsearch -d         # 守護進程啟動

1.3 驗證 Elasticsearch 7.6.0 是否啟動成功

驗證方式1:打開瀏覽器,輸入 http://localhost:9200/ 地址,然后可以得到下面的信息:

驗證方式2:命令行輸入:curl 127.0.0.1:9200。或者輸入:curl localhost:9200

{
  "name" : "VM_0_9_centos",                               # 默認啟動的時候指定了 ES 實例名稱.
  "cluster_name" : "elasticsearch",                       # 默認名為 elasticsearch
  "cluster_uuid" : "noTo0yvOQBeMtZXh9D0frQ",
  "version" : {                                           # 版本信息
    "number" : "7.6.0",
    ......
  },
  "tagline" : "You Know, for Search"
}

打開瀏覽器,通過 http://localhost:9200/_cat/nodes?v 地址,可以看到當前節點信息,如下:

命令行輸入:curl 127.0.0.1:9200/_cat/nodes?v。或者輸入:curl localhost:9200/_cat/nodes?v。

ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1           45          83   1    0.00    0.01     0.08 dilm      *      VM_0_9_centos

1.4 設置 Elasticsearch 7.6.0 可以外網訪問

1. elasticsearch默認端口9200,需要開啟服務器端口才可以外網訪問。

2. 修改elasticsearch.yml配置文件,將ip改為0.0.0.0,如果需要特定ip可以訪問,可以設定為固定的ip。

network.host: 0.0.0.0

3. 啟動elasticsearch,發現無法啟動會出現報錯信息。

ERROR: [2] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2]: 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 

錯誤1解決:修改 /etc/sysctl.conf 配置文件,添加一行配置:vm.max_map_count=360000

錯誤2解決:修改elasticsearch.yml配置文件,放開注釋即可:cluster.initial_master_nodes: ["node-1", "node-2"]

Elasticsearch 的配置

1. 配置文件位於 /elasticsearch-7.6.0/config 目錄下面

  • elasticsearch.yml     es的相關配置
  • jvm.options               jvm的相關參數(內存大小等)
  • log4j2.properties     日志相關配置

2. elasticsearch.yml關鍵配置說明

# ---------------------------------- Cluster ---------------------------------------------------
cluster.name: my-application   ES集群名稱,以此作為是否同一集群的判斷條件,相同集群內的節點設置相同的集群名。

# ----------------------------------- Node -----------------------------------------------------
node.name: node-1              ES節點名稱,以此作為集群中不同節點的區分條件,即實例名。

# ----------------------------------- Paths ----------------------------------------------------
path.data: /path/to/data       數據存儲地址,指定了存儲文檔數據目錄
path.logs: /path/to/logs       日志存儲地址,注意這里要改成實際路徑

# ---------------------------------- Network ---------------------------------------------------
network.host: 127.0.0.1        網絡地址和端口,用於 http 和 transport 服務使用
http.port: 9200

3. elasticsearch的兩種模式:Development 與 Production 模式說明:

  • 以 transport 的地址是否綁定在 localhost 為標准判斷 network.host。
  • Development 模式下在啟動時會以warning的方式提示配置檢查異常。
  • Production 模式下在啟動時會以error的方式提示配置檢查異常並退出。

4. 參數修改的第二種方式

[elsearch@localhost ~]# bin/elasticsearch -Ehttp.port=19200

Elasticsearch 本地啟動集群的方式:即單機集群多個 ES 實例

1. 單機多個 ES 實例,形成一個 ES 單機偽集群,啟動腳本如下:

[elsearch@localhost ~]# bin/elasticsearch  
[elsearch@localhost ~]# bin/elasticsearch -E http.port=7200 -E path.data=node2
[elsearch@localhost ~]# bin/elasticsearch -E http.port=8200 -E path.data=node3
# [elsearch@localhost ~]# bin/elasticsearch -E node.name=node01 -E cluster.name=bysocket_es_cluster -E path.data=node01_data -d
# [elsearch@localhost ~]# bin/elasticsearch -E node.name=node02 -E cluster.name=bysocket_es_cluster -E path.data=node02_data -d

2. 查看多個 ES 實例啟動情況

打開瀏覽器,輸入 http://localhost:9200/_cat/nodes?v 地址,可以看到啟動情況:master的值為*,則為當前 master 節點。

相關查看地址:http://IP:3120/_cat/nodes,  http://IP:3120/_cat/nodes?v,  http://IP:3120/_cluster/stats。

3. 關閉集群中的 ES 實例,可以使用簡單的命令實現

[root@localhost ~]# ps -ef | grep elasticsearch           # 找到elasticsearch線程
[root@localhost ~]# kill -9 pid                           # 殺死elasticsearch線程

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM