Linux安装Elasticsearch7.x

Linux服务器是CentOS 7.x
  1. Elasticsearch下载地址:
    https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.1.1-linux-x86_64.tar.gz

  2. 解压elasticsearch-7.1.1-linux-x86_64.tar.gz到/usr/local/目录:

    tar -avxf elasticsearch-7.1.1-linux-x86_64.tar.gz -C /usr/local/
    
  3. 进入解压后的elasticsearch目录:
    (1)新建data目录:

    mkdir data
    

    在这里插入图片描述
    (2)修改config/elasticsearch.yml:

    vim config/elasticsearch.yml
    

    取消下列项注释并修改:

    cluster.name: my-application #集群名称
    node.name: node-1 #节点名称
    #数据和日志的存储目录
    path.data: /usr/local/elasticsearch-7.1.1/data
    path.logs: /usr/local/elasticsearch-7.1.1/logs
    #设置绑定的ip,设置为0.0.0.0以后就可以让任何计算机节点访问到了
    network.host: 0.0.0.0
    http.port: 9200 #端口
    #设置在集群中的所有节点名称,这个节点名称就是之前所修改的,当然你也可以采用默认的也行,目前是单机,放入一个节点即可
    cluster.initial_master_nodes: ["node-1"]
    

    修改完毕后,:wq 保存退出vim

  4. 准备启动es
    进入/bin目录执行命令:

    ./elasticsearch
    

    我这里出现如下错误:

    Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
    #
    # There is insufficient memory for the Java Runtime Environment to continue.
    # Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
    # An error report file with more information is saved as:
    # logs/hs_err_pid22863.log
    [root@VM_0_2_centos bin]# 
    

    看来是我这1G的内存太小了啊,elasticsearch使用java的jvm默认是使用1G的内存的,这里我们修改一下内存,直接把内存改到200m
    cd 到es目录修改 ./config/jvm.options:

    vim ./config/jvm.options 
    

    修改该内容:

    -Xms200m
    -Xmx200m
    

    :wq 保存并退出vim,再次启动es

    再次启动出现如下错误:

    [2019-06-21T16:20:03,039][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 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.1.1.jar:7.1.1]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.1.1.jar:7.1.1]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.1.1.jar:7.1.1]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.1.1.jar:7.1.1]
        Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:102) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:169) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:325) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.1.1.jar:7.1.1]
        ... 6 more
        [root@VM_0_2_centos elasticsearch-7.1.1]# 
    

    这是不能使用root用户操作,添加一个其他的用户再试试:

    [root@VM_0_2_centos elasticsearch-7.1.1]# adduser es
    [root@VM_0_2_centos elasticsearch-7.1.1]# passwd es
    Changing password for user es.
    New password: 
    Retype new password: 
    passwd: all authentication tokens updated successfully.
    

    改一下es目录所属用户:

    [root@VM_0_2_centos elasticsearch-7.1.1]# chown es /usr/local/elasticsearch-7.1.1/ -R
    

    vim 编辑 /etc/security/limits.conf,在末尾加上:

    es soft nofile 65536
    es hard nofile 65536
    es soft nproc 4096
    es hard nproc 4096
    

    vim 编辑 vim /etc/security/limits.d/20-nproc.conf,将* 改为用户名(es):

    # Default limit for number of user's processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.
    
    es          soft    nproc     4096
    root       soft    nproc     unlimited
    

    vim 编辑 /etc/sysctl.conf,在末尾加上:

    vm.max_map_count = 655360
    

    执行:

    [root@VM_0_2_centos ~]# sysctl -p
    kernel.printk = 5
    vm.max_map_count = 655360
    [root@VM_0_2_centos ~]# 
    

    登录刚才新建的es用户,并启动elasticsearch,OK

    [root@VM_0_2_centos elasticsearch-7.1.1]# su es
    [es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch
    

    在这里插入图片描述

  5. 后台启动:

    [es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch -d
    [es@VM_0_2_centos elasticsearch-7.1.1]$ 
    

    查看进程:

    [es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch -d
    [es@VM_0_2_centos elasticsearch-7.1.1]$ ps -ef|grep elasticsearch
    es       18652     1 19 17:48 pts/2    00:00:00 /usr/local/java/jdk1.8.0_211/bin/java -Xms200m -Xmx200m -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-182563007296674551 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Dio.netty.allocator.type=unpooled -Des.path.home=/usr/local/elasticsearch-7.1.1 -Des.path.conf=/usr/local/elasticsearch-7.1.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elasticsearch-7.1.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
    es       18728  8399  0 17:48 pts/2    00:00:00 grep --color=auto elasticsearch
    [es@VM_0_2_centos elasticsearch-7.1.1]$ 
    
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值