Linux安裝Elasticsearch及head插件

提示:本人使用的系統:Centos7。在此之前,請確保安裝了JDK,由於安裝過於簡單,這裏不介紹了。

安裝Elasticsearch

【Elasticsearch7.2百度雲,本人使用的版本】
【官網下載】

1.解壓
tar -zxvf /usr/local/elasticsearch.tar.gz

2.修改配置文件(默認全部註釋,將下面複製粘貼在末尾即可)
vi /usr/local/elasticsearch-7.2.0/config/elasticsearch.yml

cluster.name: es_cluster
# 確保在不同環境中集羣的名稱不重複:
node.name: node-1
# 綁定的網卡IP:
network.host: 192.168.114.120
# http協議端口:
http.port: 9200
# 是否爲主節點
node.master: true
# 初始主節點
cluster.initial_master_nodes: ["node-1"]
# 開始發現新節點的IP地址
discovery.zen.ping.unicast.hosts: ["192.168.114.120"]
# 支持跨域
http.cors.enabled: true
http.cors.allow-origin: "*"

3.修改limits.conf
vi /etc/security/limits.conf 追加如下內容

 * soft nofile 65536
 * hard nofile 131072
 * soft nproc 2048
 * hard nproc 4096

注意:如果有想測試的話,在修改limits.conf文件之後,對於非root角色需要重新切換角色才能生效。

否則將出錯
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3795] for user [elasticsearch] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

4.修改sysctl.conf
方式一.永久生效
vi /etc/sysctl.conf 追加如下內容

vm.max_map_count=262144

輸入命令 sysctl -p 使修改生效
方式二.臨時生效
sysctl -w vm.max_map_count=262144

否則將出錯
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

5.由於elasticsearch不能以root用戶運行,所以這裏創建一個用戶elasticsearch(隨意)
adduser elasticsearch
passwd elasticsearch
chown -R elasticsearch:elasticsearch /usr/local/elasticsearch-7.2.0/
su elasticsearch

如果以root用戶運行將拋出以下異常
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

6.啓動(systemctl stop firewalld臨時關閉防火牆)
cd /usr/local/elasticsearch-7.2.0/bin/
./elasticsearch (也可使用./elasticsearch -d在後臺運行)
在這裏插入圖片描述
輸入 http://192.168.114.120:9200/
在這裏插入圖片描述

安裝head插件

一.安裝Node.js

【官網下載地址】

1.解壓
tar -xvf node-v10.16.3-linux-x64.tar.xz
2.改名
mv /usr/local/node-v10.16.3-linux-x64 /usr/local/nodejs
3.創建軟連接
ln -s /usr/local/nodejs/bin/node /usr/bin/
ln -s /usr/local/nodejs/bin/npm /usr/bin/
4.測試
node -v
npm  -v
二.安裝phantomjs

【官網下載(極慢)】
【推薦下載地址(個人版本2.1.1)】

1.安裝bzip2
yum install -y bzip2
2.解壓
tar -xvf phantomjs-2.1.1-linux-x86_64\ .tar.bz2
3.改名
mv phantomjs-2.1.1-linux-x86_64 phantomjs
4.建立軟連接
ln -s /usr/local/phantomjs/bin/phantomjs /usr/bin/
5.安裝fontconfig
yum install -y fontconfig
6.測試
phantomjs --version
三.安裝head插件

【Github下載地址】

1.安裝unzip
yum install -y unzip
2.解壓
unzip elasticsearch-head-master.zip
3.進入目錄
cd elasticsearch-head-master
4.執行命令
npm install cnpm -g --registry=https://registry.npm.taobao.org

5.修改Gruntfile.js
vi Gruntfile.js(添加hostname: ‘*’,)
在這裏插入圖片描述
6.跳轉elasticsearch-head-master/_site目錄
cd _site
7.修改app.js
vi app.js
在這裏插入圖片描述
8.安裝grunt

npm install -g grunt-cli --registry=http://registry.cnpmjs.org
npm install grunt -save-dev --registry=http://registry.cnpmjs.org
npm install grunt-contrib-clean --registry=https://registry.npm.taobao.org
npm install grunt-contrib-concat --registry=https://registry.npm.taobao.org
npm install grunt-contrib-watch --registry=https://registry.npm.taobao.org
npm install grunt-contrib-connect --registry=https://registry.npm.taobao.org
npm install grunt-contrib-copy --registry=https://registry.npm.taobao.org
npm install grunt-contrib-jasmine --registry=https://registry.npm.taobao.org

9.啓動
npm run start
10.測試
輸入 http://192.168.114.120:9100/
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章