Linux下搭建Elasticsearch7.6.2集群


使用VMvare創建虛擬機

我的創建的三台分別是:
  192.168.115.129 node-1   192.168.115.130 node-2   192.168.115.131 node-3

注意:克隆虛擬機的時候需要修改linux的ip策略為static,否則會導致ip一直在變

1:使用ifconfig命令查看我們Windows的網關

 2:編輯虛擬機的ip ,這里只給出一份。其他兩個虛擬機在克隆之后修改即可。

vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
IPADDR=192.168.115.130 # 這里自定義ip,192.168不能變
GATEWAY=192.168.3.1  # 這里是前面Windows查到的網關地址
NAME=ens33
UUID=51ee4604-9cf3-40c9-9d7d-cc10e9eb513e
DEVICE=ens33
ONBOOT=yes

3.下載es安裝包

https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz

創建存放目錄,然后使用工具上傳

mkdir /usr/local/es/

4.解壓

tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz

5. 修改配置文件  

cd ./config
vi elasticsearch.yml 

這里給出node1的配置文件

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-elasticsearch
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
# 表示該節點會不會作為主節點,true表示會;false表示不會
node.master: true
# 當前節點是否用於存儲數據,是:true、否:false
node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/es/elasticsearch-7.6.2/data
#
# Path to log files:
#
path.logs: /usr/local/es/elasticsearch-7.6.2/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.115.129
#
# Set a custom port for HTTP:
#
http.port: 9200
transport.tcp.port: 9300
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# 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]"]
#
# es7.x 之后新增的配置,寫入候選主節點的設備地址,在開啟服務后可以被選為主節點
discovery.seed_hosts: ["192.168.115.129","192.168.115.130","192.168.115.131"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
discovery.zen.minimum_master_nodes: 2
# 判斷結點是否脫離時間配置
discovery.zen.fd.ping_timeout: 60s
# 判斷結點是否脫離次數配置
discovery.zen.fd.ping_retries: 5
# es7.x 之后新增的配置,初始化一個新的集群時需要此配置來選舉master
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
# 表示開啟蛞蝓訪問支持,此值默認為fals
http.cors.enabled: true
# 表示跨域訪問允許的域名地址,可使用正則表達式,“*”則表示允許所有域名訪問
http.cors.allow-origin: "*"

6. jdk配置,es7.6.2需要依賴jdk11,不過7.0之后es自帶jdk,如果我們自己安裝的jdk,則會優先使用我們安裝的,使用自帶的話則需要修改配置。

具體修改可以參考該博客:
https://blog.csdn.net/xiaoxiong_web/article/details/105597150

7.創建普通用戶

  es無法使用root用戶啟動,所以我們需要創建一個用戶用於es的啟動

創建用戶組   groupadd esgroup
創建用戶     useradd -g esgroup es
設置權限     chown -R es:esgroup /usr/local/es/
設置密碼     passwd es

8.修改linux內核參數

  需要修改Linux文件打開最大數,否則啟動會報錯

修改/etc/security/limits.conf 增加下面內容
* soft nproc 65535* hard nproc 65535* soft nofile 65535* hard nofile 131072

修改/etc/sysctl.conf 增加內容: vm.max_map_count=655360
然后執行命令,使配置生效: sysctl
-p

9.關閉防火牆

systemctl disable firewalld

 

完成以上步驟之后,開始克隆虛擬機(克隆完整鏡像)

1)克隆完成之后,修改虛擬機的ip(上面有提到)

2)修改es的配置文件 elasticsearch.yml

其他兩個節點只需修改node.name和host

node.name: node-2
twork.host: 192.168.115.130
node.name: node-3
twork.host: 192.168.115.131

到這里就大功告成了,切換到 es的 bin目錄,啟動

cd bin/
切換到之前創建的普通用戶
su es
啟動
./elasticsearch

 

注意:我遇到一個很坑的問題,因為我先啟動一個節點的elasticsearch,然后再拷貝虛擬機去搭建集群,導致后面雖然配置文件沒問題,但是三個節點獨立存在,沒有形成集群,一直以為是配置出了問題,到時候才知道需要刪掉

es的data目錄下的數據,否則不會更新節點信息。

 


免責聲明!

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



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