Elasticsearch 7.7部署

 Elasticsearch(簡稱:ES)是一個開源的分佈式搜索引擎, Elasticsearch 還是一個分佈式文檔數據庫.並提供了大量數據的存儲功能快速的搜索與分析功能.

  起源於 Lucene, 基於 Java 語言開發的搜索引擎類庫, 創建於 1999 年, 2005 年成爲 Apache 頂級開源項目.Lucene 具有高性能, 以擴展的優點,

主要功能

  • 分佈式搜索引擎
  • 大數據近實時分析引擎
  • 高性能
  • 容易使用/容易擴展
  • 聚合功能
  • 分佈式存儲及集羣管理

Elasticsearch個版本特性

5x版本(2016-10)

  • Lucene 6x,性能提升,默認打分機制從 TF-IDF 改爲 BM 25.
  • 支持 Ingest 節點 / Painless Scripting / Completion suggested 支持/ 原生的 Java REST 客戶端
  • Type 標記成 deprecated, 支持 Keyword 的類型
  • 性能優化
    • 內部引擎移除了避免同一文檔併發更新的競爭鎖, 帶來 15% - 20% 的性能提升.
    • Istan aggregation, 支持分片上聚合的緩存.
    • 新增了 Profile API.

6X版本(2017-10)

  • Lucene 7X
  • 新功能
    • 跨集羣複製(CCR)
    • 索引生命週期管理
    • SQL 的支持
  • 更友好的升級及數據遷移
    • 在主要版本之間的遷移更爲簡單,體驗升級.
    • 全新的基於操作的數據複製框架,可加速恢復數據.
  • 性能優化
    • 有效存儲稀疏字段的新方法,降低了存儲成本.
    • 在索引時進行排序,可加快排序的查詢性能.

7X版本(2019-4)

  • Lucene 8.0
  • 重大改進 - 正式廢除單個索引下多 Type 的支持.
  • 7.1開始, Security 功能免費試用.
  • ECK - Elasticsearch Operator on Kubernetes
  • 新功能
    • 新的集羣協調機制.
    • 功能完整的 REST 客戶端.
    • Script Score Query.
  • 性能優化
    • 默認的 Primary Shard 數從 5 改爲 1, 避免 Ober Sharding.
    • 性能優化,更快的 TOP k.

 部署elasticsearch

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

  elasticsearch7X版本自帶JDK環境,之前版本需要安裝JDK.

通用環境配置

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

1. 關閉防火牆和selinux

[root@node6 ~]# setenforce 0

[root@node6 ~]# cat /etc/selinux/config

SELINUX=disabled

 

[root@node6 ~]# systemctl stop firewalld

[root@node6 ~]# systemctl disable firewalld

 

2. 修改系統打開最大文件句柄

[root@node6 ~]# cat /etc/security/limits.conf

# End of file

*       soft   nofile       655350

*       hard   nofile       655350

*       soft    nproc       20000

*       hard    nproc       20000

 

3. 修改內核參數

[root@node6 ~]# cat /etc/sysctl.conf

# For more information, see sysctl.conf(5) and sysctl.d(5).

fs.file-max=419430

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_fin_timeout = 1

net.ipv4.tcp_keepalive_time = 1200

net.ipv4.ip_local_port_range = 10000 65535

net.ipv4.tcp_max_syn_backlog = 16384

net.ipv4.tcp_max_tw_buckets = 36000

net.ipv4.route.gc_timeout = 100

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_synack_retries = 1

net.core.somaxconn = 16384

net.core.netdev_max_backlog = 16384

net.ipv4.tcp_max_orphans = 16384

net.ipv4.tcp_rmem = 4096 4096 16777216

net.ipv4.tcp_wmem = 4096 4096 16777216

net.ipv4.tcp_mem = 786432 2097152 3145728

#kernel.pty.max = 4

vm.max_map_count=262144

 

[root@node6 ~]# sysctl -p

 

4. 創建用戶

[root@node6 ~]# useradd elasticsearch -M -s /sbin/nologin

 

5. 創建數據及日誌目錄

[root@node3 ~]# mkdir /data/elasticsearch/{data,logs} -p

[root@node3 ~]# chown elasticsearch:elasticsearch -R /data/elasticsearch/

下載並安裝elasticsearch

1

2

3

