本文记录一次在CentOS上安装ElasticSearch的过程,其中也包含了安装过程中遇到的错误以及相应的解决方法。
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。
下载
使用wget下载elasticsearch安装包,本文使用的安装包版本为2.4.0。
[root@dev18 srv]# wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.0/elasticsearch-2.4.0.tar.gz --2017-03-19 19:52:16-- https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.0/elasticsearch-2.4.0.tar.gz Resolving download.elastic.co... 107.21.249.70,54.243.211.74,107.22.208.105,... Connecting to download.elastic.co|107.21.249.70|:443... connected. HTTP request sent,awaiting response... 200 OK Length: 27364449 (26M) [application/gzip] Saving to: “elasticsearch-2.4.0.tar.gz” 67% [==========================================================================================================================================================> ] 18,529,728 3.56K/s in 13m 54s 2017-03-19 20:06:12 (21.7 KB/s) - Connection closed at byte 18529728. Retrying. --2017-03-19 20:06:13-- (try: 2) https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.0/elasticsearch-2.4.0.tar.gz Connecting to download.elastic.co|107.21.249.70|:443... connected. HTTP request sent,awaiting response... 206 Partial Content Length: 27364449 (26M),8834721 (8.4M) remaining [application/gzip] Saving to: “elasticsearch-2.4.0.tar.gz” 100%[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=========================================================================>] 27,364,449 560K/s in 17s 2017-03-19 20:06:32 (495 KB/s) - “elasticsearch-2.4.0.tar.gz” saved [27364449/27364449] [root@dev18 srv]#
解压缩
使用tar -zvxf elasticsearch-2.4.0.tar.gz命令将elasticsearch安装包解压,如:
[root@dev18 srv]# tar -zvxf elasticsearch-2.4.0.tar.gz elasticsearch-2.4.0/README.textile elasticsearch-2.4.0/LICENSE.txt elasticsearch-2.4.0/NOTICE.txt elasticsearch-2.4.0/modules/ elasticsearch-2.4.0/modules/lang-groovy/ elasticsearch-2.4.0/modules/reindex/ elasticsearch-2.4.0/modules/lang-expression/ elasticsearch-2.4.0/modules/lang-groovy/plugin-security.policy elasticsearch-2.4.0/modules/lang-groovy/plugin-descriptor.properties elasticsearch-2.4.0/modules/lang-groovy/groovy-2.4.6-indy.jar elasticsearch-2.4.0/modules/lang-groovy/lang-groovy-2.4.0.jar elasticsearch-2.4.0/modules/reindex/plugin-descriptor.properties elasticsearch-2.4.0/modules/reindex/reindex-2.4.0.jar elasticsearch-2.4.0/modules/lang-expression/plugin-security.policy elasticsearch-2.4.0/modules/lang-expression/plugin-descriptor.properties elasticsearch-2.4.0/modules/lang-expression/asm-commons-5.0.4.jar elasticsearch-2.4.0/modules/lang-expression/antlr4-runtime-4.5.1-1.jar elasticsearch-2.4.0/modules/lang-expression/lang-expression-2.4.0.jar elasticsearch-2.4.0/modules/lang-expression/lucene-expressions-5.5.2.jar elasticsearch-2.4.0/modules/lang-expression/asm-5.0.4.jar elasticsearch-2.4.0/config/elasticsearch.yml elasticsearch-2.4.0/config/logging.yml elasticsearch-2.4.0/bin/plugin.bat elasticsearch-2.4.0/bin/elasticsearch.in.bat elasticsearch-2.4.0/bin/service.bat elasticsearch-2.4.0/bin/elasticsearch.bat elasticsearch-2.4.0/bin/elasticsearch-service-mgr.exe elasticsearch-2.4.0/bin/elasticsearch-service-x64.exe elasticsearch-2.4.0/bin/elasticsearch-service-x86.exe elasticsearch-2.4.0/bin/elasticsearch.in.sh elasticsearch-2.4.0/bin/elasticsearch elasticsearch-2.4.0/bin/plugin elasticsearch-2.4.0/lib/lucene-core-5.5.2.jar elasticsearch-2.4.0/lib/lucene-backward-codecs-5.5.2.jar elasticsearch-2.4.0/lib/lucene-analyzers-common-5.5.2.jar elasticsearch-2.4.0/lib/lucene-queries-5.5.2.jar elasticsearch-2.4.0/lib/lucene-memory-5.5.2.jar elasticsearch-2.4.0/lib/lucene-Highlighter-5.5.2.jar elasticsearch-2.4.0/lib/lucene-join-5.5.2.jar elasticsearch-2.4.0/lib/lucene-queryparser-5.5.2.jar elasticsearch-2.4.0/lib/lucene-sandBox-5.5.2.jar elasticsearch-2.4.0/lib/lucene-suggest-5.5.2.jar elasticsearch-2.4.0/lib/lucene-misc-5.5.2.jar elasticsearch-2.4.0/lib/lucene-grouping-5.5.2.jar elasticsearch-2.4.0/lib/lucene-spatial-5.5.2.jar elasticsearch-2.4.0/lib/lucene-spatial3d-5.5.2.jar elasticsearch-2.4.0/lib/spatial4j-0.5.jar elasticsearch-2.4.0/lib/guava-18.0.jar elasticsearch-2.4.0/lib/securesm-1.0.jar elasticsearch-2.4.0/lib/hppc-0.7.1.jar elasticsearch-2.4.0/lib/joda-time-2.9.4.jar elasticsearch-2.4.0/lib/joda-convert-1.2.jar elasticsearch-2.4.0/lib/jackson-core-2.8.1.jar elasticsearch-2.4.0/lib/jackson-dataformat-smile-2.8.1.jar elasticsearch-2.4.0/lib/jackson-dataformat-yaml-2.8.1.jar elasticsearch-2.4.0/lib/snakeyaml-1.15.jar elasticsearch-2.4.0/lib/jackson-dataformat-cbor-2.8.1.jar elasticsearch-2.4.0/lib/netty-3.10.6.Final.jar elasticsearch-2.4.0/lib/compress-lzf-1.0.2.jar elasticsearch-2.4.0/lib/t-digest-3.0.jar elasticsearch-2.4.0/lib/HdrHistogram-2.1.6.jar elasticsearch-2.4.0/lib/commons-cli-1.3.1.jar elasticsearch-2.4.0/lib/jsr166e-1.1.0.jar elasticsearch-2.4.0/lib/elasticsearch-2.4.0.jar elasticsearch-2.4.0/lib/jts-1.13.jar elasticsearch-2.4.0/lib/compiler-0.8.13.jar elasticsearch-2.4.0/lib/log4j-1.2.17.jar elasticsearch-2.4.0/lib/apache-log4j-extras-1.2.17.jar elasticsearch-2.4.0/lib/jna-4.1.0.jar [root@dev18 srv]#
重命名解压后的elasticsearch目录名elasticsearch-2.4.0。
[root@dev18 srv]# mv elasticsearch-2.4.0 elasticsearch [root@dev18 srv]# cd elasticsearch [root@dev18 elasticsearch]# ll total 44 drwxr-xr-x 2 root root 4096 Mar 19 20:15 bin drwxr-xr-x 2 root root 4096 Mar 19 20:15 config drwxr-xr-x 2 root root 4096 Mar 19 20:15 lib -rw-rw-r-- 1 1000 1000 11358 Aug 24 2016 LICENSE.txt drwxrwxr-x 5 1000 1000 4096 Aug 29 2016 modules -rw-rw-r-- 1 1000 1000 150 Aug 24 2016 NOTICE.txt -rw-rw-r-- 1 1000 1000 8700 Aug 24 2016 README.textile [root@dev18 elasticsearch]#
启动遇到问题
进入elasticsearch的bin目录,尝试使用./elasticsearch -d命令启动elasticsearch。
[root@dev18 elasticsearch]# cd bin [root@dev18 bin]# ll total 324 -rwxr-xr-x 1 1000 1000 5551 Aug 24 2016 elasticsearch -rw-rw-r-- 1 1000 1000 909 Aug 24 2016 elasticsearch.bat -rw-rw-r-- 1 1000 1000 3307 Aug 24 2016 elasticsearch.in.bat -rwxr-xr-x 1 1000 1000 2814 Aug 24 2016 elasticsearch.in.sh -rw-rw-r-- 1 1000 1000 104448 Jul 27 2016 elasticsearch-service-mgr.exe -rw-rw-r-- 1 1000 1000 103936 Jul 27 2016 elasticsearch-service-x64.exe -rw-rw-r-- 1 1000 1000 80896 Jul 27 2016 elasticsearch-service-x86.exe -rwxr-xr-x 1 1000 1000 2992 Aug 24 2016 plugin -rw-rw-r-- 1 1000 1000 1303 Aug 24 2016 plugin.bat -rw-rw-r-- 1 1000 1000 6872 Aug 24 2016 service.bat [root@dev18 bin]# ./elasticsearch -d
遇到问题 (不能以root账号进行启动elasticSearch) --
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
详细问题如下:
[root@dev18 bin]# ./elasticsearch -d [root@dev18 bin]# Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root. at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:94) at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:160) at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286) at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35) Refer to the log for complete error details.
针对上述问题 (don't run elasticsearch as root.),本文给出两种解决方案~
解决方法
方法1
在启动elasticsearch的时候,指定允许root启动~ 如:
[root@dev18 bin]# ./elasticsearch -Des.insecure.allow.root=true
[root@dev18 bin]# ./elasticsearch -Des.insecure.allow.root=true [2017-03-20 09:09:11,160][WARN ][bootstrap ] running as ROOT user. this is a bad idea! [2017-03-20 09:09:11,189][WARN ][bootstrap ] unable to install syscall filter: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel,CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed [2017-03-20 09:09:11,893][INFO ][node ] [Bobster] version[2.4.0],pid[1388],build[ce9f0c7/2016-08-29T09:14:17Z] [2017-03-20 09:09:11,893][INFO ][node ] [Bobster] initializing ... [2017-03-20 09:09:13,159][INFO ][plugins ] [Bobster] modules [lang-groovy,reindex,lang-expression],plugins [],sites [] [2017-03-20 09:09:13,211][INFO ][env ] [Bobster] using [1] data paths,mounts [[/ (/dev/mapper/vg0-lv_root)]],net usable_space [8.8gb],net total_space [24.9gb],spins? [possibly],types [ext4] [2017-03-20 09:09:13,211][INFO ][env ] [Bobster] heap size [1007.3mb],compressed ordinary object pointers [true] [2017-03-20 09:09:16,788][INFO ][node ] [Bobster] initialized [2017-03-20 09:09:16,789][INFO ][node ] [Bobster] starting ... [2017-03-20 09:09:16,879][INFO ][transport ] [Bobster] publish_address {127.0.0.1:9300},bound_addresses {127.0.0.1:9300},{[::1]:9300} [2017-03-20 09:09:16,887][INFO ][discovery ] [Bobster] elasticsearch/o1NR_vRSS_mDyTstiSgGEQ [2017-03-20 09:09:20,076][INFO ][cluster.service ] [Bobster] new_master {Bobster}{o1NR_vRSS_mDyTstiSgGEQ}{127.0.0.1}{127.0.0.1:9300},reason: zen-disco-join(elected_as_master,[0] joins received) [2017-03-20 09:09:20,113][INFO ][http ] [Bobster] publish_address {127.0.0.1:9200},bound_addresses {127.0.0.1:9200},{[::1]:9200} [2017-03-20 09:09:20,114][INFO ][node ] [Bobster] started [2017-03-20 09:09:20,162][INFO ][gateway ] [Bobster] recovered [0] indices into cluster_state
这种方式能够启动,但是elasticsearch会提示,使用ROOT账户运行,这是一个不好的主意。
[WARN ][bootstrap ] running as ROOT user. this is a bad idea!
方法2
创建一个elasticsearch相关的账号~
(1) 首先,创建一个分组,取名为esgroup,然后,往该分组中添加用户es,并设置es账户的密码。
[root@dev18 bin]# groupadd esgroup [root@dev18 bin]# useradd -g esgroup es [root@dev18 bin]# passwd es Changing password for user es. New password: Retype new password: passwd: all authentication tokens updated successfully. [root@dev18 bin]#
(2)修改elasticsearch目录权限~
[root@dev18 elasticsearch]# chown -R root . [root@dev18 elasticsearch]# chown -R es . [root@dev18 elasticsearch]# chgrp -R esgroup .
(3)使用新创建的账号es来登录终端, 并使用./elasticsearch -d命令启动elasticsearch
[es@dev18 ~]$ cd /srv/elasticsearch [es@dev18 elasticsearch]$ cd bin [es@dev18 bin]$ ./elasticsearch -d
(4)验证
在方法2中,通过前面的(1)、(2)、(3)三个步骤之后,elasticsearch已经运行~
所以,我们需要做一下验证,看elasticsearch是否正常启动~
使用ps -ef|grep elasticsearch查看进程~
[es@dev18 bin]$ ps -ef|grep elasticsearch es 1656 1 29 09:17 pts/3 00:00:09 /usr/java/jdk1.7.0_71/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/srv/elasticsearch -cp /srv/elasticsearch/lib/elasticsearch-2.4.0.jar:/srv/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -d es 1714 1624 0 09:18 pts/3 00:00:00 grep elasticsearch [es@dev18 bin]$
使用curl -X GET http://localhost:9200查看信息~
[es@dev18 bin]$ curl -X GET http://localhost:9200 { "name" : "George Tarleton","cluster_name" : "elasticsearch","version" : { "number" : "2.4.0","build_hash" : "ce9f0c7394dee074091dd1bc4e9469251181fc55","build_timestamp" : "2016-08-29T09:14:17Z","build_snapshot" : false,"lucene_version" : "5.5.2" },"tagline" : "You Know,for Search" } [es@dev18 bin]$
至此,默认条件配置的elasticsearch就成功了~ 后续就可以玩elasticsearch相关的其它功能了~~
原文链接:https://www.f2er.com/centos/378316.html