一、下載安裝
-
下載
到官網(wǎng)找到對應(yīng)版本的下載鏈接蠢笋,用wget命令下載 下載地址
[root@localhost es]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.tar.gz
--2018-12-05 16:29:27-- https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.tar.gz
正在解析主機(jī) artifacts.elastic.co (artifacts.elastic.co)... 54.225.221.128, 107.21.127.184, 107.21.202.15, ...
正在連接 artifacts.elastic.co (artifacts.elastic.co)|54.225.221.128|:443... 已連接。
已發(fā)出 HTTP 請求麦箍,正在等待回應(yīng)... 200 OK
長度:33781024 (32M) [binary/octet-stream]
正在保存至: “elasticsearch-5.6.8.tar.gz”
100%[=================================================================>] 33,781,024 1.14MB/s 用時(shí) 30s
2018-12-05 16:29:59 (1.06 MB/s) - 已保存 “elasticsearch-5.6.8.tar.gz” [33781024/33781024])
- 解壓
[root@localhost es]# tar -zxf elasticsearch-5.6.8.tar.gz
-
建立軟鏈接
習(xí)慣建一個(gè)目錄管理所有應(yīng)用的軟件界(為了個(gè)人方便而已)
[root@localhost /]# ln -s /develop/es/elasticsearch-5.6.8/ /shortcut/es
[root@localhost /]# cd shortcut/
[root@localhost shortcut]# ll
總用量 0
lrwxrwxrwx. 1 root root 32 12月 5 16:56 es -> /develop/es/elasticsearch-5.6.8/
-
新建用戶
es 5以上都不允許用root用戶啟動(dòng)畜普,如果用root啟動(dòng)會出現(xiàn)以下錯(cuò)誤:can not run elasticsearch as root
[root@localhost elasticsearch-5.6.8]# bin/elasticsearch
[2018-12-05T16:40:00,801][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.8.jar:5.6.8]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.8.jar:5.6.8]
...
新建一個(gè)叫es用戶,并為es設(shè)置密碼
[root@localhost es]# useradd es
[root@localhost es]# passwd es
給es賬號賦權(quán)
[root@localhost es]# chown -R es /develop/es/elasticsearch-5.6.8
- 啟動(dòng)es
[es@localhost es]$bin/elasticsearch
[2018-12-06T11:29:07,535][INFO ][o.e.n.Node ] [] initializing ...
[2018-12-06T11:29:17,825][INFO ][o.e.h.n.Netty4HttpServerTransport] [5nNJgP4]
publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2018-12-06T11:29:17,825][INFO ][o.e.n.Node ] [5nNJgP4] started
這樣子變啟動(dòng)成功了。 可以訪問對應(yīng)的127.0.0.1:9200 看到以下結(jié)果:
[root@localhost ~]# curl 127.0.0.1:9200
{
"name" : "5nNJgP4",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "aek3sfxyRjeMfvgrK-jB0Q",
"version" : {
"number" : "5.6.8",
"build_hash" : "688ecce",
"build_date" : "2018-02-16T16:46:30.010Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}
這時(shí)候es就算安裝成功了欢瞪。
-
設(shè)置為可被外部訪問的ip
這時(shí)候并不能用ip訪問es,如下圖
[root@localhost es]# curl 192.168.24.152::9200
curl: (6) Could not resolve host: 192.168.24.152:; 未知的名稱或服務(wù)
所以需要修改對應(yīng)配置文件信息
- 修改elasticsearch.yml,設(shè)置host 跟port
[root@localhost ~]# vim /develop/es/elasticsearch-5.6.8/config/elasticsearch.yml
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
- 這時(shí)候啟動(dòng)會遇到下面問題
[2018-12-06T14:01:48,138][INFO ][o.e.b.BootstrapChecks ] [5nNJgP4] bound or publishing to a
non-loopback address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[1]max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
原因:無法創(chuàng)建本地文件問題,用戶最大可創(chuàng)建文件數(shù)太小
解決方案:
切換到root用戶徐裸,編輯limits.conf配置文件遣鼓, 添加類似如下內(nèi)容:
vim /etc/security/limits.conf
添加如下內(nèi)容:
* hard nofile 65536
* soft nofile 65536
備注: * 代表Linux所有用戶名稱(比如 es)保存、退出重贺、重新登錄才可生效
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
原因:最大虛擬內(nèi)存太小
解決方案:切換到root用戶下骑祟,修改配置文件sysctl.conf
vim /etc/sysctl.conf
添加下面配置
vm.max_map_count=655360
并執(zhí)行
[root@localhost ~]# sysctl -p
vm.max_map_count = 655360
注意:這時(shí)候還不能訪問需要關(guān)閉防火墻或者開放9200端口
centos7防火墻設(shè)置
- 問題解決
[root@localhost es]# curl 192.168.24.152:9200
{
"name" : "5nNJgP4",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "aek3sfxyRjeMfvgrK-jB0Q",
"version" : {
"number" : "5.6.8",
"build_hash" : "688ecce",
"build_date" : "2018-02-16T16:46:30.010Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}