0. 操作系统:CentOS release 5.6 i686 athlon i386 GNU/Linux
1. 安装 java jdk1.8 (参考:Centos 6.5 安装java及设置默认jdk版本)
2. 下载安装包:elasticsearch-5.0.0.tar.zip
注:此为虚拟机测试,以下系统资源配置会较低。
解压文件
# tar zxvf elasticsearch-5.0.0.tar.gz
# mv elasticsearch-5.0.0 /usr/local/elasticsearch
# mkdir -p /usr/local/elasticsearch/{data,logs}
配置 es 参数文件 (Important Elasticsearch configuration)
# vi /usr/local/elasticsearch/config/elasticsearch.yml
# 注意冒号后有空格
http.port: 9200
node.name: node-1
cluster.name: es_cluster
network.host: 192.168.1.222
bootstrap.memory_lock: false
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs
配置足够内存 (Set JVM heap size via jvm.options)
# vi /usr/local/elasticsearch/config/jvm.options
-Xms512M
-Xmx512M
配置环境变量
# vi /etc/profile
export ES_HOME=/usr/local/elasticsearch
# source /etc/profile
添加独立用户,并启动服务
# groupadd elsearch
# useradd elsearch -g elsearch
# chown -R elsearch:elsearch /usr/local/elasticsearch
# su elsearch
# cd /usr/local/elasticsearch/bin
# ./elasticsearch
可能错误(一)
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 [elsearch] likely too low, increase to at least [2048]
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决:修改配置
# https://www.elastic.co/guide/en/elasticsearch/reference/master/setting-system-settings.html
# vi /etc/security/limits.conf #永久设置
elsearch soft nofile 65536
elsearch hard nofile 65536
elsearch soft nproc 2048
elsearch hard nproc 2048
# ulimit -n 65536 #临时设置,重启无效
# ulimit -u 2048
# ulimit -a
# vi /etc/sysctl.conf #永久设置
vm.max_map_count=262144
# sysctl -w vm.max_map_count=262144 #临时设置,重启无效
# sysctl -a | grep "vm.max_map_count"
可能错误(二)
Java HotSpot(TM) Server VM warning: INFO: os::commit_memory(0xcc000000, 469762048, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 469762048 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/elasticsearch/bin/hs_err_pid7598.log
解决:修改足够的内存
# vi /usr/local/elasticsearch/config/jvm.options
-Xms512M
-Xmx512M
# vi /usr/local/elasticsearch/bin/elasticsearch
# ES_JAVA_OPTS="-Xms512m -Xmx512m" $ES_HOME/bin/elasticsearch
正常启动服务状态
[2017-01-07T12:18:21,508][INFO ][o.e.n.Node ] [node-1] initializing ...
[2017-01-07T12:18:21,814][INFO ][o.e.e.NodeEnvironment ] [node-1] using [1] data paths, mounts [[/ (/dev/sda2)]], net usable_space [11gb], net total_space [17.7gb], spins? [possibly], types [ext3]
[2017-01-07T12:18:21,816][INFO ][o.e.e.NodeEnvironment ] [node-1] heap size [505.6mb], compressed ordinary object pointers [unknown]
[2017-01-07T12:18:21,849][INFO ][o.e.n.Node ] [node-1] version[5.0.0], pid[16529], build[253032b/2016-10-26T04:37:51.531Z], OS[Linux/2.6.18-238.el5/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_111/25.111-b14]
[2017-01-07T12:18:30,971][INFO ][o.e.p.PluginsService ] [node-1] loaded module [aggs-matrix-stats]
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService ] [node-1] loaded module [ingest-common]
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-expression]
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-groovy]
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-mustache]
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-painless]
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService ] [node-1] loaded module [percolator]
[2017-01-07T12:18:30,974][INFO ][o.e.p.PluginsService ] [node-1] loaded module [reindex]
[2017-01-07T12:18:30,974][INFO ][o.e.p.PluginsService ] [node-1] loaded module [transport-netty3]
[2017-01-07T12:18:30,975][INFO ][o.e.p.PluginsService ] [node-1] loaded module [transport-netty4]
[2017-01-07T12:18:30,976][INFO ][o.e.p.PluginsService ] [node-1] no plugins loaded
[2017-01-07T12:18:55,728][INFO ][o.e.n.Node ] [node-1] initialized
[2017-01-07T12:18:55,728][INFO ][o.e.n.Node ] [node-1] starting ...
[2017-01-07T12:18:59,185][INFO ][o.e.t.TransportService ] [node-1] publish_address {192.168.1.222:9300}, bound_addresses {192.168.1.222:9300}
[2017-01-07T12:18:59,277][INFO ][o.e.b.BootstrapCheck ] [node-1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2017-01-07T12:19:03,447][INFO ][o.e.c.s.ClusterService ] [node-1] new_master {node-1}{8x-utN34QFqJmeeIhrTGjA}{euJKK9YNSSueCM__ko6O8Q}{192.168.1.222}{192.168.1.222:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2017-01-07T12:19:03,636][INFO ][o.e.h.HttpServer ] [node-1] publish_address {192.168.1.222:9200}, bound_addresses {192.168.1.222:9200}
[2017-01-07T12:19:03,636][INFO ][o.e.n.Node ] [node-1] started
[2017-01-07T12:19:03,637][INFO ][o.e.g.GatewayService ] [node-1] recovered [0] indices into cluster_state
[2017-01-07T12:23:04,309][INFO ][o.e.m.j.JvmGcMonitorService] [node-1] [gc][young][248][9] duration [723ms], collections [1]/[1s], total [723ms]/[1.7s], memory [72.1mb]->[37mb]/[505.6mb], all_pools {[young] [51.2mb]->[172.8kb]/[51.2mb]}{[survivor] [6.3mb]->[4.7mb]/[6.3mb]}{[old] [14.4mb]->[32.3mb]/[448mb]}
[2017-01-07T12:23:04,310][WARN ][o.e.m.j.JvmGcMonitorService] [node-1] [gc][248] overhead, spent [723ms] collecting in the last [1s]
浏览器打开网址:http://192.168.1.222:9200/ (出现当前集群节点信息)
{
"name" : "node-1",
"cluster_name" : "es_cluster",
"cluster_uuid" : "3DUO7WigT9m0pqMz-QlR4g",
"version" : {
"number" : "5.0.0",
"build_hash" : "253032b",
"build_date" : "2016-10-26T04:37:51.531Z",
"build_snapshot" : false,
"lucene_version" : "6.2.0"
},
"tagline" : "You Know, for Search"
}
参考: Installing Elasticsearch