1.安装Elasticsearch

目录:
1.安装Elasticsearch
2.Elasticsearch概念
3.Elasticsearch索引
4.Elasticsearch查询
5.Elasticsearch聚合aggregations
6.Spring Data Elasticsearch入门
7.Repository文档操作

一、单机

1、CentOS版本

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core) 

2、安装

[root@localhost opt]# tar -zxvf elasticsearch-6.2.4.tar.gz 
[root@localhost opt]# mv elasticsearch-6.2.4 /usr/local/elasticsearch

3、编辑jvm.options

[root@localhost config]# vim jvm.options 
# 内存调小
-Xms512m
-Xmx512m

4、编辑elasticsearch.yml

# 创建目录
[root@localhost elasticsearch]# mkdir data
# 编辑elasticsearch.yml
[root@localhost config]# vim elasticsearch.yml
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs
network.host: 0.0.0.0 # 绑定到0.0.0.0,允许任何ip来访问

elasticsearch.yml的其它可配置信息:

属性名说明
cluster.name配置elasticsearch的集群名称,默认是elasticsearch。建议修改成一个有意义的名称。
node.name节点名,es会默认随机指定一个名字,建议指定一个有意义的名称,方便管理
path.conf设置配置文件的存储路径,tar或zip包安装默认在es根目录下的config文件夹,rpm安装默认在/etc/ elasticsearch
path.data设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开
path.logs设置日志文件的存储路径,默认是es根目录下的logs文件夹
path.plugins设置插件的存放路径,默认是es根目录下的plugins文件夹
bootstrap.memory_lock设置为true可以锁住ES使用的内存,避免内存进行swap
network.host设置bind_host和publish_host,设置为0.0.0.0允许外网访问
http.port设置对外服务的http端口,默认为9200。
transport.tcp.port集群结点之间通信端口
discovery.zen.ping.timeout设置ES自动发现节点连接超时的时间,默认为3秒,如果网络延迟高可设置大些
discovery.zen.minimum_master_nodes主结点数量的最少值 ,此值的公式为:(master_eligible_nodes / 2) + 1 ,比如:有3个符合要求的主结点,那么这里要设置为2

5、运行

# 创建用户并授权
[root@localhost bin]# adduser elasticsearch
[root@localhost bin]# chown -R elasticsearch /usr/local/elasticsearch
# 切换用户
[root@localhost bin]# su elasticsearch
# 运行
[elasticsearch@localhost bin]$ /usr/local/elasticsearch/bin/elasticsearch

6、报错及解决

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]

编辑 /etc/security/limits.conf,追加以下内容;

* soft nofile 65536
* hard nofile 65536

编辑 /etc/sysctl.conf,追加以下内容:

vm.max_map_count=655360
# 保存后,执行:
[root@localhost security]# sysctl -p

7、端口

9300:集群节点间通讯接口
9200:客户端访问接口

8、安装ik分词器

下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases

[elasticsearch@localhost bin]$ cd /usr/local/elasticsearch/plugins/
[elasticsearch@localhost plugins]$ cp /var/opt/elasticsearch-analysis-ik-6.2.4.zip .
[elasticsearch@localhost plugins]$ unzip elasticsearch-analysis-ik-6.2.4.zip -d ik-analyzer
# 重启elasticsearch

二、集群

编辑elasticsearch.yml

# 集群名,自定义集群名。每个节点都一样。
cluster.name: dxb-es-cluster

# 节点名,同一集群下要求每个节点的节点名不一致,起到区分节点和辨认节点作用
node.name: es-node-1

# 是否为主节点,选项为true或false,当为true时在集群启动时该节点为主节点,在宕机或任务挂掉之后会选举新的主节点,恢复后该节点依然为主节点
node.master: true

# 是否处理数据,选项为true或false。负责数据的相关操作
node.data: true

# 默认数据路径,可用逗号分隔多个路径
path.data: /usr/local/elasticsearch/data

# 默认日志路径
path.logs: /usr/local/elasticsearch/logs

# 内存锁,选项为true或false,用来确保用户在es-jvm中设置的ES_HEAP_SIZE参数内存可以使用一半以上而又不溢出
#bootstrap.mlockall: true

# 对外暴露的host,0.0.0.0时暴露给外网
network.host: 0.0.0.0
# Set a custom port for HTTP:
# 对外访问的端口号,默认为9200
http.port: 9200

# 集群间通信的端口号,默认为9300
transport.tcp.port: 9300

# 集群的ip集合,可指定端口,默认为9300
discovery.zen.ping.unicast.hosts: ["192.168.20.133", "192.168.20.134", "192.168.20.135"]

# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
# 最少的主节点个数,为了防止脑裂,最好设置为(总结点数/2 + 1)个
#discovery.zen.minimum_master_nodes: 2

# 主节点选举超时时间设置
#discovery.zen.ping_timeout

# 值为n,网关控制在n个节点启动之后才恢复整个集群
#gateway.recover_after_nodes: 3

# 值为n,一个系统中最多启用节点个数为n
#node.max_local_storage_nodes

# 选项为true或false,删除indices是否需要现实名字
#action.destructive_requires_name: true

运行

# 创建用户并授权
[root@localhost bin]# chown -R elasticsearch /usr/local/elasticsearch-cluster/
# 切换用户
[root@localhost bin]# su elasticsearch
# 运行
[elasticsearch@localhost bin]$ /usr/local/elasticsearch-cluster/elasticsearch-m/bin/elasticsearch -d
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值