1. 程式人生 > 其它 >阿里雲centos7.4安裝ElasticSearch7.8

阿里雲centos7.4安裝ElasticSearch7.8

技術標籤:elasticsearchelasticsearch

阿里雲centos7.4安裝ElasticSearch7.8

資源準備:

華為映象下載地址,選擇對應的版本下載,注意:elasticsearch、logstatic、kibana、ik分詞器三者版本需要保持一致。

ElasticSearch: https://mirrors.huaweicloud.com/elasticsearch/?C=N&O=D

Logstash: https://mirrors.huaweicloud.com/logstash/?C=N&O=D

Kibana: https://mirrors.huaweicloud.com/kibana/?C=N&O=D

IK分詞器:https://github.com/medcl/elasticsearch-analysis-ik/releases

ElasticSearch-head:https://github.com/mobz/elasticsearch-head

1、軟體準備(均為Linux安裝包)

(1)jdk(選擇系統版本對應的安裝包)

地址:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

(2)ElasticSearch7.8(選擇系統版本對應的安裝包)

地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch

2、安裝jdk

# 1.進入指定資料夾新建Java目錄將檔案上傳到該目錄下進行解壓
cd /usr/local
mkdir java
tar -zxvf jdk安裝包名稱

# 2.配置Linux系統環境變數
vim /etc/profile

# 3.檔案末尾新增
export JAVA_HOME=/usr/java/jdk解壓檔名稱
export PATH=$PATH:$JAVA_HOME/bin

# 4.過載系統配置,使其生效
source /ect/profile

# 5.檢視是否配置成功
java -version

3、安裝elasticsearch

介紹:由於elasticsearch啟動不能以root賬號進行啟動,所以需要新建一個使用者給其檔案操作許可權啟動

安裝準備:

# 1.上傳安裝包到jdk同樣目錄下解壓
 cd /usr/local/java

# 2.解壓
tar -zxvf es安裝包名稱

# 3.新建一個es使用者組使用者
groupadd esgroup
useradd esuser01 -g esgroup
passed esuser01
前後輸入兩次密碼即可

# 4.root賬戶給新建的es使用者新增elasticsearch操作許可權
chown esuser01 /usr/local/java/elasticsearch-7.8.0 -R

# 5.切換到es組使用者
su esuser01

開始安裝:

1.修改es JVM引數(可選操作,如果當前機器記憶體不夠可設定)
vim /usr/local/java/elasticsearch/elasticsearch-7.8.0/config/jvm.options
-Xms512m
-Xmx512m
2.修改elasticsearch.yml 配置

# 開啟遠端連線許可權
network.host: 0.0.0.0

報錯: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=655360

# 執行如下命令檢測是否生效
sysctl -p

報錯:the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

解決方法:

修改elasticsearch.yml 配置

# 當前節點名稱
node.name: node-1

# 叢集初始化地址
cluster.initial_master_nodes: ["node-1"]

其他報錯:

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

vim /etc/security/limits.conf	 在最後面追加下面內容
	*               soft    nofile          65536
	*               hard    nofile          65536
	*               soft    nproc           4096
	*               hard    nproc           4096

登入重新在檢測配置是否生效
ulimit -Hn
ulimit -Sn
ulimit -Hu
ulimit -Su


[2]: max number of threads [3802] for user [es] is too low, increase to at least [4096]

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

將之前的*替換為你新建的esuser01

4、啟動

進入elasticsearch/bin目錄下執行其下一條命令即可

# 前臺方式啟動,視窗關閉,elasticsearch立即關閉
./elasticsearch

#後臺方式啟動,視窗關閉,es不關閉
./elasticsearch -d

5、記得開啟阿里雲當前伺服器的安全組規則

開啟9200和9300埠

9200:頁面瀏覽器,kibana,elasticsearch-head-master連線

9300:java程式連線埠

6、測試

# 當前機器
curl localhost:9200/

# 外網訪問
公網ip:9200/

7、安裝head外掛

1. 訪問github網站
	搜尋: elasticsearch-head 外掛
	
2. 安裝git
	yum install git
	
3. 將elasticsearch-head下載到本地
	git clone git://github.com/mobz/elasticsearch-head.git

4. 安裝nodejs
	#注意: 沒有wget的請先安裝yum install -y wget
	wget http://cdn.npm.taobao.org/dist/node/latest-v8.x/node-v8.1.2-linux-x64.tar.xz

5. 解壓縮nodejs
	xz -d node-v10.15.3-linux-arm64.tar.xz
	tar -xvf node-v10.15.3-linux-arm64.tar

6. 配置環境變數
	mv node-v10.15.3-linux-arm64 nodejs
	mv nodejs /usr/nodejs
	vim /etc/profile
		export NODE_HOME=/usr/nodejs
		export PATH=$PATH:$JAVA_HOME/bin:$NODE_HOME/bin
	source /etc/profile
7.	進入elasticsearch-head的目錄
	npm config set registry https://registry.npm.taobao.org
	npm install
	npm run start

8.  編寫elastsearch.yml配置檔案開啟head外掛的訪問
	http.cors.enabled: true
	http.cors.allow-origin: "*"

9.  啟動訪問head外掛 預設埠9100
	http://ip:9100  檢視叢集狀態