centos 下安裝 elastic search 啓動的問題

正常步驟html

1Download and unzip Elasticsearchjava

2 Run bin/elasticsearch node

3 Run curl http://localhost:9200/vim

 

異常信息:app

root 帳戶啓動報錯,Exception in thread "main" Java.lang.RuntimeException: don't run elasticsearch as root.curl

解決辦法:jvm

 

 

解決方法1:elasticsearch

在執行elasticSearch時加上參數-Des.insecure.allow.root=true,完整命令以下ide

[plain] view plain copyui

 在CODE上查看代碼片派生到個人代碼片

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

解決辦法2:

 

用vi打開elasicsearch執行文件,在變量ES_JAVA_OPTS使用前添加如下命令

[plain] view plain copy

 在CODE上查看代碼片派生到個人代碼片

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

 

解決辦法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. # --------------------------------- Discovery ----------------------------------

  2. #

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

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

  5. #

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

  7. #

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

  9. #

  10. discovery.zen.minimum_master_nodes: 3

  11. #

  12. # For more information, see the documentation at:

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

 

而後修改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用戶,使用以下命令查看是否修改爲功

 
  1. [seven@localhost ~]$ ulimit -Hn

  2. 65536

 

 

第2個問題:解決方案:

 

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

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

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

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

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

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

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

  8. #

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

  10. vm.max_map_count=262144

  11. [root@localhost ~]# sysctl -p

  12. vm.max_map_count = 262144

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

 

上面還有一個錯誤是關於jvm內存分配的問題heap size [268435456] not equal to maximum heap size [2147483648],須要修改的jvm配置

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

將-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 。

 

最後終於啓動成功,而且其餘機器也能夠訪問了。

相關文章
相關標籤/搜索