1 安装java环境
由于es 需要java环境,jdk的安装以及java环境配置如下:
jdk 安装:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
更新java 包:
sudo apt-get install oracle-java8-set-default
配置java环境变量:
在配置文件/etc/environment中添加如下配置:
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
验证:
java -version
输出:
han@ubuntu:~$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
2、安装es
下载并解压安装包:
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.tar.gz
tar -xvf elasticsearch-5.2.2.tar.gz
开启远程访问,修改配置文件 config/elasticsearch.yml
network.host: 0.0.0.0
进入到bin目录启动es:
cd elasticsearch-5.2.2/bin
./elasticsearch
输出如下:
han@ubuntu:~/es/elasticsearch-5.2.2/bin$ ./elasticsearch
[2017-03-22T06:56:26,934][INFO ][o.e.n.Node ] [] initializing ...
[2017-03-22T06:56:27,185][INFO ][o.e.e.NodeEnvironment ] [JhuAdHb] using [1] data paths, mounts [[/ (/dev/sda1)]], net usable_space [4.2gb], net total_space [9gb], spins? [possibly], types [ext4]
[2017-03-22T06:56:27,190][INFO ][o.e.e.NodeEnvironment ] [JhuAdHb] heap size [123.7mb], compressed ordinary object pointers [true]
[2017-03-22T06:56:27,199][INFO ][o.e.n.Node ] node name [JhuAdHb] derived from node ID [JhuAdHbCR06e_9PpTj8gyQ]; set [node.name] to override
[2017-03-22T06:56:27,213][INFO ][o.e.n.Node ] version[5.2.2], pid[7940], build[f9d9b74/2017-02-24T17:26:45.835Z], OS[Linux/4.4.0-31-generic/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_121/25.121-b13]
[2017-03-22T06:56:29,650][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [aggs-matrix-stats]
[2017-03-22T06:56:29,651][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [ingest-common]
[2017-03-22T06:56:29,652][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [lang-expression]
[2017-03-22T06:56:29,652][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [lang-groovy]
[2017-03-22T06:56:29,653][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [lang-mustache]
[2017-03-22T06:56:29,653][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [lang-painless]
[2017-03-22T06:56:29,653][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [percolator]
[2017-03-22T06:56:29,657][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [reindex]
[2017-03-22T06:56:29,657][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [transport-netty3]
[2017-03-22T06:56:29,658][INFO ][o.e.p.PluginsService ] [JhuAdHb] loaded module [transport-netty4]
[2017-03-22T06:56:29,665][INFO ][o.e.p.PluginsService ] [JhuAdHb] no plugins loaded
[2017-03-22T06:56:36,781][INFO ][o.e.n.Node ] initialized
[2017-03-22T06:56:36,782][INFO ][o.e.n.Node ] [JhuAdHb] starting ...
注意:
在启动过程中遇到了如下错误:
Java HotSpot(TM) Client VM warning: INFO: os::commit_memory(0x74800000, 201326592, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 201326592 bytes for committing reserved memory.
在修改了./config/jvm.options文件里的内存配置后启动成功
将-Xms2g -Xmx2g 修改为 -Xms128m -Xmx128m
在文件elasticsearch.yml中添加配置如下:
避免出现跨域问题
http.cors.enabled: true
http.cors.allow-origin: "*"
3、安装es插件head
运行命令:
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
sudo npm install
sudo npm run start
sudo npm install -g grunt-cli
sudo npm install grunt --save-dev
修改配置
修改elasticsearch-head下Gruntfile.js文件,默认监听在127.0.0.1下9200端口
启动服务:
sudo grunt server
通过浏览器访问如下: