Centos7 中安裝Elasticsearch

1.下載安裝包

1.1 下載elasticsearch 7.13.3

curl -L -O //artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.3-linux-x86_64.tar.gz

1.2 解壓文件

tar -zxf elasticsearch-7.13.3-linux-x86_64.tar.gz

1.3 將解壓文件移動至所要存儲的文件目錄下

mv elasticsearch-7.13.3 /data/elasticsearch

2.創建普通用戶

為了安全問題,es不允許root用戶直接運行,新建用戶

2.1添加用戶

#添加用戶
adduser es
#添加密碼
passwd es
1234567890

2.2 將解壓後的es目錄給es用戶授權

chown -R es:es /data/elasticsearch

2.3 在es用戶下創建elasticsearch的數據和日誌目錄

mkdir elasticsearch
cd elasticsearch
mkdir  data
mkdir logs

3. 修改eleasticsearch.yml文件

3.1 進入到es的config目錄下

cd /data/elasticsearch/config/

3.2 修改yml文件

vi elasticsearch.yml

# 集群名
cluster.name: my-es
# 節點名
node.name: node-2
# 是否有資格主節點
node.master: true
# 是否存儲數據
node.data: true
# 最大集群節點數
node.max_local_storage_nodes: 5
# ip地址
network.host: 0.0.0.0
# es的httpo的埠
http.port: 9200
# 內部節點之間溝通埠
transport.tcp.port: 9700
# 節點發現
discovery.zen.ping.unicast.hosts: ["192.168.12.46:9700", "192.168.12.3:9700", "192.168.12.2:9700", "192.168.12.45:9700", "192.168.12.47:9700"]
# 初始化新的集群是需要此配置來選舉新的master
# cluster.initial_master_nodes: ["node-1","node-2","node-3","node-4","node-5"]
cluster.initial_master_nodes: node-1
# es保存數據及日誌的路徑
path.data: /home/es/elasticsearch/data
path.logs: /home/es/elasticsearch/logs

4. 修改配置文件

新創建的es用戶最大可創建的文件數太小,最大虛擬記憶體太小,切換到root用戶,進行一下配置

4.1 切換到root用戶 並 進行limits.conf文件配置

# 切換root用戶
su

# 配置最小文件數
vi /etc/security/limits.conf

# 文件末尾增加下面內容
es soft nofile 65535
es hard nofile 65537

4.2 進行20-文件配置

vi /etc/security/limits.d/20-nproc.conf

# 文件末尾增加下面內容,最多可創建的文件數
es soft nofile 65536
es hard nofile 65536

# * 代表Linux所有用戶名稱
* hard nproc 4096

4.3 進行sysctl.conf配置

vi /etc/sysctl.conf

# 文件末尾增加下面內容
vm.max_map_count=655360

# 保存文件後,重新載入,輸入命令
sysctl -p

5.設置ES的JVM佔用記憶體參數

啟動之前,設置ES的JVM佔用記憶體參數,防止記憶體不足錯誤

vi /data/elasticsearch/config/jvm.options
 
# 改為最小記憶體4g,最大記憶體4g
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## and the min and max should be set to the same value. For
## example, to set the heap to 4 GB, create a new file in the
## jvm.options.d directory containing these lines:
##
-Xms4g
-Xmx4g
##
## See //www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################