在CentOS上 安装部署Elastic Search

2019-09-28  本文已影响0人  林深时觉寒

安装部署Elastic Search

  1. /home/目录下新建elastic文件夹,切换该文件下.

    cd /home
    mkdir elastic
    cd elastic
    
  2. 下载wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz

  3. 解压。tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz

  4. 启动sh elasticsearch

    会发现报错了,报错信息:

    OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
    [2019-09-24T10:27:40,249][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [localhost.localdomain] 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:163) ~[elasticsearch-7.3.2.jar:7.3.2]
     at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.3.2.jar:7.3.2]
     at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.3.2.jar:7.3.2]
     at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.3.2.jar:7.3.2]
     at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.3.2.jar:7.3.2]
     at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.3.2.jar:7.3.2]
     at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.3.2.jar:7.3.2]
    Caused by: java.lang.RuntimeException: can not run elasticsearch as root
     at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.3.2.jar:7.3.2]
     at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.3.2.jar:7.3.2]
     at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.3.2.jar:7.3.2]
     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.3.2.jar:7.3.2]
     ... 6 more
    
    

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

    useradd elastic
    chown -R elastic:elastic elasticsearch-7.3.2
    su elastic
    sh elasticsearch-7.3.2/bin/elasticsearch
    

    这时启动成功。但是现在是前台启动,我们可以Ctrl + C退出,然后sh elasticsearch-7.3.2/bin/elasticsearch -d的命令后台启动。

  5. 启动后可使用ps -ef | grep elasticsearch查看进程。

    elastic  14992     1 99 10:31 pts/1    00:00:24 /home/elastic/elasticsearch-7.3.2/jdk/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -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-13731651965100738695 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -Djava.locale.providers=COMPAT -Dio.netty.allocator.type=unpooled -XX:MaxDirectMemorySize=536870912 -Des.path.home=/home/elastic/elasticsearch-7.3.2 -Des.path.conf=/home/elastic/elasticsearch-7.3.2/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /home/elastic/elasticsearch-7.3.2/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
    elastic  15008 14992  0 10:31 pts/1    00:00:00 /home/elastic/elasticsearch-7.3.2/modules/x-pack-ml/platform/linux-x86_64/bin/controller
    elastic  15024 14732  0 10:31 pts/1    00:00:00 grep --color=auto elasticsearch
    
  6. 测试访问,curl http://localhost:9200。显示如下信息:

    {
      "name" : "localhost.localdomain",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "VFVnijYtRSOOaLP0HP37ow",
      "version" : {
        "number" : "7.3.2",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "1c1faf1",
        "build_date" : "2019-09-06T14:40:30.409026Z",
        "build_snapshot" : false,
        "lucene_version" : "8.1.0",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    
  7. 在宿主机外部电脑访问,失败。

    报错

    ERROR: [2] bootstrap checks failed
    [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
    [2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
    
    

    切换root用户,vi /etc/security/limits.conf

    在倒数第二行

    * soft nofile 65536
    * hard nofile 65536
    # End of file
    

    vi /etc/sysctl.conf添加

    vm.max_map_count=655360
    

    保存后执行sysctl -p

    启动,报错

    ERROR: [1] bootstrap checks failed
    [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
    

    修改elasticsearch.yml,取消注释保留一个节点
    cluster.initial_master_nodes: ["node-1","node-2"]

    再次启动,ok。在外部浏览器访问:http://ip:9200

    {
      "name" : "localhost.localdomain",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "VFVnijYtRSOOaLP0HP37ow",
      "version" : {
        "number" : "7.3.2",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "1c1faf1",
        "build_date" : "2019-09-06T14:40:30.409026Z",
        "build_snapshot" : false,
        "lucene_version" : "8.1.0",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    

    ok.

  8. 参考资料:

    https://blog.csdn.net/happyzxs/article/details/89156068

    http://blog.java1234.com/blog/articles/342.html

上一篇下一篇

猜你喜欢

热点阅读