Fork me on GitHub

在Centos7中安装elasticsearch5.5

在Centos7中安装elasticsearch5.5

 

第一步:必须要有jre支持

elasticsearch是用Java实现的,跑elasticsearch必须要有jre支持,所以必须先安装jre

可以参考 http://www.cnblogs.com/morgana/p/8688775.html

 

第二步:下载elasticsearch

进入官方下载 https://www.elastic.co/downloads/elasticsearch

因为是centos中运行 所以我们选 tar.gz压缩包;

下载后 用ftp上传到centos里 我们把这个文件上传到 /home/data/下

 

第三步:安装和配置elasticsearch

进入data目录  解压

[root@bogon ~]# cd /home/data/

[root@bogon data]# tar -zxvf elasticsearch-5.5.2.tar.gz 

新建目录 剪切文件到新目录

[root@bogon data]# cd

[root@bogon ~]# mkdir /home/es/

[root@bogon ~]# mv /home/data/elasticsearch-5.5.2 /home/es/

 

我们执行,来启动 elasticsearch

[root@bogon ~]# sh /home/es/elasticsearch-5.5.2/bin/elasticsearch

报错了:

[2017-09-07T19:43:10,628][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:127) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.2.jar:5.5.2]

Caused by: java.lang.RuntimeException: can not run elasticsearch as root

at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.2.jar:5.5.2]

at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.2.jar:5.5.2]

... 6 more

 

意思是不能用root用户来启动,那我们新建一个用户来启动

[root@bogon ~]# useradd elastic

[root@bogon ~]# chown -R elastic:elastic /home/es/elasticsearch-5.5.2/

新建elastic用户 并且把目录权限赋予给elastic 

我们切换成elastic用户,然后执行

[root@bogon ~]# su elastic

[elastic@bogon root]$ sh /home/es/elasticsearch-5.5.2/bin/elasticsearch

出来一大串info 说明成功了,但是这种方式是前台运行,不方便我们操作其他的 我们加下 -d 后台运行

先ctrl+c退出执行;

[elastic@bogon root]$ sh /home/es/elasticsearch-5.5.2/bin/elasticsearch -d

我们来检查下是否启动成功

[elastic@bogon root]$  ps -ef | grep elasticsearch

elastic    2962      1 23 19:48 pts/1    00:00:02 /home/java/jdk1.8.0_144/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/home/es/elasticsearch-5.5.2 -cp /home/es/elasticsearch-5.5.2/lib/* org.elasticsearch.bootstrap.Elasticsearch -d

elastic    2977   2849  0 19:48 pts/1    00:00:00 grep --color=auto elasticsearch

 

注意 有朋友经常出现 如下错误

ERROR: [2] bootstrap checks failed

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

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

 

可以参考:http://www.cnblogs.com/morgana/p/8688793.html

 

我们来验证下服务是否正常运行 curl http://localhost:9200

[elastic@bogon root]$ curl http://localhost:9200

{

  "name" : "K22mJd5",

  "cluster_name" : "elasticsearch",

  "cluster_uuid" : "R2qfXKtrQl2PwKdJMmPuMA",

  "version" : {

    "number" : "5.5.2",

    "build_hash" : "b2f0c09",

    "build_date" : "2017-08-14T12:33:14.154Z",

    "build_snapshot" : false,

    "lucene_version" : "6.6.0"

  },

  "tagline" : "You Know, for Search"

}

 

出来这个 说明配置OK。

 

第四步:允许外网连接配置

前面我们配置的仅仅是本机使用 但是我们比如集群以及其他机器连接 ,则需要配置下。

可以修改 /home/es/elasticsearch/config/elasticsearch.yml 文件

把 network.host 和 http.port 前面的 备注去掉 然后Host改成你的局域网IP即可

QQ鎴浘20170907195451.jpg

 

修改后 保存退出

 

然后我们把防火墙也关了 

systemctl stop firewalld.service

systemctl disable firewalld.service   禁止防火墙开机启动

 

最后我们重启下elasticsearch服务

ps -ef | grep elasticsearch 找到进程号

然后kill -9 进程号

 

再启动下elasticsearch

我们用谷歌浏览器请求下 http://192.168.1.108:9200/

QQ鎴浘20170907200318.jpg

 

OK 出现这东西 才算配置完成;

 

posted on 2018-04-01 22:36  vmaze  阅读(1080)  评论(0编辑  收藏  举报

导航