Linux下elasticsearch安装

2020-01-19  本文已影响0人  城堡下的晚祷

本文使用linux版本为CentOS6.8,ES版本为6.2.4,安装包可以从官网下载
https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-2-4

1.将elasticsearch-6.2.4.tar.gz上传至Linux系统/opt/software目录下,解压到/opt/module/目录下

[root@hadoop130 software]# tar -zxvf elasticsearch-6.2.4.tar.gz  -C  /opt/module/
elasticsearch-6.2.4/
elasticsearch-6.2.4/lib/
elasticsearch-6.2.4/lib/elasticsearch-6.2.4.jar
elasticsearch-6.2.4/lib/elasticsearch-core-6.2.4.jar
elasticsearch-6.2.4/lib/lucene-core-7.2.1.jar
elasticsearch-6.2.4/lib/lucene-analyzers-common-7.2.1.jar
elasticsearch-6.2.4/lib/lucene-backward-codecs-7.2.1.jar
......
2.进入bin目录下启动ES
[root@hadoop130 elasticsearch-6.2.4]# cd bin/
[root@hadoop130 bin]# ./elasticsearch
[2020-01-19T00:56:38,923][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-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.4.jar:6.2.4]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.4.jar:6.2.4]
    ... 6 more

上述报错表示不能用root用户启动ES,切换用户重新启动

[yzl@hadoop130 bin]$ ./elasticsearch
Exception in thread "main" java.nio.file.AccessDeniedException: /opt/module/elasticsearch-6.2.4/config/jvm.options
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
    at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
    at java.nio.file.Files.newByteChannel(Files.java:361)
    at java.nio.file.Files.newByteChannel(Files.java:407)
    at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
    at java.nio.file.Files.newInputStream(Files.java:152)
    at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:58)

上述错误是由于用户没有ES安装目录的运行权限导致的

[yzl@hadoop130 module]$ ll
总用量 12
drwxr-xr-x.  8 root root 4096 4月  13 2018 elasticsearch-6.2.4

root用户下执行 授予所有用户该目录的所有权限

chmod -R 777 elasticsearch-6.2.4/

重新启动

[yzl@hadoop130 bin]$ ./elasticsearch
[2020-01-19T01:20:00,721][WARN ][o.e.b.JNANatives         ] unable to install syscall filter: 
java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed
    at org.elasticsearch.bootstrap.SystemCallFilter.linuxImpl(SystemCallFilter.java:341) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.SystemCallFilter.init(SystemCallFilter.java:616) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.JNANatives.tryInstallSystemCallFilter(JNANatives.java:258) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Natives.tryInstallSystemCallFilter(Natives.java:113) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:110) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) [elasticsearch-cli-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-cli-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) [elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) [elasticsearch-6.2.4.jar:6.2.4]
[2020-01-19T01:20:01,665][INFO ][o.e.n.Node               ] [] initializing ...
[2020-01-19T01:20:01,988][INFO ][o.e.e.NodeEnvironment    ] [v-Ors61] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [27.8gb], net total_space [34.9gb], types [rootfs]
[2020-01-19T01:20:01,988][INFO ][o.e.e.NodeEnvironment    ] [v-Ors61] heap size [990.7mb], compressed ordinary object pointers [true]
[2020-01-19T01:20:02,000][INFO ][o.e.n.Node               ] node name [v-Ors61] derived from node ID [v-Ors61CSoG0Yymdxs54iw]; set [node.name] to override
[2020-01-19T01:20:02,000][INFO ][o.e.n.Node               ] version[6.2.4], pid[4012], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/2.6.32-642.el6.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_144/25.144-b01]
......

原因: Centos6不支持SecComp,而ES默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动解决:修改elasticsearch.yml 添以下内容 :

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

重新启动<( ̄ ﹌  ̄)>

