centos 7.5下安装 elasticsearch 启动的问题

centos7.5下安装 elasticsearch 启动的问题

安装elasticsearch正常步骤

  1. Download and unzip Elasticsearch
  2. Run bin/elasticsearch 
  3.  Run curl http://localhost:9200/

异常信息:

root 账户启动报错,Exception in thread "main" Java.lang.RuntimeException: don't run elasticsearch as root.

解决办法:

解决方法1:

在执行elasticSearch时加上参数-Des.insecure.allow.root=true,完整命令如下

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

解决办法2:

用vi打开elasicsearch执行文件,在变量ES_JAVA_OPTS使用前添加以下命令

  1. ES_JAVA_OPTS="-Des.insecure.allow.root=true"  

解决办法3(建议使用此方法):

添加新用户组和用户,让非root 用户组用户启动:

groupadd elasticsearch

useradd es -g elasticsearch -p 123456

然后把我们的es 所在文件夹的 用户指定为 elsearch 

chown -R es:elasticsearch /opt/elasticsearch

启动成功之后 会有日志:

[2016-12-20T18:40:28,270][INFO ][o.e.g.GatewayService     ] [MUQhN6Y] recovered [0] indices into cluster_state
[2016-12-20T18:40:28,276][INFO ][o.e.h.HttpServer         ] [MUQhN6Y] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2016-12-20T18:40:28,276][INFO ][o.e.n.Node               ] [MUQhN6Y] started

访问url 成功会有结果:

{
  "name" : "MUQhN6Y",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "GQd_A6XCRFKMnzswmckmuA",
  "version" : {
    "number" : "5.1.1",
    "build_hash" : "5395e21",
    "build_date" : "2016-12-06T12:36:15.409Z",
    "build_snapshot" : false,
    "lucene_version" : "6.3.0"
  },
  "tagline" : "You Know, for Search"
}

现在本机访问可以访问了,但是在其他机器上访问还是有问题,提示连接拒绝,为什么呢?

因为这个端口只是监听127.0.0.1 的回环地址,不监听其他地址,而127 的地址只能本机访问,所以其他机器无法访问这台机器。

那该怎么办呢?

es 提供了解决办法:

/opt/elasticsearch-2.4.6/config 目录下有一个 文件elasticsearch.yml

如果想监听本机所有ip ,则配置:network.host: 192.168.1.146

如果想监听指定ip,多个ip逗号隔开 则:network.host: 127.0.0.1,192.168.12.18

然后重新启动,爆出异常:

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

vm.max_map_count [65530] likely too low, increase to at least [262144]

第一个问题:解决方案:

同样回到config/elasticsearch.yml文件,找到如下配置,开放discovery.zen.ping.unicast.hosts及discovery.zen.minimum_master_nodes

# --------------------------------- Discovery ----------------------------------

#

# Pass an initial list of hosts to perform discovery when new node is started:

# The default list of hosts is ["127.0.0.1", "[::1]"]

#

discovery.zen.ping.unicast.hosts: ["192.168.0.155"]

#

# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):

#

discovery.zen.minimum_master_nodes: 3

#

# For more information, see the documentation at:

# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>

然后修改max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]这个错误(切换到root操作)

切换到root 用户 :

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

[root@localhost ~]# cat /etc/security/limits.conf | grep -v "seven" > /tmp/system_limits.conf

[root@localhost ~]# echo "seven hard nofile 65536" >> /tmp/system_limits.conf

[root@localhost ~]# echo "seven soft nofile 65536" >> /tmp/system_limits.conf

[root@localhost ~]# mv /tmp/system_limits.conf /etc/security/limits.conf

以上serven 名称为 自己的非root 用户名。

修改后重新登录seven用户,使用如下命令查看是否修改成功

[seven@localhost ~]$ ulimit -Hn

65536

第2个问题:解决方案:



    [root@localhost ~]# cat /etc/sysctl.conf | grep -v "vm.max_map_count" > /tmp/system_sysctl.conf

    [root@localhost ~]# echo "vm.max_map_count=262144" >> /tmp/system_sysctl.conf

    [root@localhost ~]# mv /tmp/system_sysctl.conf /etc/sysctl.conf

    mv:是否覆盖"/etc/sysctl.conf"? y

    [root@localhost ~]# cat /etc/sysctl.conf

    # System default settings live in /usr/lib/sysctl.d/00-system.conf.

    # To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file

    #

    # For more information, see sysctl.conf(5) and sysctl.d(5).

    vm.max_map_count=262144

    [root@localhost ~]# sysctl -p

    vm.max_map_count = 262144

上面还有一个错误是关于jvm内存分配的问题heap size [268435456] not equal to maximum heap size [2147483648],需要修改的jvm配置

[seven@localhost bin]$ vim /usr/java/elasticsearch/config/jvm.options

将-Xmx2g改成-Xmx256m,也就是heap size [268435456] /1024/1024的值

又爆出第三个问题:max number of threads [1024] for user [lish] likely too low, increase to at least [2048]

解决方案:

# vi /etc/security/limits.d/90-nproc.conf 
# Default limit for number of user‘s processes to prevent
# accidental fork bombs. 
# See rhbz #432903 for reasoning. * soft nproc 1024 root soft nproc unlimited

修改1024 为2048 。

最后终于启动成功,并且其他机器也可以访问了

猜你喜欢

转载自blog.csdn.net/u010735147/article/details/81985309
今日推荐