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可行