警告

  • es 最好不要 7.10.2 之后的版本 推荐用opensearch-1.1.0

硬件服务器

  • 10.168.2.87
  • 10.168.2.88
  • 10.168.2.89

1.环境准备 (每台都需要做)

1.1创建用户(root用户操作)

  • useradd top

1.2 修改用户密码(root用户操作)

  • passwd top

1.3 赋予用户sudo权限(root用户操作)

  • 修改命令

    1chmod -v u+w /etc/sudoers
    2sed -i 's#.*top.*##g' /etc/sudoers
    3sed -i 's#root.*ALL=(ALL).*ALL#root  ALL=(ALL)  ALL \ntop   ALL=(ALL)  ALL#g' /etc/sudoers
    4chmod -v u-w /etc/sudoers
    

1.4 安全limits文件限制

  • 修改文件

    1vim  /etc/security/limits.conf
    
  • 增加的内容

    1* soft nofile 65536
    2* hard nofile 65536
    

最后几行加上 需要增加的部分

1.5 系统文件限制

  • 修改文件

    1vim  /etc/sysctl.conf 
    
  • 增加的内容

    1vm.max_map_count=655360
    

最后几行加上 需要增加的部分(最后几行加上)

1.6 载入指定配置

  • 修改文件

    1[top@node85 .ssh]$ sudo sysctl -p
    2[sudo] top 的密码:
    3vm.max_map_count = 655360
    
  • 结果如图

image-20211111205714215

1.7 重启

  • 执行命令

    1sudo reboot
    

2.Es安装参考

官网下载地址

2.1 下载安装包:

  • 执行命令

    1mkdir /home/top/es
    2cd /home/top/es
    3wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.2-linux-x86_64.tar.gz
    

3.ES安装

3.1 解压ES安装包

  • 执行命令

    1cd /home/top/es
    2tar -xzvf elasticsearch-7.10.2-linux-x86_64.tar.gz
    

3.2 创建数据目录、日志目录

  • 执行命令

    1mkdir /home/top/es/data -p
    2mkdir /home/top/es/logs -p
    

3.3分发配置及安装目录

  • 执行命令

    1scp -r  /home/top/es u86:/home/top/        
    2scp -r  /home/top/es u87:/home/top/
    
  • 或者

    1scp -r  /home/top/es top@10.168.2.86:/home/top/
    2scp -r  /home/top/es top@10.168.2.87:/home/top/
    

4. ES节点配置

  • 10.168.2.85 (master)

  • cat /home/top/es/elasticsearch-7.10.2/config/elasticsearch.yml

     1# ======================== Elasticsearch Configuration =========================
     2#
     3# NOTE: Elasticsearch comes with reasonable defaults for most settings.
     4#       Before you set out to tweak and tune the configuration, make sure you
     5#       understand what are you trying to accomplish and the consequences.
     6#
     7# The primary way of configuring a node is via this file. This template lists
     8# the most important settings you may want to configure for a production cluster.
     9#
    10# Please consult the documentation for further information on configuration options:
    11# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
    12#
    13# ---------------------------------- Cluster -----------------------------------
    14#
    15# Use a descriptive name for your cluster:
    16# 集群名字
    17cluster.name: es-top
    18#
    19# ------------------------------------ Node ------------------------------------
    20#
    21# Use a descriptive name for the node:
    22# 描述节点名字
    23node.name: node85
    24#
    25# Add custom attributes to the node:
    26#
    27#node.attr.rack: r1
    28#
    29# ----------------------------------- Paths ------------------------------------
    30#
    31# Path to directory where to store the data (separate multiple locations by comma):
    32#
    33path.data: /home/top/es/data
    34#
    35# Path to log files:
    36#
    37path.logs: /home/top/es/logs
    38#
    39# ----------------------------------- Memory -----------------------------------
    40#
    41# Lock the memory on startup:
    42#
    43#bootstrap.memory_lock: true
    44#
    45# Make sure that the heap size is set to about half the memory available
    46# on the system and that the owner of the process is allowed to use this
    47# limit.
    48#
    49# Elasticsearch performs poorly when the system is swapping the memory.
    50#
    51# ---------------------------------- Network -----------------------------------
    52#
    53# By default Elasticsearch is only accessible on localhost. Set a different
    54# address here to expose this node on the network:
    55#
    56network.host: node85
    57#
    58# By default Elasticsearch listens for HTTP traffic on the first free port it
    59# finds starting at 9200. Set a specific HTTP port here:
    60#
    61http.port: 9200
    62# tcp端口
    63transport.tcp.port: 9300
    64#
    65# For more information, consult the network module documentation.
    66#
    67# --------------------------------- Discovery ----------------------------------
    68#
    69# Pass an initial list of hosts to perform discovery when this node is started:
    70# The default list of hosts is ["127.0.0.1", "[::1]"]
    71#
    72discovery.seed_hosts: ["node85", "node86","node87"]
    73#
    74# Bootstrap the cluster using an initial set of master-eligible nodes:
    75#
    76cluster.initial_master_nodes: ["node85"]
    77#
    78# For more information, consult the discovery and cluster formation module documentation.
    79#
    80# ---------------------------------- Various -----------------------------------
    81#
    82# Require explicit names when deleting indices:
    83#
    84#action.destructive_requires_name: true
    85
    86##  7.15 没有个配置了
    87#  node.data
    88#  node.ingest
    89#  node.master
    90#  node.ml
    91#  node.remote_cluster_client
    92#  node.transform
    93#  node.voting_only
    94## 需要用 https://www.elastic.co/guide/en/elasticsearch/reference/7.15/modules-node.html#node-roles
    95
    96# # 跨域
    97http.cors.enabled: true
    98http.cors.allow-origin: "*"
    
  • 10.168.2.86 (node)

  • cat /home/top/elasticsearch-7.10.2/config/elasticsearch.yml
 1# ======================== Elasticsearch Configuration =========================
 2#
 3# NOTE: Elasticsearch comes with reasonable defaults for most settings.
 4#       Before you set out to tweak and tune the configuration, make sure you
 5#       understand what are you trying to accomplish and the consequences.
 6#
 7# The primary way of configuring a node is via this file. This template lists
 8# the most important settings you may want to configure for a production cluster.
 9#
