ALearner

  • 首页
  • Python
  • Linux
  • Java
  • 工具
  • 前端
  • 算法
  • My World
HelloStranger
每个人都是初学者
  1. 首页
  2. Linux
  3. 正文

Centos7 安装 Elasticsearch 6.2.2 及root启动和新建用户启动

2018年10月13日 10710点热度 9人点赞 0条评论

Elasticsearch

ElasticSearch 的介绍比较多,读者可以自行谷歌搜索,下面是我认为比较简洁的概括(来源于网上,侵删)

  • ElasticSearch是一个高可扩展的开源的全文搜索分析引擎。
    它允许你快速的存储、搜索和分析大量数据。ElasticSearch通常作为后端程序,为需要复杂查询的应用提供服务。
  • Elasticsearch是一个基于Lucene的开源分布式搜索引擎,具有分布式多用户能力。Elasticsearch是用java开发,提供Restful接口,能够达到实时搜索、高性能计算;同时Elasticsearch的横向扩展能力非常强,不需要重启服务,基本上达到了零配置。

安装前提

Elasticsearch的运行至少需要安装 Java8及其以上,Centos7安装Java的步骤具体可以参考下面的文章:

Linux(Centos7)安装Java JDK 1.8 : http://alearner.top/index.php/2017/07/20/linuxinstalljdk1-8/

下载·安装

 

下载Elasticsearch

官网 : https://www.elastic.co/

最新版下载地址 : https://www.elastic.co/downloads/elasticsearch

下载特定版本 :https://www.elastic.co/downloads/past-releases

Centos进入特定文件夹(笔者习惯将下载的文件放在  /usr/downloads 文件夹下),下载对应版本的文件

[root@sdumzg downloads]# pwd
/usr/downloads
[root@sdumzg downloads]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz

解压

 tar -zxvf elasticsearch-6.2.2.tar.gz

移动到想要存放的目录下 (本例将把elasticsearch放在/usr/local/目录下运行)

 mv elasticsearch-6.2.2 /usr/local

进入对应bin目录

[root@sdumzg elasticsearch-6.2.2]# ls
bin config lib LICENSE.txt logs modules NOTICE.txt plugins README.textile
[root@sdumzg elasticsearch-6.2.2]# cd bin/
[root@sdumzg bin]# pwd
/usr/local/elasticsearch-6.2.2/bin
[root@sdumzg bin]#

 

启动

启动命令

 ./elasticsearch

后台启动

 ./elasticsearch

假如直接在root用户下启动,将会出现以下错误提示

[2018-10-13T10:35:29,941][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.2.jar:6.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.2.jar:6.2.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.2.jar:6.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.2.jar:6.2.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.2.jar:6.2.2]
... 6 more

原因 :

这是Elasticsearch出于系统安全考虑设置的条件。由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑, 建议创建一个单独的用户用来运行ElasticSearch。

解决办法

 

允许Elasticsearch通过root用户启动(不推荐)

./elasticsearch -Des.insecure.allow.root=true

创建一个单独的用户用来运行ElasticSearch(推荐)

1、创建elsearch用户组及elsearch用户

[root@sdumzg bin]# groupadd elsearch
[root@sdumzg bin]# useradd elsearch -g elsearch -p elasticsearch


2、更改elasticsearch文件夹及内部文件的所属用户及组为elsearch:elsearch

[root@sdumzg local]# ls
bin  elasticsearch-6.2.2  etc  games  include  jdk1.8.0_181  lib  lib64  libexec  sbin  share  src
[root@sdumzg local]# chown -R elsearch:elsearch  elasticsearch-6.2.2

3、切换到elsearch用户后后台启动

su elsearch
./elasticsearch -d

4、启动后打印信息如下

