elasticSearch安装步骤

  • Post author:
  • Post category:其他


  1. 下载elasticSearch Linux版,然后找个位置解压
  2. 进入elasticSearch的bin目录下

    [root@localhost bin]# ./elasticsearch
    2018-12-11T22:58:32,045][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:140) ~[elasticsearch-6.5.2.jar:6.5.2]
    	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.2.jar:6.5.2]
    	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.2.jar:6.5.2]
    	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.2.jar:6.5.2]
    	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.2.jar:6.5.2]
    	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.2.jar:6.5.2]
    	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.2.jar:6.5.2]
    Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.2.jar:6.5.2]
    	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.2.jar:6.5.2]
    	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.2.jar:6.5.2]
    	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.2.jar:6.5.2]
    	... 6 more

  3. 创建用户和组

    [root@localhost bin]# groupadd eszu
    [root@localhost bin]# useradd esyonghu -g eszu -p 123456

  4. 进入elasticsearch-6.5.2目录的上一级

    将elasticsearch-6.5.2目录下的所有权限赋予刚创建的用户

    root@localhost elasticsearch-6.5.2]# cd ..
    [root@localhost tools]# ll
    total 291860
    drwxr-xr-x. 8 root root       143 Nov 30 08:02 elasticsearch-6.5.2
    -rw-r--r--. 1 root root 113320120 Dec 11 22:53 elasticsearch-6.5.2.tar.gz
    -rwxrwxrwx. 1 root root 185540433 Dec 11 22:39 jdk-linux-x64.tar.gz
    [root@localhost tools]# chown -R esyonghu:eszu elasticsearch-6.5.2

  5. 切换用户

    [root@localhost tools]# su esyonghu

  6. 修改ip ,修改配置文件

    [esyonghu@localhost elasticsearch-6.5.2]$ cd config/
    [esyonghu@localhost config]$ ll
    total 36
    -rw-rw----. 1 esyonghu eszu   207 Dec 11 22:58 elasticsearch.keystore
    -rw-rw----. 1 esyonghu eszu  2853 Nov 30 07:55 elasticsearch.yml
    -rw-rw----. 1 esyonghu eszu  3194 Nov 30 07:55 jvm.options
    -rw-rw----. 1 esyonghu eszu 12423 Nov 30 08:02 log4j2.properties
    -rw-rw----. 1 esyonghu eszu   473 Nov 30 08:02 role_mapping.yml
    -rw-rw----. 1 esyonghu eszu   197 Nov 30 08:02 roles.yml
    -rw-rw----. 1 esyonghu eszu     0 Nov 30 08:02 users
    -rw-rw----. 1 esyonghu eszu     0 Nov 30 08:02 users_roles
    [esyonghu@localhost config]$ vi elasticsearch.yml 

  7. 将下面内容的注释部分打开

    network.host: 192.168.119.140
    #
    # Set a custom port for HTTP:
    #
    http.port: 9200

  8. 保存后,重新启动

    [esyonghu@localhost bin]$ ./elasticsearch

    主要出现下面三个错误

    ERROR: [3] bootstrap checks failed
    [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
    [2]: max number of threads [3780] for user [esyonghu] is too low, increase to at least [4096]
    [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    [2018-12-12T21:54:57,353][INFO ][o.e.n.Node               ] [PlbSkhz] stopping ...
    [2018-12-12T21:54:57,413][INFO ][o.e.n.Node               ] [PlbSkhz] stopped
    [2018-12-12T21:54:57,413][INFO ][o.e.n.Node               ] [PlbSkhz] closing ...
    [2018-12-12T21:54:57,473][INFO ][o.e.n.Node               ] [PlbSkhz] closed
    [2018-12-12T21:54:57,488][INFO ][o.e.x.m.j.p.NativeController] [PlbSkhz] Native controller process has stopped - no new native processes can be started
    

    解决方法

    [root@localhost ~]# vi /etc/security/limits.conf

    在文件的末尾加上

    esyonghu soft nofile 65536
    esyonghu hard nofile 65536
    esyonghu soft nproc 4096
    esyonghu hard nproc 4096

    进入到下面文件夹

    [root@localhost ~]# cd /etc/security/limits.d
    [root@localhost limits.d]# ll
    total 4
    -rw-r--r--. 1 root root 191 Nov  6  2016 20-nproc.conf
    
    [root@localhost limits.d]# vi 20-nproc.conf 
    
    # Default limit for number of user's processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.
    
    *          soft    nproc     4096
    root       soft    nproc     unlimited
    ~                                                                                                                            
    ~  

    将上面内容的*号改成用户名

    # See rhbz #432903 for reasoning.
    
    esyonghu   soft    nproc     4096
    root       soft    nproc     unlimited

    修改下面文件加上内容

    [root@localhost security]# vi /etc/sysctl.conf 
    vm.max_map_count = 655360

    对于上面的内容让其生效

    [root@localhost security]# sysctl -p
    vm.max_map_count = 655360

    重新启动ES,发现仍然有两个问题。

    ERROR: [2] bootstrap checks failed
    [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
    [2]: max number of threads [3780] for user [esyonghu] is too low, increase to at least [4096]
    [2018-12-12T22:10:33,868][WARN ][o.e.m.j.JvmGcMonitorService] [PlbSkhz] [gc][young][2][28] duration [1.9s], collections [1]/[2.7s], total [1.9s]/[10.4s], memory [121.1mb]->[65.1mb]/[1015.6mb], all_pools {[young] [59mb]->[292.5kb]/[66.5mb]}{[survivor] [7.3mb]->[7.8mb]/[8.3mb]}{[old] [54.7mb]->[57mb]/[940.8mb]}
    [2018-12-12T22:10:33,869][WARN ][o.e.m.j.JvmGcMonitorService] [PlbSkhz] [gc][2] overhead, spent [1.9s] collecting in the last [2.7s]
    [2018-12-12T22:10:33,993][INFO ][o.e.n.Node               ] [PlbSkhz] stopping ...
    [2018-12-12T22:10:34,092][INFO ][o.e.n.Node               ] [PlbSkhz] stopped
    [2018-12-12T22:10:34,092][INFO ][o.e.n.Node               ] [PlbSkhz] closing ...
    [2018-12-12T22:10:34,156][INFO ][o.e.n.Node               ] [PlbSkhz] closed
    [2018-12-12T22:10:34,197][INFO ][o.e.x.m.j.p.NativeController] [PlbSkhz] Native controller process has stopped - no new native processes can be started

    重启虚拟机reboot

  9. 关闭防火墙

    [root@localhost ~]# systemctl stop firewalld.service

  10. 对于9100端口,防火墙放行

    firewall-cmd --zone=public --add-port=9100/tcp --permanent

  11. 重启防火墙

    firewall-cmd --reload

  12. 启动es ,使用su esyonghu,进入es下的bin目录下./elasticsearch

  13. 启动es-head,进入到es-head目录下 ,执行

    node_modules/grunt/bin/grunt server



版权声明:本文为zhanghe687原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。