1. 程式人生 > >詳解centos7虛擬機器安裝elasticsearch5.0.x-安裝篇(自己做測試了,es啟動有錯誤可以在這上面找)

詳解centos7虛擬機器安裝elasticsearch5.0.x-安裝篇(自己做測試了,es啟動有錯誤可以在這上面找)

本篇文章主要介紹了centos7虛擬機器安裝elasticsearch5.0.x-安裝篇,具有一定的參考價值,感興趣的小夥伴們可以參考一下。

centos7虛擬機器安裝elasticsearch5.0.x-安裝篇

請預先安裝jdk詳細步驟請參考://www.jb51.net/softjc/193398.html

建立新使用者(非root使用者)

elasticsearch只能用非root啟動,這裡我建立了一個叫seven的使用者

?

1

2

[[email protected] ~]# useradd seven

[[email protected]

~]# passwd seven

下載elasticsearch

?

1

2

3

4

5

[[email protected] ~]# su seven

[[email protected] root]$ cd /home/seven

[[email protected] ~]$ mkdir download

[[email protected] ~]$ cd download

[[email protected] download]$ wget https://download.elastic.co

/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/5.0.0-alpha3/elasticsearch-5.0.0-alpha3.tar.gz

解壓並執行elasticsearch

解壓

?

1

[[email protected] download]$ tar -zxvf elasticsearch-5.0.0-alpha3.tar.gz

移動到指定資料夾並重命名(方便管理)

?

1

[

[email protected] download]$ mv elasticsearch-5.0.0-alpha3 /usr/java/elasticsearch

修改訪問elasticsearch的IP及埠

?

1

[[email protected] config]$ vim /usr/java/elasticsearch/config/elasticsearch.yml

找到如下程式碼段,並取消network.host及http.port所在行的註釋,修改IP及埠

?

1

2

3

4

5

6

7

8

9

10

11

12

# ---------------------------------- Network -----------------------------------

#

# Set the bind address to a specific IP (IPv4 or IPv6):

#

network.host: 192.168.0.155

#

# Set a custom port for HTTP:

#

http.port: 9200

#

# For more information, see the documentation at:

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

直接執行bin/elasticsearch檔案啟動elasticsearch

?

1

2

[[email protected] bin]$ cd /usr/java/elasticsearch/bin/

[[email protected] bin]$ ./elasticsearch

啟動時發現報錯了。。。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

[[email protected] bin]$ ./elasticsearch

[2016-06-28 13:49:27,899][INFO ][node      ] [Mondo] version[5.0.0-alpha3], pid[3671], build[cad959b/2016-05-26T08:25:57.564Z], OS[Linux/3.10.0-327.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1 .0_91/25.91-b14]

▽2016-06-28 13:49:27,900][INFO ][node      ] [Mondo] initializing ...

[2016-06-28 13:49:28,941][INFO ][plugins     ] [Mondo] modules [percolator, lang-mustache, lang-painless, ingest-grok, reindex, lang-expression, lang-groovy], plugins []

[2016-06-28 13:49:28,963][INFO ][env      ] [Mondo] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [15.7gb], net total_space [17.4gb], spins? [unknown], types [rootfs]

[2016-06-28 13:49:28,963][INFO ][env      ] [Mondo] heap size [1.9gb], compressed ordinary object pointers [true]

[2016-06-28 13:49:31,980][INFO ][node      ] [Mondo] initialized

[2016-06-28 13:49:31,980][INFO ][node      ] [Mondo] starting ...

[2016-06-28 13:49:32,115][INFO ][transport    ] [Mondo] publish_address {192.168.0.155:9300}, bound_addresses {192.168.0.155:9300}

Exception in thread "main" java.lang.RuntimeException: bootstrap checks failed

initial heap size [268435456] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents mlockall from locking the entire heap

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

please set [discovery.zen.minimum_master_nodes] to a majority of the number of master eligible nodes in your cluster

