天天看點

elasticsearch及head插件安裝與配置1. 環境軟體版本說明2. 環境軟體下載下傳說明3. elasticsearch安裝4. elasticsearch-head插件安裝

1. 環境軟體版本說明

  • 系統:ubuntu14.04.1
  • JDK:1.8
  • elasticsearch:5.5.2
  • node:9.11.1
  • elasticsearch:5.X

2. 環境軟體下載下傳說明

1). 軟體位址

  • 系統:這個嘛。。。
  • JDK:非重點,請自行解決
  • elasticsearch:https://www.elastic.co/downloads/elasticsearch
  • elasticsearch-5.5.2:https://www.elastic.co/downloads/past-releases/elasticsearch-5-5-2
  • node:https://nodejs.org/dist/v9.11.1/node-v9.11.1-linux-x64.tar.xz
  • elasticsearch-head:https://github.com/mobz/elasticsearch-head/archive/master.zip

2). 軟體下載下傳

  • 下載下傳elasticsearch-5.5.2
# wget https://www.elastic.co/downloads/past-releases/elasticsearch-5-5-2
           
  • 下載下傳node

    `

# wget https://nodejs.org/dist/v9.11.1/node-v9.11.1-linux-x64.tar.xz
           
  • 下載下傳head插件
# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
           

3. elasticsearch安裝

elasticsearch解壓即能用,當然為了更友善的使用,還是要簡單配置一下。

1). 解壓

`

# tar -zxvf elasticsearch-5.5.2.tar.gz
           

2). 配置

# cd elasticsearch-5.5.2/config/
# vim elasticsearch.yml

network.host: 0.0.0.0
# 跨域通路設定
http.cors.enabled: true
http.cors.allow-origin: "*"
           

3). 配置elasticsearch啟動使用者

在啟動elasticsearch之前還要建立一個非root使用者,elasticsearch不允許使用root使用者啟動。當使用非root使用者時,要配置一下使用者的檔案打開數和使用者最大處理數。

會出現如下錯誤:

ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
           
ERROR: bootstrap checks failed max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
           

解決centos系統執行一下如下腳本

#!/bin/bash
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
echo "* soft memlock unlimited" >> /etc/security/limits.conf
echo "* hard memlock unlimited" >> /etc/security/limits.conf
echo "vm.max_map_count = 262144" >> /etc/sysctl.conf
echo "* soft nproc 4096" >> /etc/security/limits.d/90-nproc.conf
echo "root soft nproc unlimited" >> /etc/security/limits.d/90-nproc.conf
sysctl -p
ulimit -l unlimited
           

解決ubuntu系統

(1). 在 /etc/security/limits.conf 中添加

* hard nofile 2037581
* soft nofile 2037581
root hard nofile 2037581
root soft nofile 2037581
           

(2). 在 /etc/pam.d/su 添加

session required pam_limits.so
           

(3)在 /etc/pam.d/common-session 添加

session required pam_limits.so
           

(4). 在 /etc/sysctl.conf 中添加

vm.max_map_count = 262144
           

4). 啟動

  • 前台啟動
# bin/elasticsearch
           
  • 背景啟動
# bin/elasticsearch -d
           
  • 方式 一檢視端口是否啟動
# lsof -i:9200
COMMAND   PID  USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    24738 kevin  117u  IPv4 32165101      0t0  TCP *:wap-wsp (LISTEN)
           
  • 方式二用curl

    傳回如下資訊說明啟動功能。

# curl localhost:9200
{
  "name" : "kevin-node-01",
  "cluster_name" : "kevin-dev",
  "cluster_uuid" : "Sq62mKiaQiGGYOQR-Dmq6Q",
  "version" : {
    "number" : "6.2.4",
    "build_hash" : "ccec39f",
    "build_date" : "2018-04-12T20:37:28.497551Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
           

4. elasticsearch-head插件安裝

elasticsearch依賴node環境,是以要想安裝head插件就要先安裝node環境。

1). node環境安裝

* 解壓

先把tar.xz解壓出tar.gz,然後再解壓tar.gz檔案

# tar -xvf node-v9.11.1-linux-x64.tar.xz
# tar -zxvf node-v9.11.1-linux-x64.tar.gz
           

設定軟連接配接

# ln -s /opt/node-v9.11.1/bin/npm /usr/local/bin/ 
# ln -s /opt/node-v9.11.1/bin/node /usr/local/bin/
           

檢測是否安裝成功,如果不成功重新開啟一個session對話再試一下。

# node -v
# npm -v
           

2). head安裝

* 解壓

# unzip master.zip
           

配置

  • vim Gruntfile.js

    添加 hostname: '0.0.0.0'

90                 connect: {
 91                         server: {
 92                                 options: {
 93                                         port: 9100,
 94                                         base: '.',
 95                                         keepalive: true,
 96                                         hostname:'0.0.0.0'
 97                                 }       
           

安裝

進入到node的根目錄下

# cd /opt/elasticsearch-head-master/
npm install
           

我的報如下錯誤

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-08-04T02_49_32_733Z-debug.log
[email protected]:/opt/elasticsearch-head-master# 
[email protected]:/opt/elasticsearch-head-master# 
[email protected]:/opt/elasticsearch-head-master# 
[email protected]:/opt/elasticsearch-head-master# npm install [email protected]

npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected]
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-08-04T02_51_00_390Z-debug.log
           

解決:把不能安裝的script路過去,要注意你報錯資訊中@背景的版本号

npm install [email protected] --ignore-scripts
           

啟動head

  • 啟動
npm run start
           
  • 然後就可以通路head插件了,head插件的端口預設是9100。
    elasticsearch及head插件安裝與配置1. 環境軟體版本說明2. 環境軟體下載下傳說明3. elasticsearch安裝4. elasticsearch-head插件安裝
  • 如果head不能識别es的位址,就去head中配置一下es的位址資訊。
    elasticsearch及head插件安裝與配置1. 環境軟體版本說明2. 環境軟體下載下傳說明3. elasticsearch安裝4. elasticsearch-head插件安裝

vim _site/app.js 把4354行的localhost改ip位址即可。

4342 (function( app, i18n ) {
4343 
4344         var ui = app.ns("ui");
4345         var services = app.ns("services");
4346 
4347         app.App = ui.AbstractWidget.extend({
4348                 defaults: {
4349                         base_uri: null
4350                 },
4351                 init: function(parent) {
4352                         this._super();
4353                         this.prefs = services.Preferences.instance();
4354                         this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.161.103:9200";
4355                         if( this.base_uri.charAt( this.base_uri.length - 1 ) !== "/" ) {
4356                                 // XHR request fails if the URL is not ending with a "/"
4357                                 this.base_uri += "/";
4358                         }
4359                         if( this.config.auth_user ) {
4360                                 var credentials = window.btoa( this.config.auth_user + ":" + this.config.auth_password );
4361                                 $.ajaxSetup({
4362                                         headers: {
4363                                                 "Authorization": "Basic " + credentials
4364                                         }
4365                                 });
4366                         }
4367                         this.cluster = new services.Cluster({ base_uri: this.base_uri });
           

轉載于:https://www.cnblogs.com/chaos-x/p/9446250.html

繼續閱讀