一、安裝Elasticsearch
1、官網(wǎng)(https://www.elastic.co/cn/downloads/elasticsearch)下載 elasticsearch-6.3.0.tar.gz
2、使用MobaXterm登陸服務(wù)器宰睡,上傳安裝包到soft目錄下
[root@xxx] cd /
[root@xxx] mkdir soft
3租冠、解壓安裝
[root@xxx] cd /soft
[root@xxx] tar -zxvf elasticsearch-6.3.0.tar.gz
4垄惧、為方便使用搓谆,將elasticsearch-6.3.0文件夾名字修改為elasticsearch
5炒辉、配置外網(wǎng)訪問
[root@xxx elasticsearch] cd /soft/elasticsearch
[root@xxx elasticsearch-6.3.0] vim ./config/elasticsearch.yml
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0 #修改為0.0.0.0,表示讓外網(wǎng)訪問
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
# --------------------------------- 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.26.28"] #配置服務(wù)器公網(wǎng)地址
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery module documentation.
6泉手、elasticsearch不能使用超級(jí)用戶root運(yùn)行辆脸,需要建立一個(gè)賬號(hào)用于啟動(dòng)
#添加用戶
[root@xxx elasticsearch] adduser eslian
#設(shè)置密碼
[root@xxx elasticsearch] passwd eslian
7、給eslian用戶授權(quán)elasticsearch目錄
[root@xxx elasticsearch] sudo chown -R eslian /usr/elasticsearch
[root@xxx elasticsearch] sudo chgrp -R eslian /usr/elasticsearch
8螃诅、切換至elasticsearch目錄,并以eslian用戶運(yùn)行
[root@xxx elasticsearch] cd /soft/elasticsearch
[root@xxx elasticsearch] su eslian
[root@xxx elasticsearch] ./bin/elasticsearch
備注:如果想后臺(tái)運(yùn)行状囱,執(zhí)行 ./bin/elasticsearch -d
停止elasticsearch服務(wù)
#前臺(tái)啟動(dòng)术裸,使用Ctrl+C停止
#后臺(tái)運(yùn)行,使用kill -9停止
[root@xxx elasticsearch] ps -ef|grep elasticsearch
[root@xxx elasticsearch] kill -9 進(jìn)程號(hào)
9亭枷、測試是否啟動(dòng)成功
新開一個(gè)終端袭艺,用curl訪問
[root@xxx /] curl 'http://127.0.0.1:9200/?pretty'
返回下面結(jié)果證明成功
{
"name" : "4nu2-gx",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "nMlrViNkSWejHskq0cVNXw",
"version" : {
"number" : "6.3.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "424e937",
"build_date" : "2018-06-11T23:38:03.357887Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
注意:安裝完成后外部訪問(如使用Java代碼操作)elasticsearch,不要忘記開放9200端口叨粘,如果是阿里云服務(wù)器猾编,應(yīng)該給9200端口添加安全組規(guī)則。
二升敲、Elasticsearch安裝經(jīng)常報(bào)錯(cuò)的解決方法
1答倡、java.lang.RuntimeException: can not run elasticsearch as root
提示不能使用root用戶來啟動(dòng)elasticsearch
解決方法:su cylian 切換用戶來啟動(dòng)即解決
2、java.io.FileNotFoundException: /soft/elasticsearch/logs/elasticsearch.log(Permission denied)
提示權(quán)限不足
解決方法:切換到root用戶驴党,執(zhí)行上述步驟7即可
3瘪撇、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解決方法:切換到root用戶,編輯 limits.conf
vim /etc/security/limits.conf
#添加如下內(nèi)容:
* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
#注意要有*號(hào)
4港庄、max number of threads [3802] for user [eslian] is too low, increase to at least [4096]
解決方法:切換到root用戶倔既,進(jìn)入limits.d目錄下修改配置文件
vim /etc/security/limits.d/90-nproc.conf
#修改如下內(nèi)容:
* soft nproc 1024
#修改為
* soft nproc 4096
5、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決方法:切換到root用戶鹏氧,修改配置sysctl.conf
vim /etc/sysctl.conf
#添加下面配置:
vm.max_map_count=655360
#并執(zhí)行命令:
sysctl -p
配置完成后渤涌,重新啟動(dòng)elasticsearch,即可啟動(dòng)成功把还。