linux版本:centos7
一,ES 目錄介紹
- bin:可執行文件在裏面,運行es的命令就在這個裏面,包含了一些腳本文件等
- config:配置文件目錄
- JDK:java環境
- lib:依賴的jar,類庫
- logs:日誌文件
- modules:es相關的模塊
- plugins:可以自己開發的插件
- data:這個目錄沒有,自己新建一下,後面要用 -> mkdir data,這個作爲索引目錄
二,es核心配置文件
▽
# ======================== 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
#
# 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: /usr/local/elasticsearch-7.4.2/data
#
# Path to log files:
#
#path.logs: /usr/local/elasticsearch-7.4.2/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: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# 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"]
#
# 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
三,es的啓動與關閉
停止es
如果是前臺啓動,直接ctrl+c就可以停止
後臺啓動:
./elasticsearch -d
停止殺進程:
//查看端口號
jps
//殺端口號
kill 端口號
啓動es
進入到es的安裝路徑下的bin下面
./elasticsearch
四,安裝步驟:
-
將文件上傳的服務器上
-
解壓縮文件
tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz
-
將解壓後的文件夾移動到local下好管理
mv elasticsearch-7.4.2 /usr/local
-
進入到local文件夾下
cd /usr/local
-
修改核心配置文件
-
修改集羣名稱,默認是elasticsearch,雖然目前是單機,但是也會有默認的
-
爲當前的es節點取個名稱,名稱隨意,如果在集羣環境中,都要有相應的名字
-
修改data數據保存地址
-
修改日誌數據保存地址
-
綁定es網絡ip,原理同redis默認端口號,可以自定義修改(0.0.0.0代表所有ip都可以訪問)
-
集羣節點,名字可以先改成之前的那個節點名稱
-
-
添加用戶 ES不允許使用root操作es,需要添加用戶,操作如下:
useradd esuser
chown -R esuser:esuser /usr/local/elasticsearch-7.4.2
su esuser
whoami
- 進入到/bin目錄下,啓動es
./elasticsearch
- 啓動成功後訪問
IP:9200
注意:如果啓動失敗請往下看!!!
五,啓動失敗原因與解決辦法
1. 用的虛擬機或服務啓的內存太小,導致啓動失敗
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
解決辦法:
注:如果你的安裝步驟和我一樣,那麼這個配置文件就在這個目錄下面,如果不一樣,請到你自己的es安裝目錄下修改這個配置文件
vim /usr/.local/elasticsearch-7.4.2/config/jvm.options
- 默認jvm的大小是1G,可以改成128m
2. vm.max_map_count設置過小報錯
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決辦法:
-
修改配置文件
vim /etc/sysctl.conf
-
在配置文件中添加
vm.max_map_count=262145
-
sysctl -p
刷新一下
3. 用root用戶啓動es
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
解決辦法:新建一個用戶,切換到新建用戶下啓動
useradd esuser
chown -R esuser:esuser /usr/local/elasticsearch-7.4.2
su esuser
whoami
4.配置文件設置太小
解決辦法:
- 修改配置文件
vim /etc/security/limits.conf
- 在配置文件最後添加
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
5.啓動沒有異常,但是頁面進不去
解決辦法:雲服務器記得添加安全組配置,虛擬機把防火牆關掉