10# Please consult the documentation for further information on configuration options:
11# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
12#
13# ---------------------------------- Cluster -----------------------------------
14#
15# Use a descriptive name for your cluster:
16# 集群名字
17cluster.name: es-top
18#
19# ------------------------------------ Node ------------------------------------
20#
21# Use a descriptive name for the node:
22# 描述节点名字
23node.name: node86
24#
25# Add custom attributes to the node:
26#
27#node.attr.rack: r1
28#
29# ----------------------------------- Paths ------------------------------------
30#
31# Path to directory where to store the data (separate multiple locations by comma):
32#
33path.data: /home/top/es/data
34#
35# Path to log files:
36#
37path.logs: /home/top/es/logs
38#
39# ----------------------------------- Memory -----------------------------------
40#
41# Lock the memory on startup:
42#
43#bootstrap.memory_lock: true
44#
45# Make sure that the heap size is set to about half the memory available
46# on the system and that the owner of the process is allowed to use this
47# limit.
48#
49# Elasticsearch performs poorly when the system is swapping the memory.
50#
51# ---------------------------------- Network -----------------------------------
52#
53# By default Elasticsearch is only accessible on localhost. Set a different
54# address here to expose this node on the network:
55#
56network.host: node86
57#
58# By default Elasticsearch listens for HTTP traffic on the first free port it
59# finds starting at 9200. Set a specific HTTP port here:
60#
61http.port: 9200
62# tcp端口
63transport.tcp.port: 9300
64#
65# For more information, consult the network module documentation.
66#
67# --------------------------------- Discovery ----------------------------------
68#
69# Pass an initial list of hosts to perform discovery when this node is started:
70# The default list of hosts is ["127.0.0.1", "[::1]"]
71# 配置两个重要的发现和集群形成设置,以便集群中的节点可以相互发现并选举一个主节点
72discovery.seed_hosts: ["node85:9300", "node86:9300","node87:9300"]
73#
74# Bootstrap the cluster using an initial set of master-eligible nodes:
75# 明确列出应在第一次选举中计算其选票的主合格节点
76cluster.initial_master_nodes: ["node85"]
77#
78# For more information, consult the discovery and cluster formation module documentation.
79#
80# ---------------------------------- Various -----------------------------------
81#
82# Require explicit names when deleting indices:
83#
84#action.destructive_requires_name: true
85
86##  7.15 没有个配置了
87#  node.data
88#  node.ingest
89#  node.master
90#  node.ml
91#  node.remote_cluster_client
92#  node.transform
93#  node.voting_only
94## 需要用 https://www.elastic.co/guide/en/elasticsearch/reference/7.15/modules-node.html#node-roles
95
96# # 跨域
97http.cors.enabled: true
98http.cors.allow-origin: "*"
  • 10.168.2.87 (node)
  • cat /home/top/elasticsearch-7.10.2/config/elasticsearch.yml
 1# ======================== Elasticsearch Configuration =========================
 2#
 3# NOTE: Elasticsearch comes with reasonable defaults for most settings.
 4#       Before you set out to tweak and tune the configuration, make sure you
 5#       understand what are you trying to accomplish and the consequences.
 6#
 7# The primary way of configuring a node is via this file. This template lists
 8# the most important settings you may want to configure for a production cluster.
 9#