[2018-10-13T12:20:44,973][INFO ][o.e.n.Node ] [] initializing ...
[2018-10-13T12:20:45,089][INFO ][o.e.e.NodeEnvironment ] [KCwAer2] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [35gb], net total_space [39.2gb], types [rootfs]
[2018-10-13T12:20:45,089][INFO ][o.e.e.NodeEnvironment ] [KCwAer2] heap size [1015.6mb], compressed ordinary object pointers [true]
[2018-10-13T12:20:45,091][INFO ][o.e.n.Node ] node name [KCwAer2] derived from node ID [KCwAer2pSbu2Ph7W7r-ldw]; set [node.name] to override
[2018-10-13T12:20:45,091][INFO ][o.e.n.Node ] version[6.2.2], pid[10128], build[10b1edd/2018-02-16T19:01:30.685723Z], OS[Linux/3.10.0-862.9.1.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_181/25.181-b13]
[2018-10-13T12:20:45,091][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.4pTZfg8d, -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=/usr/local/elasticsearch-6.2.2, -Des.path.conf=/usr/local/elasticsearch-6.2.2/config]
[2018-10-13T12:20:46,678][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [aggs-matrix-stats]
[2018-10-13T12:20:46,678][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [analysis-common]
[2018-10-13T12:20:46,678][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [ingest-common]
[2018-10-13T12:20:46,678][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [lang-expression]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [lang-mustache]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [lang-painless]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [mapper-extras]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [parent-join]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [percolator]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [rank-eval]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [reindex]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [repository-url]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [transport-netty4]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] loaded module [tribe]
[2018-10-13T12:20:46,679][INFO ][o.e.p.PluginsService ] [KCwAer2] no plugins loaded
[2018-10-13T12:20:51,021][INFO ][o.e.d.DiscoveryModule ] [KCwAer2] using discovery type [zen]
[2018-10-13T12:20:52,095][INFO ][o.e.n.Node ] initialized
[2018-10-13T12:20:52,095][INFO ][o.e.n.Node ] [KCwAer2] starting ...
[2018-10-13T12:20:52,619][INFO ][o.e.t.TransportService ] [KCwAer2] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2018-10-13T12:20:52,628][WARN ][o.e.b.BootstrapChecks ] [KCwAer2] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2018-10-13T12:20:52,628][WARN ][o.e.b.BootstrapChecks ] [KCwAer2] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-10-13T12:20:55,801][INFO ][o.e.c.s.MasterService ] [KCwAer2] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {KCwAer2}{KCwAer2pSbu2Ph7W7r-ldw}{Owy7PL0DSw6b8KAPfce2ew}{127.0.0.1}{127.0.0.1:9300}
[2018-10-13T12:20:55,830][INFO ][o.e.c.s.ClusterApplierService] [KCwAer2] new_master {KCwAer2}{KCwAer2pSbu2Ph7W7r-ldw}{Owy7PL0DSw6b8KAPfce2ew}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {KCwAer2}{KCwAer2pSbu2Ph7W7r-ldw}{Owy7PL0DSw6b8KAPfce2ew}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-10-13T12:20:55,887][INFO ][o.e.h.n.Netty4HttpServerTransport] [KCwAer2] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2018-10-13T12:20:55,888][INFO ][o.e.n.Node ] [KCwAer2] started
[2018-10-13T12:20:55,915][INFO ][o.e.g.GatewayService ] [KCwAer2] recovered [0] indices into cluster_state

由上面的日志可以知道,我们的集群名称和node名称是自动生成的,假如想要指定,可以使用下面命令启动
./elasticsearch -Ecluster.name=my_cluster_name -Enode.name=my_node_name

查看是否启动成功
curl http://localhost:9200/

Elasticsearch 安装成功

Elasticsearch 安装成功

 

 

后续出现问题及解决方法

问题1

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

解决:在root用户下
ulimit -n 65536

问题2

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

解决:

修改/etc/sysctl.conf配置文件

cat /etc/sysctl.conf | grep vm.max_map_countvm.max_map_count=262144

如果不存在则添加

echo "vm.max_map_count=262144" >>/etc/sysctl.conf

使生效

source /etc/sysctl.conf

问题3

bootstrap checks failed

解决 : 见文章 https://www.jianshu.com/p/4c6f9361565b

 

相关

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2018年10月13日

iquantumer

你现在的态度决定你十年后是人物还是废物。

点赞
< 上一篇

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2022 alearner.top. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

鲁ICP备16024047号