[root@node6 ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-linux-x86_64.tar.gz

 

[root@node6 ~]# rpm -ivh elasticsearch-7.7.0-x86_64.rpm

目錄說明

目錄     主要配置文件 描述 
 /usr/share/elasticsearch/bin/  elasticsearch  腳本文件存放目錄,包括 elasticesearch,安裝插件.運行統計數據等.

/etc/elasticsearch/

  elasticsearch.yml 集羣配置文件,jvm配置文件   
 /usr/share/elasticsearch/jdk/  java java運行環境 
 /data/elasticsearch/  日誌和數據目錄 數據文件及日誌目錄 
 /usr/share/elasticsearch/lib/   java類庫 
 

/usr/share/elasticsearch/modules/

  包含所有ES模塊 
/usr/share/elasticsearch/plugins/   包含所有已安裝的插件 
     

 主配置文件

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

[root@node6 ~]# cat /etc/elasticsearch/elasticsearch.yml

# ---------------------------------- Cluster -----------------------------------

# 集羣名稱

cluster.name: es-cluster

# ------------------------------------ Node ------------------------------------

# 節點 name

node.name: node-6

 

# 節點是否參加 master 選舉

node.master: true

 

# 是否爲數據節點

node.data: true

 

# ----------------------------------- Paths ------------------------------------

# 數據目錄

path.data: /data/elasticsearch/data

 

# 日誌文件存儲路徑

path.logs: /data/elasticsearch/logs

# ----------------------------------- Memory -----------------------------------

# 是否啓動時鎖定內存

bootstrap.memory_lock: true

# ---------------------------------- Network -----------------------------------

# 監聽地址

network.host: 0.0.0.0

 

# 監聽端口

http.port: 9200

# --------------------------------- Discovery ----------------------------------

# 自動發現節點

discovery.seed_hosts: ["172.16.0.206""172.16.0.204","172.16.0.203"]

 

# Bootstrap the cluster using an initial set of master-eligible nodes:

# 初始化引導集羣節點

cluster.initial_master_nodes: ["172.16.0.206""172.16.0.204","172.16.0.203"]

JVM配置

配置建議:

官網配置建議: https://www.elastic.co/cn/blog/a-heap-of-trouble

  • Xms 和 Xmx 設置成一樣
  • Xmx 不要超過機器內存的 50 %.
  • 不要超過 30G.

1

2

3

vim /etc/elasticsearch/jvm.options

-Xms2g

-Xmx2g

 啓動並檢查集羣狀態

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

# 啓動服務並設爲開機自啓

[root@node6 ~]# systemctl start elasticsearch

[root@node6 ~]# systemctl enable elasticsearch

 

# 查看集羣狀態

[root@node6 ~]# curl http://172.16.0.206:9200/_cluster/health?pretty

{

  "cluster_name" "es-cluster",

  "status" "green",

  "timed_out" false,

  "number_of_nodes" : 3,

  "number_of_data_nodes" : 3,

  "active_primary_shards" : 0,

  "active_shards" : 0,

  "relocating_shards" : 0,

  "initializing_shards" : 0,

  "unassigned_shards" : 0,

  "delayed_unassigned_shards" : 0,

  "number_of_pending_tasks" : 0,

  "number_of_in_flight_fetch" : 0,

  "task_max_waiting_in_queue_millis" : 0,

  "active_shards_percent_as_number" : 100.0

}

# 查看各nodes 數據和主節點

[root@node6 ~]# curl http://172.16.0.206:9200/_cat/nodes?v

ip           heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name

172.16.0.203           59          96   1    0.12    0.06     0.05 dilmrt    -      node-3

172.16.0.204           26          95   1    0.05    0.07     0.06 dilmrt    *      node-4

172.16.0.206           36          78   0    0.01    0.04     0.05 dilmrt    -      node-6

elasticsearch狀態說明

  • green:表示每個index的shard和replica都是活躍狀態的。
  • yellow:表示每個index的shard是活躍狀態的,replica是不可用狀態的。
  • red:表示索引中有些shard是不可用狀態,導致數據丟失。 

elasticsearch-head

  elasticsearch-head 是集羣管理, 數據可視化, 增刪改查, 查詢語句可視化工具. 從 ES5 版本後安裝方式 和 ES2 以上版本有所不同. ES2 可使用安裝插件方式進行安裝, 但是從 ES5 之後需要使用 NodeJs來啓動.

  官網地址: https://github.com/mobz/elasticsearch-head

安裝部署

1

2

3

4

5

git clone git://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head

yum install npm

npm config set registry https://mirrors.huaweicloud.com/repository/npm/

npm install

 

 修改配置文件

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

修改默認監聽地址

配置文件路徑: path/elasticsearch-head/Gruntfile.js

在server下options選項中添加:  hostname'0.0.0.0',

                connect: {

                        server: {

                                options: {

                                        hostname'0.0.0.0'# 新添加內容  

                                        port: 9100,

                                        base: '.',

                                        keepalive: true

                                }

                        }

                }

 

修改默認連接地址

配置文件: path/elasticsearch-head/_site/app.js

# 修改http://localhost:9200 爲 http://es-ip:9200

this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.16.0.206:9200";

cerebro

  cerebro 和 elasticsearch-head 類似.是一款基於Web的ElasticSearch管理監控工具 圖形化比elasticsearch-head更加友好.

  項目地址: https://github.com/lmenezes/cerebro

安裝軟件

1

2

3

wget https://github.com/lmenezes/cerebro/releases/download/v0.9.1/cerebro-0.9.1.tgz

tar xf cerebro-0.9.1.tgz

cd cerebro-0.9.1/

修改配置文件

1

2

3

4

5

6

7

vim /usr/local/cerebro-0.9.1/conf/application.conf

hosts = [

  {

    host = "http://172.16.0.206:9200"

    name = "es-cluster"

  }

]

啓動程序

1

2

3

4

# 默認監聽 0.0.0.0

bin/cerebro

# 也可指定監聽ip和端口號

bin/cerebro -Dhttp.port=1234 -Dhttp.address=127.0.0.1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章