环境准备
#lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.5 (Final)
Release: 6.5
Codename: Final
#uname -a
Linux CDVM-213010030 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Elasticsearch 依赖:
Java 8+
安装Java
下载Java jdk, Java SE Development Kit 8 - Downloads
[elsearch@CDVM-213010030 tmp]$ ls /tmp/installed/
jdk-8u121-linux-x64.rpm jdk-8u121-linux-x64.tar.gz
[elsearch@CDVM-213010030 tmp]$ rpm -ivh jdk-8u121-linux-x64.rpm
[elsearch@CDVM-213010030 tmp]$ 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)
安装Elasticsearch
- 解压安装包
# tar zxvf elasticsearch-5.2.0.tar.gz -C /opt
- 运行elasticsearch脚本启动
# cd /opt/elasticsearch-5.2.0/bin
# ./elasticsearch
- 如果是用root账号运行,会出现以下错误:
[root@CDVM-213010030 elasticsearch-5.2.0]# ./bin/elasticsearch
[2017-02-08T14:22:45,125][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.2.0.jar:5.2.0]
at
... 6 more
这是出于系统安全考虑设置的条件。由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑, 建议创建一个单独的用户用来运行ElasticSearch。
- 创建elsearch用户组及elsearch用户
groupadd elsearch
useradd elsearch -g elsearch -p elsearch
- 更改Elasticsearch文件夹及内部文件的所属用户及组为elsearch:elsearch
chown -R elsearch:elsearch /opt/elasticsearch-5.2.0
- 切换到elsearch用户再启动
# su elsearch
$ cd elasticsearch-5.2.0/bin
$ ./elasticsearch
- 启动后打印信息如下
[elsearch@CDVM-213010030 elasticsearch-5.2.0]$ ./bin/elasticsearch
[2017-02-08T15:22:52,677][WARN ][o.e.b.JNANatives ] unable to install syscall filter:
java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in
at org.elasticsearch.bootstrap.SystemCallFilter.linuxImpl(SystemCallFilter.java:350) ~[elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.SystemCallFilter.init(SystemCallFilter.java:638) ~[elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.JNANatives.tryInstallSystemCallFilter(JNANatives.java:215) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Natives.tryInstallSystemCallFilter(Natives.java:99) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:110) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:203) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.cli.Command.main(Command.java:88) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) [elasticsearch-5.2.0.jar:5.2.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) [elasticsearch-5.2.0.jar:5.2.0]
[2017-02-08T15:22:52,768][INFO ][o.e.n.Node ] [] initializing ...
[2017-02-08T15:22:52,838][INFO ][o.e.e.NodeEnvironment ] [qm6aUUo] using [1] data paths, mounts [[/ (/dev/vda)]], net usable_space [184gb], net total_space [196.8gb], spins? [possibly], types [ext4]
[2017-02-08T15:22:52,839][INFO ][o.e.e.NodeEnvironment ] [qm6aUUo] heap size [1.9gb], compressed ordinary object pointers [true]
[2017-02-08T15:22:52,840][INFO ][o.e.n.Node ] node name [qm6aUUo] derived from node ID [qm6aUUoUScO_S16Sod_7Bw]; set [node.name] to override
[2017-02-08T15:22:52,841][INFO ][o.e.n.Node ] version[5.2.0], pid[22947], build[24e05b9/2017-01-24T19:52:35.800Z], OS[Linux/2.6.32-431.el6.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_121/25.121-b13]
[2017-02-08T15:22:53,573][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [aggs-matrix-stats]
[2017-02-08T15:22:53,573][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [ingest-common]
[2017-02-08T15:22:53,573][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [lang-expression]
[2017-02-08T15:22:53,573][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [lang-groovy]
[2017-02-08T15:22:53,573][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [lang-mustache]
[2017-02-08T15:22:53,573][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [lang-painless]
[2017-02-08T15:22:53,573][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [percolator]
[2017-02-08T15:22:53,574][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [reindex]
[2017-02-08T15:22:53,574][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [transport-netty3]
[2017-02-08T15:22:53,574][INFO ][o.e.p.PluginsService ] [qm6aUUo] loaded module [transport-netty4]
[2017-02-08T15:22:53,574][INFO ][o.e.p.PluginsService ] [qm6aUUo] no plugins loaded
[2017-02-08T15:22:55,217][INFO ][o.e.n.Node ] initialized
[2017-02-08T15:22:55,218][INFO ][o.e.n.Node ] [qm6aUUo] starting ...
[2017-02-08T15:22:55,288][WARN ][i.n.u.i.MacAddressUtil ] Failed to find a usable hardware address from the network interfaces; using random bytes: 24:be:3c:15:2d:4a:1d:e3
[2017-02-08T15:22:55,336][INFO ][o.e.t.TransportService ] [qm6aUUo] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2017-02-08T15:22:55,342][WARN ][o.e.b.BootstrapChecks ] [qm6aUUo] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2017-02-08T15:22:55,342][WARN ][o.e.b.BootstrapChecks ] [qm6aUUo] system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[2017-02-08T15:22:58,384][INFO ][o.e.c.s.ClusterService ] [qm6aUUo] new_master {qm6aUUo}{qm6aUUoUScO_S16Sod_7Bw}{qojdwy-UQmODn4nlWEboQA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2017-02-08T15:22:58,401][INFO ][o.e.h.HttpServer ] [qm6aUUo] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2017-02-08T15:22:58,401][INFO ][o.e.n.Node ] [qm6aUUo] started
[2017-02-08T15:22:58,424][INFO ][o.e.g.GatewayService ] [qm6aUUo] recovered [0] indices into cluster_state
Elasticsearch-5只支持内核3.5以上版本的linux操作系统
- ElasticSearch后端启动命令
./elasticsearch -d
- 修改配置文件
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
bootstrap.system_call_filter: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 10.213.10.30
#network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 10920
- 错误1
ERROR: bootstrap checks failed
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[2017-02-08T16:13:57,827][INFO ][o.e.n.Node ] [qm6aUUo] stopping ...
[2017-02-08T16:13:57,925][INFO ][o.e.n.Node ] [qm6aUUo] stopped
[2017-02-08T16:13:57,925][INFO ][o.e.n.Node ] [qm6aUUo] closing ...
[2017-02-08T16:13:57,946][INFO ][o.e.n.Node ] [qm6aUUo] closed
解决方案:
使用下面的方法临时使其生效
$ sudo sysctl -w vm.max_map_count=262144
或修改 /etc/sysctl.conf 文件,添加 “vm.max_map_count = 262144”;
设置后,立即生效
[root@CDVM-213010030 elasticsearch-5.2.0]# sysctl -p
[root@CDVM-213010030 elasticsearch-5.2.0]# sysctl -a | grep
vm.max_map_count = 262144
- 错误2
ERROR: bootstrap checks failed
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[2017-02-08T16:39:43,123][INFO ][o.e.n.Node ] [qm6aUUo] stopping ...
[2017-02-08T16:39:43,136][INFO ][o.e.n.Node ] [qm6aUUo] stopped
[2017-02-08T16:39:43,136][INFO ][o.e.n.Node ] [qm6aUUo] closing ...
[2017-02-08T16:39:43,242][INFO ][o.e.n.Node ] [qm6aUUo] closed
原因:
这是在因为Centos6不支持SecComp,而ES5.2.0默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。
解决方案:
在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
可以查看issues
https://github.com/elastic/elasticsearch/issues/22899
- 错误3
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解决方案:
修改/etc/security/limits.conf文件,添加或修改如下行:
hard nofile 65536
soft nofile 65536
测试
$ curl http://10.213.10.30:10920/?pretty
{
"name" : "qm6aUUo",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "UXrjeTP6SmmOIZOZ4j9I4w",
"version" : {
"number" : "5.2.0",
"build_hash" : "24e05b9",
"build_date" : "2017-01-24T19:52:35.800Z",
"build_snapshot" : false,
"lucene_version" : "6.4.0"
},
"tagline" : "You Know, for Search"
}