1. 需要的環境并安裝
apt-get update
apt-get install openjdk-8-jdk
java -version
2. 下載,安裝并配置elasticsearch
下載:上官網下載elasticsearch
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz
這個鏈接可以直接下載elasticsearch-7.3.2的安裝包
如果需要其他版本的安裝包
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
解壓包:
tar zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz
配置elasticsearch.yml
cd elasticsearch-7.3.2/config
vim elasticsearch.yml
如下:
# ---------------------------------- Cluster -----------------------------------
cluster.name: es-cluster
# ------------------------------------ Node ------------------------------------
node.name: node-1
# ----------------------------------- Paths ------------------------------------
path.data: /path/to/data
path.logs: /path/to/logs
# ----------------------------------- Memory -----------------------------------
bootstrap.memory_lock: false
# ---------------------------------- Network -----------------------------------
network.host: 0.0.0.0
http.port: 9200
# --------------------------------- Discovery ----------------------------------
discovery.seed_hosts: ["你的ip地址:9300", "你的ip地址:9301"]
cluster.initial_master_nodes: ["你的ip地址:9300", "你的ip地址:9301"]
# ---------------------------------- Gateway -----------------------------------
gateway.recover_after_nodes: 1
在檔案里修改,記得把前面的警號去掉,
cluster.name:集群的名字
node.name:配置當前節點的節點名字
path.data:索引資料的儲存路徑
path.logs:日志檔案的存盤路徑
bootstrap.memory_lock:應該是用來鎖記憶體的,這里應該是用true開啟的狀態,可我elasticsearch拉起來的時候總是會報錯,網上很多辦法試過了沒用所以我就關掉了,
network.host:這個引數是用來同時設定bind_host和publish_host這兩個引數的
http.port:設定對外的HTTP埠,默認時9200
discovery.seed_hosts:發現主機的初始串列
cluster.initial_master_nodes:首次啟動elasticsearch時需要投票誰才是主節點
gateway.recover_after_nodes:設定集群中N個節點啟動時進行資料回復,默認1
將elasticsearch-7.3.2改名為node1
并且復制node1名字為node2
mv elasticsearch-7.3.2 node1
cp -rf node1 node2
修改node2中的elasticsearch.yml檔案
# ---------------------------------- Cluster -----------------------------------
cluster.name: es-cluster
# ------------------------------------ Node ------------------------------------
node.name: node-2
# ----------------------------------- Paths ------------------------------------
path.data: /path/to/data1
path.logs: /path/to/logs1
# ----------------------------------- Memory -----------------------------------
bootstrap.memory_lock: false
# ---------------------------------- Network -----------------------------------
network.host: 0.0.0.0
http.port: 9201
transport.tcp.port: 9301
# --------------------------------- Discovery ----------------------------------
discovery.seed_hosts: ["你的ip地址:9300", "你的ip地址:9301"]
cluster.initial_master_nodes: ["你的ip地址:9300", "你的ip地址:9301"]
# ---------------------------------- Gateway -----------------------------------
gateway.recover_after_nodes: 1
mkdir /path/to/data1
mkdir /path/to/logs1
cp /path/to/logs/* /path/to/logs1
索引資料的存盤路徑和日志存盤路徑不改,第二個節點拉起來的時候會報錯
3.修改jvm.options
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms1g
-Xmx1g
Xms1g和Xmx1g是修改elasticsearch運行時的記憶體大小,這就是1g,有時候會有記憶體報錯,說明運行elasticsearch運行記憶體不夠,可以改為Xms256m和Xms256m
4.添加ES組和用戶并且將必要的檔案全部加到用戶和組里并且改權限
groupadd elasticsearch
useradd -m elasticsearch -g elasticsearch
passwd elasticsearch
chown -R elasticsearch:elasticsearch node1/
chown -R elasticsearch:elasticsearch node2/
cd /path/to/
chown -R elasticsearch:elasticsearch data
chown -R elasticsearch:elasticsearch data1
chown -R elasticsearch:elasticsearch log
chown -R elasticsearch:elasticsearch log1
5.運行elasticsearch
su elasticsearch
cd node1/
bin/elasticsearch
運行elasticsearch不能用root用戶,運行起來會報沒有找到node2,運行node2就好了,
su elasticsearch
cd node2/
bin/elasticsearch
運行成功,網頁輸入你的ip:9200,出現網頁
{
"name" : "node-1",
"cluster_name" : "es-cluster",
"cluster_uuid" : "pBMSuoUeQiOZFUDHig",
"version" : {
"number" : "7.3.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "1c1",
"build_date" : "2019-09-06T14:40:30.409026Z",
"build_snapshot" : false,
"lucene_version" : "8.1.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
然后用elasticsearch-head連接ES集群,
先開兩個session看能不能讓es正常運行,可以之后再用
bin/elasticsearch -d
后臺運行
6.排錯
首先要主意的是把防火墻關閉,防火墻影響埠訪問
ufw status
ufw disable
記憶體不夠
vim /etc/sysctl.conf
vm.max_map_count = 655360
執行:
sysctl -p
vim /etc/security/limits.conf
添加:
* soft nofile 65536
* hard nofile 65536
7.參考博客
https://www.cnblogs.com/lichmama/p/12364356.html
https://www.cnblogs.com/chenxi-mxj/p/12366407.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/232501.html
標籤:其他
