因為elasticsearch是用java編寫的,所以需要先安裝JDK;
jdk1.8的安裝:安裝指導
elasticsearch的下載和安裝
一、下載elasticSearch
1、下載地址: http://www.elastic.co/cn/downloads (本篇下載 elasticsearch 5.6.6)
2、使用 wget 命令下載
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.6.tar.gz
二、安裝elasticsearch
1、解壓elasticsearch到 /usr/local 目錄下
tar -zxvf elasticsearch-5.6.6.tar.gz -C /usr/local/
2、進入到解壓的elasticsearch包目錄下:cd /usr/local/elasticsearch-5.6.6/
3、啟動 ./bin/elasticsearch -d #參數 -d 指的是后台運行
4、使用 curl http://localhost:9200/ 查看是否運行,如果返回如下信息則標示運行正常:
5、elasticsearch默認restful-api的端口是9200 不支持Ip地址,只能在本機用http://localhost:9200來訪問。如果需要改變,需要修改配置文件。
默認情況下 Elasticsearch 的 RESTful 服務只有本機才能訪問,也就是說無法從主機訪問虛擬機中的服務。
可以修改 /etc/elasticsearch/config/elasticsearch.yml 文件,將注釋的 network.host 和 http.port 放開,並配置正確的IP;
cd /usr/local/elasticsearch-5.6.6 vim config/elasticsearch.yml
6、先將Elasticsearch 關閉,然后啟動;
關閉方法:輸入命令: ps -ef | grep elasticsearch ,找到進程,然后kill掉就行了;
啟動方法:輸入命令:su elastic , 然后輸入 ./bin/elasticserach -d
7、在谷歌瀏覽器中打開:http://{server_IP}:9200/
三、問題
1、問題一:啟動elasticsearch報錯如下:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
解決方法:
由於elasticsearch5.0默認分配jvm空間大小為2g,修改jvm空間分配: vim config/jvm.options
-Xms2g
-Xmx2g
修改為
-Xms512m
-Xmx512m
2、問題二:啟動elasticsearch報錯如下:org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
解決方法:
原因是elasticsearch默認是不支持用root用戶來啟動的,需要添加專門的用戶。
cd /usr/local useradd elastic chown -R elastic:elastic elasticsearch-5.6.6/ su elastic ./elasticsearch-5.6.6/bin/elasticsearch -d
3、問題三:啟動報錯如下
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1775] for user [elastic] is too low, increase to at least [2048]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決方法:
(1)[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1775] for user [elastic] is too low, increase to at least [2048]
先切換到root賬戶下面,使用 vi /etc/security/limits.conf ,增加如下內容
elastic soft nofile 65536 elastic hard nofile 65536 elastic soft nproc 2048 elastic hard nproc 2048
(2)[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
使用 vim /etc/sysctl.conf ,增加如下的內容
vm.max_map_count=262144
輸入:sysctl -p ,如下所示
(3)重新啟動elasticsearch,
su elastic cd /usr/local/elasticsearch-5.6.6 ./bin/elasticsearch -d