Ubuntu 16.04.2 安装 elasticsearch 6.2.4

words: 1.1k    views:    time: 5min

ubuntu版本:16.04.2
elasticsearch版本:6.2.4

1. 安装elasticsearch

创建用户及目录

1
2
3
mkdir -p /usr/local/kencery/elasticsearch
groupadd elasticsearch
useradd -d /usr/local/kencery/elasticsearch -g elasticsearch -p elasticsearch elasticsearch

解压包到elasticsearch目录下,这里下载的是elasticsearch-6.2.4.tar.gz,然后直接在bin目录下执行:./elasticsearch

有两个问题注意下,一是不要用root用户执行,二是有可能会遇到错误:

1
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

这个修改下/etc/sysctl.conf,添加下面配置,然后 sysctl -p

1
vm.max_map_count=655360

另外记得改下elasticsearch.yml中的network.host以及端口配置,重启后就可以访问了:http://192.168.141.13:9200/

2. 安装elasticsearch-head

elasticsearch 5.x之后不支持直接plugin安装head插件,而是将head作为一个独立的服务安装的

1.首先需要安装依赖的node,npm,grunt

1
2
3
4
apt-get install npm
apt-get install nodejs-legacy
npm install -g grunt
npm install -g grunt-cli

下载elasticsearch-head,我解压到目录/usr/local/kencery/elasticsearch-head,将目录用户改为elasticsearch

2.然后修改配置

2.1. 修改head的连接地址: elasticsearch-head/_site/app.js,将localhost改为自己的ip

1
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";

2.2. 修改服务器的监听地址: elasticsearch-head/Gruntfile.js, 在options中添加 hostname: ‘*’

1
2
3
4
5
6
7
8
9
connect: {  
server: {
options: {
port: 9100,
base: '.',
keepalive: true
}
}
}

2.3. 修改elasticseach的配置文件elasticsearch.yml, 修改对应的ip以及跨域的设置,添加:

1
2
http.cors.enabled: true 
http.cors.allow-origin: "*"

3.在elasticsearch-head下运行: grunt server

3.1. 但是会出现错误(当时命令敲的npm start,一样的)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
root@ubuntu:/usr/local/kencery/elasticsearch-head# npm start

> elasticsearch-head@0.0.0 start /usr/local/kencery/elasticsearch-head
> grunt server

grunt-cli: The grunt command line interface (v1.2.0)

Fatal error: Unable to find local grunt.

If you're seeing this message, grunt hasn't been installed locally to
your project. For more information about installing and configuring grunt,
please see the Getting Started guide:

http://gruntjs.com/getting-started

npm ERR! Linux 4.4.0-62-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! elasticsearch-head@0.0.0 start: `grunt server`
npm ERR! Exit status 99
npm ERR!
npm ERR! Failed at the elasticsearch-head@0.0.0 start script 'grunt server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the elasticsearch-head package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! grunt server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs elasticsearch-head
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls elasticsearch-head
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /usr/local/kencery/elasticsearch-head/npm-debug.log

提示大概是版本不是最新的问题,所以就抱着试一试的心态去升级npm以及node

1
2
3
4
npm cache clean -f
npm install -g n
n stable
npm install npm@latest -g

然后再查看下版本:

1
2
3
4
elasticsearch@ubuntu:~$ node -v
v10.4.0
elasticsearch@ubuntu:~$ npm -v
6.1.0

3.2. 但是运行grunt server依然报错:

1
grunt hasn't been installed locally to your project

参考https://segmentfault.com/q/1010000004172559/a-1020000004193932 安装:

1
npm install grunt --save-dev

3.3 再次运行,依然报错:

1
2
3
4
5
6
7
8
elasticsearch@ubuntu:/usr/local/kencery/elasticsearch-head$ grunt server
>> Local Npm module "grunt-contrib-clean" not found. Is it installed?
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-watch" not found. Is it installed?
>> Local Npm module "grunt-contrib-connect" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
Warning: Task "connect:server" not found. Use --force to continue.

然后干脆把有关grunt的都装了一遍最新的:

1
2
3
4
5
6
7
8
9
npm install grunt@latest
npm install grunt-cli@latest
npm install grunt-contrib-copy@latest
npm install grunt-contrib-concat@latest
npm install grunt-contrib-uglify@latest
npm install grunt-contrib-clean@latest
npm install grunt-contrib-watch@latest
npm install grunt-contrib-connect@latest
npm install grunt-contrib-jasmine@latest

3.4. 最后grunt server可以启动了

1
2
3
4
5
elasticsearch@ubuntu:/usr/local/kencery/elasticsearch-head$ grunt server
(node:1527) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

可以看到elasticsearch服务的端口是9200,head插件服务的端口是9100,我们访问head然后head再访问的elasticsearch。可以新建索引:


参考:

  1. http://www.cnblogs.com/hanyinglong/p/5409003.html
  2. https://blog.csdn.net/jiankunking/article/details/65448030
  3. https://blog.csdn.net/hard_boy/article/details/79565068
  4. https://www.cnblogs.com/ae6623/p/6242423.html
  5. https://segmentfault.com/q/1010000004172559/a-1020000004193932