CentOS6.5 安装 Elasticsearch5.5 超详细教程

一、Elasticsearch 简介

下面摘自官网

Elasticsearch is a distributed, RESTful search and analytics engine capable of solving a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data so you can discover the expected and uncover the unexpected.
(Elasticsearch是一种分布式,REST风格的搜索和分析引擎,能够解决越来越多的用例。 作为弹性堆栈的核心,它集中存储您的数据,以便您可以发现预期并发现意外。)

二、Elasticsearch 安装

安装前准备

  • 安装最新版 JDK ,本人测试环境是JDK 1.8.0_112,官方说 JDK 1.7 + 即可
  • 下载 Elasticsearch 最新安装包。

安装Elasticsearch

  • 解压安装包

    $ cd /opt/es
    
    $ tar zxvf elasticsearch-5.5.0.tar.gz
    
  • 修改 Elasticsearch 相关参数

    vi /opt/es/elasticsearch-5.5.0/config/elasticsearch.yml

    修改如下内容:

    # 集群的名字
    cluster.name: elasticsearch

    # 节点名字
    node.name: node-1

    # 索引分片个数,默认为5片
    index.number_of_shards: 5

    # 索引副本个数,默认为1个副本
    index.number_of_replicas: 1

    # 数据存储目录(多个路径用逗号分隔)
    path.data: /home/ntc/es/data

    # 日志目录
    path.logs: /home/ntc/es/logs

    # 修改一下ES的监听地址,这样别的机器才可以访问
    network.host: 172.16.X.X

    # 设置节点间交互的tcp端口(集群),默认是9300
    transport.tcp.port: 9300

    # 监听端口(默认的就好)
    http.port: 9200

    # 增加新的参数,这样head插件才可以访问es
    http.cors.enabled: true
    http.cors.allow-origin: "*"

  • 启动Elasticsearch

    $ cd elasticsearch-5.5.0
    
    $ ./bin/elasticsearch
    

    此时由于是用root用户启动的,所以会报如下错误。

[2017-07-11T12:10:33,262][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.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.0.jar:5.5.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.0.jar:5.5.0]
    ... 6 more

解决方案有两种:

  1. 直接修改Elasticsearch配置,支持用root启动。

    因为未验证,后续补充
    
  2. 出于系统安全考虑,建议新建单独的用户运行 Elasticsearch。

    (1) 创建用户组和用户

    $ groupadd esgroup
    $ useradd es -g esgroup
    

    (2) 修改 Elasticsearch 文件夹及内部所有文件的所属用户组和用户(注意用户和用户组的顺序)。

    $ chown -R es:esgroup /opt/es/elasticsearch-5.5.0
    

    (3) 切换到es用户,并启动Elasticsearch

    $ su - es
    [es@localhost ~]$ cd /opt/es/elasticsearch-5.5.0
    [es@localhost elasticsearch-5.5.0]$ ./bin/elasticsearch
    

    (4) 启动后,输出如下信息,启动成功

    [2017-07-11T12:48:13,611][INFO ][o.e.n.Node               ] initialized
    [2017-07-11T12:48:13,611][INFO ][o.e.n.Node               ] [zzZc25X] starting ...
    [2017-07-11T12:48:13,878][INFO ][o.e.t.TransportService   ] [zzZc25X] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
    [2017-07-11T12:48:13,898][WARN ][o.e.b.BootstrapChecks    ] [zzZc25X] max number of threads [1024] for user [es] is too low, increase to at least [2048]
    [2017-07-11T12:48:13,899][WARN ][o.e.b.BootstrapChecks    ] [zzZc25X] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    [2017-07-11T12:48:13,899][WARN ][o.e.b.BootstrapChecks    ] [zzZc25X] system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
    [2017-07-11T12:48:17,005][INFO ][o.e.c.s.ClusterService   ] [zzZc25X] new_master {zzZc25X}{zzZc25XOTdacyXbQyrqhMw}{ajlhWEWxTZyitnVUy-OFHQ}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
    [2017-07-11T12:48:17,056][INFO ][o.e.h.n.Netty4HttpServerTransport] [zzZc25X] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
    [2017-07-11T12:48:17,058][INFO ][o.e.n.Node               ] [zzZc25X] started
    [2017-07-11T12:48:17,321][INFO ][o.e.g.GatewayService     ] [zzZc25X] recovered [0] indices into cluster_state
    

三、验证 Elasticsearch 启动状态

  • 浏览器直接访问地址查看状态

    输入地址:

    http://172.16.X.X:9200/
    

    输出结果:

    {
      "name" : "zzZc25X",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "m52p74pBSIeX-Le50BM_qQ",
      "version" : {
        "number" : "5.5.0",
        "build_hash" : "260387d",
        "build_date" : "2017-06-30T23:16:05.735Z",
        "build_snapshot" : false,
        "lucene_version" : "6.6.0"
      },
      "tagline" : "You Know, for Search"
    }
    
  • 命令查看状态

    输入命令:

    [es@localhost elasticsearch-5.5.0]$ ps -ef | grep elastic
    

    输出结果:

    es       26430 26272 16 12:59 pts/1    00:00:22 /opt/jdk1.8.0_112/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -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=/opt/es/elasticsearch-5.5.0 -cp /opt/es/elasticsearch-5.5.0/lib/* org.elasticsearch.bootstrap.Elasticsearch
    

四、Elasticsearch 后台启动及关闭

  • Elasticsearch后台启动

    通过./bin/elasticsearch 启动服务,按 ctrl+c 的时候程序就会stop掉比较尴尬,所以需要后台启动程序。
    
    首先授权执行命令:
    chmod +x ./bin/elasticsearch
    再次执行后台启动命令:
    ./bin/elasticsearch -d
    
  • 通过上一步查看到的 Elasticsearch 状态中的端口,执行下面命令杀死 Elasticsearch 进程

    [es@localhost elasticsearch-5.5.0]$ kill -9 26430
    

五、安装过程中的一些其他问题

  • 启动时会有这么一个警告,不影响使用,网上查询说使用最新linux版本就可以了。
[2017-07-11T13:13:08,465][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.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.SystemCallFilter.init(SystemCallFilter.java:638) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.JNANatives.tryInstallSystemCallFilter(JNANatives.java:215) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Natives.tryInstallSystemCallFilter(Natives.java:99) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.cli.Command.main(Command.java:88) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.5.0.jar:5.5.0]
  • max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

    解决方案:切换到root用户,编辑 limits.conf 添加下面内容

    vi /etc/security/limits.conf

    添加如下内容:

    * soft nofile 65536

    * hard nofile 131072

    * soft nproc 2048

    * hard nproc 4096

  • max number of threads [1024] for user [es] is too low, increase to at least [2048]

    解决方案:切换到root用户,进入limits.d目录下修改配置文件。

    修改如下内容:

    * soft nproc 1024

    #修改为

    * soft nproc 2048

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

    解决方案:切换到root用户修改配置sysctl.conf

    vi /etc/sysctl.conf

    添加下面配置:

    vm.max_map_count=655360

    并执行命令:

    sysctl -p

  • system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

    原因: CentOS6.X 不支持SecComp,而ES5.2.0默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。

    解决方案:修改/opt/es/elasticsearch-5.5.0/config/elasticsearch.yml中配置

    vi /opt/es/elasticsearch-5.5.0/config/elasticsearch.yml

    修改如下配置

    #bootstrap.memory_lock: true

    #修改为

    bootstrap.memory_lock: false

    bootstrap.system_call_filter: false

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容