max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:125)

  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:85)

  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:65)

  at org.elasticsearch.bootstrap.Bootstrap$5.validateNodeBeforeAcceptingRequests(Bootstrap.java:183)

  at org.elasticsearch.node.Node.start(Node.java:337)

  at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:198)

  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:257)

  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:96)

  at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:91)

  at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54)

  at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:91)

  at org.elasticsearch.cli.Command.main(Command.java:53)

  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:70)

  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:63)

Refer to the log for complete error details.

[2016-06-28 13:49:32,144][INFO ][node      ] [Mondo] stopping ...

[2016-06-28 13:49:32,198][INFO ][node      ] [Mondo] stopped

[2016-06-28 13:49:32,198][INFO ][node      ] [Mondo] closing ...

[2016-06-28 13:49:32,210][INFO ][node      ] [Mondo] closed

於是我臨時提高了vm.max_map_count的大小

*此操作需要root許可權

?

1

[[email protected] ~]# sysctl -w vm.max_map_count=262144

檢視修改結果

?

1

2

[[email protected] ~]# sysctl -a|grep vm.max_map_count

vm.max_map_count = 262144

或者永久性修改

?

1

2

3

4

5

6

7

8

9

10

11

12

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

[[email protected] ~]# echo "vm.max_map_count=262144" >> /tmp/system_sysctl.conf

[[email protected] ~]# mv /tmp/system_sysctl.conf /etc/sysctl.conf

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

[[email protected] ~]# 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

[[email protected] ~]# sysctl -p

vm.max_map_count = 262144

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

?

1

[[email protected] bin]$ vim /usr/java/elasticsearch/config/jvm.options

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

又有新的錯誤。。。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

Exception in thread "main" java.lang.RuntimeException: bootstrap checks failed

initial heap size [268435456] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents mlockall from locking the entire heap

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

memory locking requested for elasticsearch process but memory is not locked

  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:125)

  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:85)

  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:65)

  at org.elasticsearch.bootstrap.Bootstrap$5.validateNodeBeforeAcceptingRequests(Bootstrap.java:183)

  at org.elasticsearch.node.Node.start(Node.java:337)

  at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:198)

  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:257)

  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:96)

  at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:91)

  at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54)

  at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:91)

  at org.elasticsearch.cli.Command.main(Command.java:53)

  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:70)

  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:63)

Refer to the log for complete error details.

[2016-06-28 14:55:49,770][INFO ][node      ] [Goldbug] stopping ...

[2016-06-28 14:55:49,875][INFO ][node      ] [Goldbug] stopped

[2016-06-28 14:55:49,875][INFO ][node      ] [Goldbug] closing ...

[2016-06-28 14:55:49,887][INFO ][node      ] [Goldbug] closed

這個問題折騰了我一下午,最後還是找到了解決方案,同樣回到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操作)

?

1

2

3

4

5

[[email protected] ~]# cp /etc/security/limits.conf /etc/security/limits.conf.bak

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

[[email protected] ~]# echo "seven hard nofile 65536" >> /tmp/system_limits.conf

[[email protected] ~]# echo "seven soft nofile 65536" >> /tmp/system_limits.conf

[[email protected] ~]# mv /tmp/system_limits.conf /etc/security/limits.conf

修改後重新登入seven使用者,使用如下命令檢視是否修改成功

?

1

2

[[email protected] ~]$ ulimit -Hn

65536

接下來就可以啟動elasticsearch了,啟動完成使用瀏覽器訪問http://192.168.0.155:9200

?

1

2

3

4

5

6

7

8

9

10

11

12

{

 "name" : "Vampire by Night",

 "cluster_name" : "elasticsearch",

 "version" : {

 "number" : "5.0.0-alpha3",

 "build_hash" : "cad959b",

 "build_date" : "2016-05-26T08:25:57.564Z",

 "build_snapshot" : false,

 "lucene_version" : "6.0.0"

 },

 "tagline" : "You Know, for Search"

}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援指令碼之家。

來源:https://www.jb51.net/article/100841.htm