elasticsearch須要安裝java 8 環境,配置JAVA_HOMEjava
查看是否有舊版本的javanode
java -verison
若是沒有安裝,能夠進入官方選擇適合本身的版本,下載地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htmllinux
下載並解壓express
$ cd /usr/local/src $ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz $ tar zxvf jdk-8u171-linux-x64.tar.gz
配置環境變量bootstrap
# export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 以後加入下面內容 #jdk export JAVA_HOME=/usr/local/src/jdk1.8.0_171 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
使配置生效vim
source /etc/profile
再次驗證是否安裝成功centos
java -version
java version "1.8.0_171" Java(TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
查看變量瀏覽器
[root@VM_35_1_centos ~]# echo $JAVA_HOME /usr/local/src/jdk1.8.0_171
安裝教程位置:安全
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/install-elasticsearch.html
這裏咱們使用tar包
cd /usr/local/src wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.9.tar.gz tar zxvf elasticsearch-5.6.9.tar.gz cd elasticsearch-5.6.9/
內存配置
默認的內存配置是2g,我學習用的機子內存較小(實際2g)會掛掉,因此我將內存改爲1g(機子實際內存的一半)
vim /etc/elasticsearch/jvm.options
內容
-Xms1g -Xmx1g
啓動
./bin/elasticsearch
若是你使用root用戶啓動,則會出現下面的報錯
[2018-05-23T15:00:43,762][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:136) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.6.9.jar:5.6.9] Caused by: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-5.6.9.jar:5.6.9] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) ~[elasticsearch-5.6.9.jar:5.6.9] ... 6 more
這是出於系統安全考慮設置的條件。因爲ElasticSearch能夠接收用戶輸入的腳本而且執行,爲了系統安全考慮,
建議建立一個單獨的用戶用來運行ElasticSearch
建立elsearch用戶組及elsearch用戶
groupadd elsearch useradd elsearch -g elsearch -p elasticsearch cd /usr/local/src chown -R elsearch:elsearch elasticsearch-5.6.9
切換到elsearch用戶再啓動
su elsearch ./elasticsearch
這時你可能還會遇到下面的報錯,max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決方法是:
sudo sysctl -w vm.max_map_count=262144
再次啓動
[elsearch@VM_35_1_centos elasticsearch-5.6.9]$ ./bin/elasticsearch [2018-05-23T15:09:55,323][INFO ][o.e.n.Node ] [] initializing ... [2018-05-23T15:09:55,546][INFO ][o.e.e.NodeEnvironment ] [ndB4c4F] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [44.7gb], net total_space [49gb], spins? [unknown], types [rootfs] [2018-05-23T15:09:55,546][INFO ][o.e.e.NodeEnvironment ] [ndB4c4F] heap size [1015.6mb], compressed ordinary object pointers [true] [2018-05-23T15:09:55,547][INFO ][o.e.n.Node ] node name [ndB4c4F] derived from node ID [ndB4c4FLRxWlhH_94CN70Q]; set [node.name] to override [2018-05-23T15:09:55,548][INFO ][o.e.n.Node ] version[5.6.9], pid[3857], build[877a590/2018-04-12T16:25:14.838Z], OS[Linux/3.10.0-514.21.1.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_171/25.171-b11] [2018-05-23T15:09:55,548][INFO ][o.e.n.Node ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/usr/local/src/elasticsearch-5.6.9] [2018-05-23T15:09:57,152][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [aggs-matrix-stats] [2018-05-23T15:09:57,152][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [ingest-common] [2018-05-23T15:09:57,152][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [lang-expression] [2018-05-23T15:09:57,152][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [lang-groovy] [2018-05-23T15:09:57,153][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [lang-mustache] [2018-05-23T15:09:57,153][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [lang-painless] [2018-05-23T15:09:57,153][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [parent-join] [2018-05-23T15:09:57,153][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [percolator] [2018-05-23T15:09:57,153][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [reindex] [2018-05-23T15:09:57,153][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [transport-netty3] [2018-05-23T15:09:57,153][INFO ][o.e.p.PluginsService ] [ndB4c4F] loaded module [transport-netty4] [2018-05-23T15:09:57,153][INFO ][o.e.p.PluginsService ] [ndB4c4F] no plugins loaded [2018-05-23T15:10:00,188][INFO ][o.e.d.DiscoveryModule ] [ndB4c4F] using discovery type [zen] [2018-05-23T15:10:01,225][INFO ][o.e.n.Node ] initialized [2018-05-23T15:10:01,225][INFO ][o.e.n.Node ] [ndB4c4F] starting ... [2018-05-23T15:10:01,505][INFO ][o.e.t.TransportService ] [ndB4c4F] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300} [2018-05-23T15:10:04,656][INFO ][o.e.c.s.ClusterService ] [ndB4c4F] new_master {ndB4c4F}{ndB4c4FLRxWlhH_94CN70Q}{HfnS160SQP2XrgYtuEKX0w}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)[, ] [2018-05-23T15:10:04,728][INFO ][o.e.h.n.Netty4HttpServerTransport] [ndB4c4F] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200} [2018-05-23T15:10:04,728][INFO ][o.e.n.Node ] [ndB4c4F] started [2018-05-23T15:10:04,809][INFO ][o.e.g.GatewayService ] [ndB4c4F] recovered [0] indices into cluster_state
發現started關鍵字,而且發現監聽127.0.0.1:9200端口,elasticsearch默認監聽9200端口
使用curl測試是否安裝成功
[root@VM_35_1_centos log]# curl localhost:9200 { "name" : "ndB4c4F", "cluster_name" : "elasticsearch", "cluster_uuid" : "X0k8EhwGThCjnf-cTkSpTg", "version" : { "number" : "5.6.9", "build_hash" : "877a590", "build_date" : "2018-04-12T16:25:14.838Z", "build_snapshot" : false, "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" }
Kibana是一個爲 ElasticSearch 提供的數據分析的 Web 接口。可以使用它對日誌進行高效的搜索、可視化、分析等各類操做。
https://www.elastic.co/guide/en/kibana/5.6/install.html
cd /usr/local/src wget https://artifacts.elastic.co/downloads/kibana/kibana-5.6.9-linux-x86_64.tar.gz tar zxvf kibana-5.6.9-linux-x86_64.tar.gz cd kibana-5.6.9-linux-x86_64/
修改kibana配置,能夠外網訪問
vim ./config/kibana.yml
內容
server.port: 5601 server.host: "0.0.0.0"
能夠瀏覽器訪問xxx.xxx.xxx.xxx:5601
注意其中的Monitoring 默認是沒有的,是由X-Pack集成提供的。該X-pack監控組件使您能夠經過Kibana輕鬆地監控ElasticSearch。您能夠實時查看集羣的健康和性能,以及分析過去的集羣、索引和節點度量。此外,能夠監視Kibana自己性能。
Elasticsearch下載X-Pack
在Es的根目錄(每一個節點),運行 bin/elasticsearch-plugin進行安裝。
bin/elasticsearch-plugin install x-pack
若是你在Elasticsearch已禁用自動索引的建立,在elasticsearch.yml配置action.auto_create_index容許X-pack創造如下指標:
action.auto_create_index: ".security*,.monitoring*,.watches,.triggered_watches,.watcher-history*"
Kibana下載X-Pack
在Kibana根目錄運行 bin/kibana-plugin 進行安裝。
bin/kibana-plugin install x-pack
實際上一個服務器只會部署一個節點,可是爲了學習elasticsearch的分佈特性,這裏探索啓動多個節點。
使用elasticsearch-5.6.9再複製一份,而後更改用戶組
cd /usr/local/src cp -r elasticsearch-5.6.9 elastic-slave1 chown -R elsearch:elsearch elastic-slave1
因爲內存過小,因此再次調整了master和slave的配置
/usr/local/src/elasticsearch-5.6.9/config/jvm.options
/usr/local/src/elastic-slave1/config/jvm.options
-Xms256m -Xmx256m
/usr/local/src/elasticsearch-5.6.9/config/elasticsearch.yml
cluster.name: test node.name: master node.master: true network.host: 127.0.0.1 action.auto_create_index: ".security*,.monitoring*,.watches,.triggered_watches,.watcher-history*"
/usr/local/src/elastic-slave1/config/elasticsearch.yml
cluster.name: test node.name: slave1 network.host: 127.0.0.1 http.port: 8200 discovery.zen.ping.unicast.hosts: ["127.0.0.1"] action.auto_create_index: ".security*,.monitoring*,.watches,.triggered_watches,.watcher-history*"
分別運行master和slave的程序
./bin/elasticsearch
運行kibana
./bin/kibana
在瀏覽器上輸入: http://xxx.xxx.xxx.xxx:5601/
,打開Kibana,要輸入用戶名和密碼登陸,默認分別是 elastic
和 changeme
,能夠很方便的看到節點的狀況
注意:複製的elastic-salve1文件夾下包含了data文件中源文件節點數據,須要把elastic-salve1文件夾下data文件下的文件清空,不然會出現下面相似錯誤。
[2018-05-23T17:52:48,839][INFO ][o.e.d.z.ZenDiscovery ] [slave-2] failed to send join request to master [{master}{iErWGFrwSuCTjXaOD9jE5g}{JHJNb1U_TVaqdNVoJmEBZw}{127.0.0.1}{127.0.0.1:9300}{ml.max_open_jobs=10, ml.enabled=true}], reason [RemoteTransportException[[master][127.0.0.1:9300][internal:discovery/zen/join]]; nested: IllegalArgumentException[can't add node {slave-2}{iErWGFrwSuCTjXaOD9jE5g}{uo1SvmJyTESE_Z6bcQrOeg}{127.0.0.1}{127.0.0.1:9301}{ml.max_open_jobs=10, ml.enabled=true}, found existing node {master}{iErWGFrwSuCTjXaOD9jE5g}{JHJNb1U_TVaqdNVoJmEBZw}{127.0.0.1}{127.0.0.1:9300}{ml.max_open_jobs=10, ml.enabled=true} with the same id but is a different node instance]; ]
http://www.ruanyifeng.com/blog/2017/08/elasticsearch.html
https://www.cnblogs.com/wxw16/p/6156335.html