groupadd elasticsearch
useradd elasticsearch -g elasticsearch
mkdir /home/elasticsearch
chown -R mkdir elasticsearch:elasticsearch /home/elasticsearch
- 下載Es:`wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.tar.gz` - 解壓Es到指定目錄:`tar -zxf elasticsearch-5.1.2.tar.gz -C /usr/local/` - 改變目錄權限:`chown -R elasticsearch:elasticsearch elasticsearch-5.1.2/` - 在Java環境變量配置好的狀況下執行後臺啓動es:`sudo ./bin/elasticsearch -d -p pid` - 關閉es:``kill `cat pid``` #pid是後臺啓動es時的進程號,文件是在/usr/local/elasticsearch-5.1.2/pid - 在服務器執行:`curl localhost:9200` - 若是有以下json返回表示安裝成功: ```json { "name" : "9bUWQKn", "cluster_name" : "elasticsearch", "cluster_uuid" : "2J3aD8mISy2A6l7JP6T4cA", "version" : { "number" : "5.1.2", "build_hash" : "c8c4c16", "build_date" : "2017-01-11T20:18:39.146Z", "build_snapshot" : false, "lucene_version" : "6.3.0" }, "tagline" : "You Know, for Search" } ```
- 下載Kibana:`wget https://artifacts.elastic.co/downloads/kibana/kibana-5.1.2-linux-x86_64.tar.gz` - 解壓:`tar -zxf kibana-5.1.2-linux-x86_64.tar.gz -C /usr/local/` - `cd /usr/local/kibana-5.1.2-linux-x86_64` - 改變kibana的擁有者爲elasticsearch:`sudo chown elasticsearch:elasticsearch -R kibana-5.1.2-linux-x86_64/` - 啓動kibana:`./bin/kibana` - 訪問:用瀏覽器http://192.168.10.10:5601/ 此時會進不去頁面 - 緣由:kibana的默認限制了訪問ip - 解決:`vim /usr/local/kibana-5.1.2-linux-x86_64/config` 將:server.host前的註釋打開,最終是:server.host: "0.0.0.0"要重啓kibana:`./bin/kibana` - 再次訪問:http://192.168.10.10:5601/ 就ok了額外說下:有了kibana了就不用安裝sense這個插件了,由於kibana 5.1.2默認集成了sense
不用elasticsearch-plugin安裝head了,直接Chrome擴展:https://chrome.google.com/web...java
在安裝es的目錄/usr/local/elasticsearch-5.1.2運行es:./bin/elasticsearch
linux
會報以下錯誤:
root@homestead:/usr/local/elasticsearch-5.1.2# ./bin/elasticsearch
2018-03-26T15:17:52,954[o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
緣由:es不能以root用戶啓動
解決:切換成elasticsearch用戶 su elasticsearch
web
./bin/elasticsearch -d -p pid
會報elasticsearch@homestead:/usr/local/elasticsearch-5.1.2$ Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
緣由:我是在Mac下安裝了Virtual Box,只分配了2g的內存,這是因爲內存不足引發的
解決:
修改es的配置文件:vim /usr/local/elasticsearch-5.1.2/config/jvm.options
將:-Xms2g
改成 -Xms1g
,若是1g還不夠的話,能夠改成-Xms512m
將:-Xmx2g
改成 -Xmx1g
,若是1g還不夠的話,能夠改成-Xmx512m
修改完jvm.options後,再執行./bin/elasticsearch -d -p pid
chrome
./bin/elasticsearch -d -p pid
會報elasticsearch@homestead:/usr/local/elasticsearch-5.1.2$ 2018-03-26 15:44:22,462 main ERROR RollingFileManager (/usr/local/elasticsearch-5.1.2/logs/elasticsearch.log) java.io.FileNotFoundException: /usr/local/elasticsearch-5.1.2/logs/elasticsearch.log (Permission denied) java.io.FileNotFoundException: /usr/local/elasticsearch-5.1.2/logs/elasticsearch.log (Permission denied)
緣由:權限不夠,致使/usr/local/elasticsearch-5.1.2/logs/elasticsearch.log日誌文件以elasticsearch的文件沒權限寫入
解決:sudo chown -R elasticsearch:elasticsearch elasticsearch-5.1.2
再次執行:./bin/elasticsearch -d -p pid
apache
main ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.RollingFileAppender
緣由:es是在java環境下運行的,因此要先安裝java,並配置好相應的環境變量
解決:如下操做在root用戶下操做將java解壓到要安裝的目錄:/usr/local/jdk1.8.0_161
配置java環境變量vim /etc/profile
在/etc/profile文件末尾添加以下幾行,根據你所安裝的目錄修改JAVA_HOME=/usr/local/jdk1.8.0_161
CLASSPATH=.:$JAVA_HOME//usr/local/jdk1.8.0_161/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
再執行source /etc/profile
生效json
如:Elasticsearch 5.1.2與Kibana 5.1.2,版本都5.1.2,不一樣版本的話,在啓動kibana時會報錯bootstrap
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
#重啓linux會失效
永久解決:sudo vim /etc/sysctl.conf
加入:vm.max_map_count=262144
再重啓linux生效vim
緣由:es的配置文件限制了指定的ip訪問,默認是服務器的locallhost:9200
,
解決:sudo vim /usr/local/elasticsearch-5.1.2/config/elasticsearch.yml
將:network.host
的註釋打開,最終是network.host: 0.0.0.0
,表示不限制訪問ipkill `cat pid
` #殺掉es進程./bin/elasticsearch -d -p pid
#啓動es
再用瀏覽器訪問:192.168.10.10:9200
瀏覽器