10# Please consult the documentation for further information on configuration options:
11# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
12#
13# ---------------------------------- Cluster -----------------------------------
14#
15# Use a descriptive name for your cluster:
16# 集群名字
17cluster.name: es-top
18#
19# ------------------------------------ Node ------------------------------------
20#
21# Use a descriptive name for the node:
22# 描述节点名字
23node.name: node87
24#
25# Add custom attributes to the node:
26#
27#node.attr.rack: r1
28#
29# ----------------------------------- Paths ------------------------------------
30#
31# Path to directory where to store the data (separate multiple locations by comma):
32#
33path.data: /home/top/es/data
34#
35# Path to log files:
36#
37path.logs: /home/top/es/logs
38#
39# ----------------------------------- Memory -----------------------------------
40#
41# Lock the memory on startup:
42#
43#bootstrap.memory_lock: true
44#
45# Make sure that the heap size is set to about half the memory available
46# on the system and that the owner of the process is allowed to use this
47# limit.
48#
49# Elasticsearch performs poorly when the system is swapping the memory.
50#
51# ---------------------------------- Network -----------------------------------
52#
53# By default Elasticsearch is only accessible on localhost. Set a different
54# address here to expose this node on the network:
55#
56network.host: node87
57#
58# By default Elasticsearch listens for HTTP traffic on the first free port it
59# finds starting at 9200. Set a specific HTTP port here:
60#
61http.port: 9200
62# tcp端口
63transport.tcp.port: 9300
64#
65# For more information, consult the network module documentation.
66#
67# --------------------------------- Discovery ----------------------------------
68#
69# Pass an initial list of hosts to perform discovery when this node is started:
70# The default list of hosts is ["127.0.0.1", "[::1]"]
71# 配置两个重要的发现和集群形成设置,以便集群中的节点可以相互发现并选举一个主节点
72discovery.seed_hosts: ["node85:9300", "node86:9300","node87:9300"]
73#
74# Bootstrap the cluster using an initial set of master-eligible nodes:
75# 明确列出应在第一次选举中计算其选票的主合格节点
76cluster.initial_master_nodes: ["node85"]
77#
78# For more information, consult the discovery and cluster formation module documentation.
79#
80# ---------------------------------- Various -----------------------------------
81#
82# Require explicit names when deleting indices:
83#
84#action.destructive_requires_name: true
85
86##  7.15 没有个配置了
87#  node.data
88#  node.ingest
89#  node.master
90#  node.ml
91#  node.remote_cluster_client
92#  node.transform
93#  node.voting_only
94## 需要用 https://www.elastic.co/guide/en/elasticsearch/reference/7.15/modules-node.html#node-roles
95
96# # 跨域
97http.cors.enabled: true
98http.cors.allow-origin: "*"

5. 启动es集群

  • 此操作需要在各个节点上运行
1/home/top/es/elasticsearch-7.10.2/bin/elasticsearch -d -p /home/top/es/pid >/dev/null 2>&1 &

6. 检测是否启动完成集群

  • [top@localhost ~]$ curl -X GET 'http://10.168.2.85:9200/'
  • {
    "name": "node85",
    "cluster_name": "es-top",
    "cluster_uuid": "v7M5HemdSvmFjVPhEAlhig",
    "version": {
    "number": "7.10.2",
    "build_flavor": "default",
    "build_type": "tar",
    "build_hash": "93d5a7f6192e8a1a12e154a2b81bf6fa7309da0c",
    createTime: 2021-11-11T19:13:45+08:00
    updateTime: 2021-11-11T19:13:45+08:00
    "build_snapshot": false,
    "lucene_version": "8.9.0",
    "minimum_wire_compatibility_version": "6.8.0",
    "minimum_index_compatibility_version": "6.0.0-beta1"
    },
    "tagline": "You Know, for Search"
    }
    1. 其他

根据当前机器的大小修改分配给es的内存

  • 文件位置:vim /home/top/es/elasticsearch-7.10.2/config/jvm.options

-Xms1g =>修改成想要的内存数
-Xmx1g =>修改成想要的内存数