ElasticSearch集群部署【windows+Linux双系统搭建】
ES集群部署
- 一、windows部署
- 二、Linux單節點部署
- 三、Linux集群部署
一、windows部署
如果已經使用過,刪除其中的data和logs文件夾中的內容
新建一個es-cluster文件夾,用于存放集群中的三個ES結點
1.結點1(master)配置
首先打開node-1文件夾->config目錄下-》bin目錄下的elasticsearch.yml文件
2.改變以下內容
不要在配置文件中加入中文注釋,啟動會失敗
# ======================== 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-application //集群名 # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: node-1 //結點名 node.master: true //既做為master node.data: true //也做為data # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # #path.data: /path/to/data # # Path to log files: # #path.logs: /path/to/logs # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # 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: localhost //ip地址,我在本地搭建 # # Set a custom port for HTTP: # http.port: 9200 //ES啟動端口 transport.tcp.port: 9201 //通信端口,因為各個結點之間要進行通信 # # 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]"] # #discovery.seed_hosts: ["host1", "host2"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # #cluster.initial_master_nodes: ["node-1", "node-2"] # # 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 http.cors.enabled: true //跨域設置 http.cors.allow-origin: "*"2.結點2配置
打開node-2文件夾-》conf-》elasticsearch.yml文件
# ======================== 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-application //集群名要一致 # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: node-2 //結點名不一致 node.master: true node.data: true # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # #path.data: /path/to/data # # Path to log files: # #path.logs: /path/to/logs # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # 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: localhost # # Set a custom port for HTTP: # http.port: 9300 transport.tcp.port: 9301 discovery.seed_hosts: ["localhost:9201"] //這是為了發現其他結點 discovery.zen.fd.ping_timeout: 1m //9201代表了master(node-1)的通信端口 discovery.zen.fd.ping_retries: 5 # # 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]"] # #discovery.seed_hosts: ["host1", "host2"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # #cluster.initial_master_nodes: ["node-1", "node-2"] # # 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 http.cors.enabled: true http.cors.allow-origin: "*"3.結點3配置
# ======================== 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-application # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: node-3 node.master: true node.data: true # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # #path.data: /path/to/data # # Path to log files: # #path.logs: /path/to/logs # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # 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: localhost # # Set a custom port for HTTP: # http.port: 9400 transport.tcp.port: 9401 discovery.seed_hosts: ["localhost:9201","localhost:9301"] //發現結點1和結點2(9201是node-1的通信端口,9301是node-2的通信端口 discovery.zen.fd.ping_timeout: 1m discovery.zen.fd.ping_retries: 5 # # 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]"] # #discovery.seed_hosts: ["host1", "host2"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # #cluster.initial_master_nodes: ["node-1", "node-2"] # # 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 http.cors.enabled: true http.cors.allow-origin: "*"4.使用postman進行測試
依次啟動node-1,node-2,node-3
二、Linux單節點部署
(1)cd到/usr/local目錄下,新建es文件夾,cd到es文件夾下
cd /usr/local/
mkdir es
cd es
(2)下載ElasticSearch
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.1-linux-x86_64.tar.gz
ES下載教程:https://blog.csdn.net/Kevinnsm/article/details/120604537?spm=1001.2014.3001.5501
(3)解壓縮
tar -zxvf elasticsearch-7.10.1-linux-x86_64.tar.gz
(4)改變文件名為es
mv elasticsearch-7.10.1 es
(5)🌞新建ES用戶
📜Linux環境下ElasticSearch不能以root用戶啟動,所以需要新建用戶
🧊創建用戶名為es的用戶,輸入useradd es
🧊為es用戶設置密碼,passwd es(密碼要滿足大于8位且含有大小寫字母已經數字,否者會匹配失敗)
(6)🌞修改文件目錄的所有者
chown:表示修改文件的所有者和所屬組
chown [-R] 所有者:所屬組 文件或目錄
chown -R es:es /usr/local/es/es
(7)🌞修改elasticsearch.yml文件內容
在文件末尾加入以下內容
cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: [“node-1”]
(8)🌞修改 /etc/security/limits.conf中的內容
由于es生成得內容比較多,所以需要修改相關配置
在文件末尾加入
es soft nofile 65535
es hard nofile 65535
加粗樣式(9)🌞修改20-nproc.conf文件
vim /etc/security/limits.d/20-nproc.conf
(10)🌞修改/etc/sysctl.conf文件
vim /etc/sysctl.conf
在文件底部加入vm.max_map_count = 655360
重新加載
sysctl -p
(11)🌞切換到es用戶下,啟動ElasticSearch
啟動腳本在bin目錄下
在es用戶下啟動報錯是因為ElasticSearch在第一次啟動過程中,會動態的生成一些文件,因為是剛生成的,所以es用戶沒有相應權限。則需要再次設置文件所有權
1.切換到root用戶下(在es用戶下是無法改變文件所有權的)
2.執行chown -R es:es /usr/local/es/es/
(12)🌞再次切換到es目錄,啟動即可
(13)🌞訪問ip:9200即可
如果是云服務器需要開放9200端口
三、Linux集群部署
持續更新中…
總結
以上是生活随笔為你收集整理的ElasticSearch集群部署【windows+Linux双系统搭建】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下安装部署ElasticSea
- 下一篇: 【虚拟化】Linux中安装配置Docke