微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

3 centos 下安装 elastic search 启动的问题

正常步骤

1Download and unzip Elasticsearch

2Run bin/elasticsearch

3Run 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,完整命令如下

[plain] view plain copy
  1. ./elasticsearch-Des.insecure.allow.root=true
解决办法2:

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


解决办法3:

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

groupadd elsearch

useradd es -g elsearch -p 123456


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

chown -R elsearch:elsearch 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 提供了解决办法:

/usr/local/share/elasticsearch-5.1.1/config 目录下有一个 文件elasticsearch.yml

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

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


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

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

2 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

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
# --------------------------------- 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

# cat /etc/security/limits.conf | grep -v "seven" > /tmp/system_limits.conf

# echo "seven hard nofile 65536" >> /tmp/system_limits.conf

# echo "seven soft nofile 65536" >> /tmp/system_limits.conf

# mv /tmp/system_limits.conf /etc/security/limits.conf

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

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

[seven@localhost ~]$ ulimit -Hn
65536


第2个问题:解决方案:

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • [root@localhost ~]# cat /etc/sysctl.conf | grep -v "vm.max_map_count" > /tmp/system_sysctl.conf [root# echo "vm.max_map_count=262144" >> /tmp/system_sysctl.conf [root# mv /tmp/system_sysctl.conf /etc/sysctl.conf mv:是否覆盖"/etc/sysctl.conf"? y [root# 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# sysctl -p vm.max_map_count = 262144

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

      
      
  • 1
  • [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 users processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.
    
    *          soft    nproc     1024
    root       soft    nproc     unlimited

    修改1024 为2048 。


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

    原文地址:https://www.jb51.cc/centos/379371.html

    版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。