Elasticsearch簡介
ElasticSearch 是一個高可用開源全文檢索和分析組件。提供存儲服務,搜索服務,大數據準實時分析等。一般用於提供一些提供複雜搜索的應用。
第一步:Elasticsearch下載
下載地址:https://www.elastic.co/downloads/elasticsearch
下載下來壓縮包爲elasticsearch-6.2.3.zip。請使用unzip elasticsearch-6.2.3.zip解壓至/opt目錄
第二步:安裝前準備
IP及端口分配:
IP | 服務端口 | 節點通訊端口 |
10.100.104.135 | 9200 | 9300(默認) |
10.100.104.136 | 9200 | 9300 |
10.100.104.137 | 9200 | 9300 |
防火牆中打開相應的端口(所有的機器都執行,都是使用root用戶)
# firewall-cmd --zone=public --add-port=9200/tcp --permanent
# firewall-cmd --zone=public --add-port=9300/tcp --permanent
# systemctl restart firewalld.service
第三步:Elasticsearch安裝
- cd /opt/elasticsearch-6.2.3進入elasticsearch解壓目錄
- 創建數據、日誌目錄
mkdir data
mkdir logs 修改elasticsearch.yml配置文件,修改內容如下:elasticsearch.yml
#集羣名稱,每臺機器必須一致
cluster.name: hdcms-es
#節點名稱,每臺機器必須不一致
node.name: node-1
#存儲數據路徑
path.data: /opt/elasticsearch-6.2.3/data
#存儲日誌路徑
path.logs: /opt/elasticsearch-6.2.3/logs
#鎖定內存,爲了提供檢索效率
bootstrap.memory_lock: true
#綁定ip, 每臺機器ip地址
network.host: 10.100.104.135
# http restful端口,提供外部訪問
http.port: 9200
# 機器unicast機器ip
discovery.zen.ping.unicast.hosts:["10.100.104.135","10.100.104.136", "10.100.104.137"]
#設置這個參數來保證集羣中的節點可以知道其它N個有master資格的節點,推薦 (n/2 + 1)
discovery.zen.minimum_master_nodes: 2
#設置集羣中N個節點啓動時進行數據恢復,默認爲1
gateway.recover_after_nodes: 1
#跨域訪問
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true創建用戶elasticsearch,由於elasticsearch不允許root用戶運行,需要創建其他用戶運行
# groupadd elasticsearch
# useradd elasticsearch -g elasticsearch
# chown -R elasticsearch:elasticsearch /opt/elasticsearch-6.2.3修改鎖定內存及用戶最大可創建文件數
vim /etc/security/limits.conf,添加內容如下:
elasticsearch soft nofile 65536
elasticsearch hard nofile 131072
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
保存退出,臨時取消限制:ulimit -l unlimited- 修改最大虛擬內存
vim /etc/sysctl.conf,添加以下配置
vm.max_map_count=655360
保存退出,並執行命令: sysctl -p - reboot重啓服務器,使配置生效
第四步:啓動Elasticsearch
- su elasticsearch,使用elasticsearch用戶啓動
- /opt/elasticsearch-6.2.3/bin/elasticsearch -d,以守護進程啓動elasticsearch
第五步:驗證Elasticsearch集羣
- 查看集羣健康
curl -XGET 'http://10.100.104.135:9200/_cluster/health?pretty' - 查看master節點(由於採用默認配置,master節點沒指定,會自動選舉)
curl 10.100.104.136:9200/_cat/master?v - 查看集羣有多少個節點, master用 * 標註
curl 10.100.104.136:9200/_cat/nodes?v
問題及解決方案
- elasticsearch客戶端head plugin,需要安裝nodejs,要求服務器能訪問外網
- 注意springboot與elasticsearch的版本,本人安裝6.2.3最終會導致springboot 1.5.8啓動錯誤,降爲2.4.5可行