[yzl@hadoop130 bin]$ ./elasticsearch
[2020-01-19T01:30:18,717][INFO ][o.e.n.Node               ] [] initializing ...
[2020-01-19T01:30:18,796][INFO ][o.e.e.NodeEnvironment    ] [v-Ors61] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [27.8gb], net total_space [34.9gb], types [rootfs]
[2020-01-19T01:30:18,797][INFO ][o.e.e.NodeEnvironment    ] [v-Ors61] heap size [990.7mb], compressed ordinary object pointers [true]
[2020-01-19T01:30:18,805][INFO ][o.e.n.Node               ] node name [v-Ors61] derived from node ID [v-Ors61CSoG0Yymdxs54iw]; set [node.name] to override
[2020-01-19T01:30:18,806][INFO ][o.e.n.Node               ] version[6.2.4], pid[4272], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/2.6.32-642.el6.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_144/25.144-b01]
[2020-01-19T01:30:18,806][INFO ][o.e.n.Node               ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.qdkbD5yY, -XX:+HeapDumpOnOutOfMemoryError, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/opt/module/elasticsearch-6.2.4, -Des.path.conf=/opt/module/elasticsearch-6.2.4/config]
[2020-01-19T01:30:19,352][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [aggs-matrix-stats]
[2020-01-19T01:30:19,352][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [analysis-common]
[2020-01-19T01:30:19,352][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [ingest-common]
[2020-01-19T01:30:19,352][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [lang-expression]
[2020-01-19T01:30:19,352][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [lang-mustache]
[2020-01-19T01:30:19,353][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [lang-painless]
[2020-01-19T01:30:19,353][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [mapper-extras]
[2020-01-19T01:30:19,353][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [parent-join]
[2020-01-19T01:30:19,353][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [percolator]
[2020-01-19T01:30:19,353][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [rank-eval]
[2020-01-19T01:30:19,353][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [reindex]
[2020-01-19T01:30:19,353][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [repository-url]
[2020-01-19T01:30:19,354][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [transport-netty4]
[2020-01-19T01:30:19,354][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [tribe]
[2020-01-19T01:30:19,354][INFO ][o.e.p.PluginsService     ] [v-Ors61] no plugins loaded
[2020-01-19T01:30:21,406][INFO ][o.e.d.DiscoveryModule    ] [v-Ors61] using discovery type [zen]
[2020-01-19T01:30:21,957][INFO ][o.e.n.Node               ] initialized
[2020-01-19T01:30:21,957][INFO ][o.e.n.Node               ] [v-Ors61] starting ...
[2020-01-19T01:30:22,080][INFO ][o.e.t.TransportService   ] [v-Ors61] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2020-01-19T01:30:22,095][WARN ][o.e.b.BootstrapChecks    ] [v-Ors61] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2020-01-19T01:30:22,096][WARN ][o.e.b.BootstrapChecks    ] [v-Ors61] max number of threads [1024] for user [yzl] is too low, increase to at least [4096]
[2020-01-19T01:30:22,096][WARN ][o.e.b.BootstrapChecks    ] [v-Ors61] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-01-19T01:30:25,158][INFO ][o.e.c.s.MasterService    ] [v-Ors61] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {v-Ors61}{v-Ors61CSoG0Yymdxs54iw}{dh3o0-MnSjCkT1l_o5K06g}{127.0.0.1}{127.0.0.1:9300}
[2020-01-19T01:30:25,164][INFO ][o.e.c.s.ClusterApplierService] [v-Ors61] new_master {v-Ors61}{v-Ors61CSoG0Yymdxs54iw}{dh3o0-MnSjCkT1l_o5K06g}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {v-Ors61}{v-Ors61CSoG0Yymdxs54iw}{dh3o0-MnSjCkT1l_o5K06g}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2020-01-19T01:30:25,197][INFO ][o.e.h.n.Netty4HttpServerTransport] [v-Ors61] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2020-01-19T01:30:25,205][INFO ][o.e.n.Node               ] [v-Ors61] started
[2020-01-19T01:30:25,219][INFO ][o.e.g.GatewayService     ] [v-Ors61] recovered [0] indices into cluster_state

started。。。终于启动成功。。。

3.另开终端测试是否可以正常使用
[yzl@hadoop130 ~]$ curl 127.0.0.1:9200
{
  "name" : "v-Ors61",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "fetCUVvXTqqCe0gJOBeeUw",
  "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.yml文件

# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.

192.168.0.1改为当前服务器IP地址

# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.32.130
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.

重新启动,居然又失败了ヽ(#`Д´)ノ┌┛〃

[2020-01-19T01:52:02,505][INFO ][o.e.n.Node               ] [v-Ors61] starting ...
[2020-01-19T01:52:02,618][INFO ][o.e.t.TransportService   ] [v-Ors61] publish_address {192.168.32.130:9300}, bound_addresses {192.168.32.130:9300}
[2020-01-19T01:52:02,633][INFO ][o.e.b.BootstrapChecks    ] [v-Ors61] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1024] for user [yzl] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-01-19T01:52:02,642][INFO ][o.e.n.Node               ] [v-Ors61] stopping ...
[2020-01-19T01:52:02,781][INFO ][o.e.n.Node               ] [v-Ors61] stopped
[2020-01-19T01:52:02,781][INFO ][o.e.n.Node               ] [v-Ors61] closing ...
[2020-01-19T01:52:02,789][INFO ][o.e.n.Node               ] [v-Ors61] closed

一个一个来解决。。。
(1)

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

原因:每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量

ulimit -Hn
ulimit -Sn

[yzl@hadoop130 bin]$ ulimit -Hn
4096
[yzl@hadoop130 bin]$ ulimit -Sn
1024

修改/etc/security/limits.conf文件,最后追加如下配置,xxx是使用ES的用户名,用户退出后重新登录生效

xxx  hard nofile 65536
 
xxx  soft nofile 65536

(2)

max number of threads [1024] for user [yzl] is too low, increase to at least [4096]

问题同上,最大线程个数太低。修改配置文件/etc/security/limits.conf(和问题1是一个文件),增加配置

xxx  hard    nproc 4096

xxx  soft  nproc 4096

(3)

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

修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144
执行sysctl -p命令后生效


[root@hadoop130 yzl]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.max_map_count = 262144

reboot后启动ES

[2020-01-19T02:19:07,091][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [aggs-matrix-stats]
[2020-01-19T02:19:07,091][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [analysis-common]
[2020-01-19T02:19:07,091][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [ingest-common]
[2020-01-19T02:19:07,091][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [lang-expression]
[2020-01-19T02:19:07,091][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [lang-mustache]
[2020-01-19T02:19:07,091][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [lang-painless]
[2020-01-19T02:19:07,091][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [mapper-extras]
[2020-01-19T02:19:07,092][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [parent-join]
[2020-01-19T02:19:07,092][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [percolator]
[2020-01-19T02:19:07,092][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [rank-eval]
[2020-01-19T02:19:07,092][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [reindex]
[2020-01-19T02:19:07,092][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [repository-url]
[2020-01-19T02:19:07,092][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [transport-netty4]
[2020-01-19T02:19:07,092][INFO ][o.e.p.PluginsService     ] [v-Ors61] loaded module [tribe]
[2020-01-19T02:19:07,093][INFO ][o.e.p.PluginsService     ] [v-Ors61] no plugins loaded
[2020-01-19T02:19:09,807][INFO ][o.e.d.DiscoveryModule    ] [v-Ors61] using discovery type [zen]
[2020-01-19T02:19:10,231][INFO ][o.e.n.Node               ] initialized
[2020-01-19T02:19:10,231][INFO ][o.e.n.Node               ] [v-Ors61] starting ...
[2020-01-19T02:19:10,371][INFO ][o.e.t.TransportService   ] [v-Ors61] publish_address {192.168.32.130:9300}, bound_addresses {192.168.32.130:9300}
[2020-01-19T02:19:10,382][INFO ][o.e.b.BootstrapChecks    ] [v-Ors61] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2020-01-19T02:19:13,439][INFO ][o.e.c.s.MasterService    ] [v-Ors61] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {v-Ors61}{v-Ors61CSoG0Yymdxs54iw}{GELoBa_CT_CN7F7hGrmW0A}{192.168.32.130}{192.168.32.130:9300}
[2020-01-19T02:19:13,445][INFO ][o.e.c.s.ClusterApplierService] [v-Ors61] new_master {v-Ors61}{v-Ors61CSoG0Yymdxs54iw}{GELoBa_CT_CN7F7hGrmW0A}{192.168.32.130}{192.168.32.130:9300}, reason: apply cluster state (from master [master {v-Ors61}{v-Ors61CSoG0Yymdxs54iw}{GELoBa_CT_CN7F7hGrmW0A}{192.168.32.130}{192.168.32.130:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2020-01-19T02:19:13,474][INFO ][o.e.h.n.Netty4HttpServerTransport] [v-Ors61] publish_address {192.168.32.130:9200}, bound_addresses {192.168.32.130:9200}
[2020-01-19T02:19:13,474][INFO ][o.e.n.Node               ] [v-Ors61] started
[2020-01-19T02:19:13,597][INFO ][o.e.g.GatewayService     ] [v-Ors61] recovered [0] indices into cluster_state

启动成功!!!

publish_address {192.168.32.130:9200}, bound_addresses {192.168.32.130:9200}

关闭防火墙!

CentOS 6
1.永久性生效,重启后不会复原

开启: chkconfig iptables on

关闭: chkconfig iptables off

2.即时生效,重启后复原

开启: service iptables start

关闭: service iptables stop

Windows下输入192.168.32.130:9200访问


上一篇下一篇

猜你喜欢

热点阅读