Elasticsearch-01 安装部署

前言

这里以官方提供的默认版本 Elasticsearch v7.17.0 为例进行学习笔记的记录
打算应用到项目中,作为APP埋点数据的存储、查询统计
下载地址
官方教程
安装配置官方教程
elasticsearch.yml 用户配置
Elasticsearch-01 安装部署_第1张图片

1. 将官网下载好的包上传至服务器并解压

解压

tar zxvf elasticsearch-7.17.0-linux-x86_64.tar.gz

2. 修改 elasticsearch.yml 配置文件

开启自动创建索引,添加如下配置

action.auto_create_index: .monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*
# 启动时锁定内存
bootstrap.memory_lock: true

3. 修改 jvm.options

设置合适的堆内存大小,默认是4GB,由于是开发服务器,我这里先配置1GB
Elasticsearch-01 安装部署_第2张图片

4. 创建 es 用户组 及 es 用户,授权

以es用户启动应用(直接以root启动会报错)

  • 创建用户组及用户
groupadd es
useradd es -g es
passwd es
  • 更改es文件夹及内部文件的所属用户及组为es:es
chown -R es:es elasticsearch-7.17.0/
  • 4.3 切换到es用户并启动
su es
./bin/elasticsearch

5. 启动报错

ERROR: [3] bootstrap checks failed. You must address the points described in the following [3] lines before starting Elasticsearch.
bootstrap check failure [1] of [3]: memory locking requested for elasticsearch process but memory is not locked
bootstrap check failure [2] of [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
bootstrap check failure [3] of [3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /usr/local/elasticsearch-7.17.0/logs/elasticsearch.log

5.1. memory locking requested for elasticsearch process but memory is not locked

  • 修改文件/etc/security/limits.conf,最后添加以下内容
# es用户组可以打开的最大的文件描述符数量,默认1024,这里的数值会限制tcp连接
# soft 是警告值,hard是阀值、超过则报错,* 代表所有用户
@es soft nofile 65536
@es hard nofile 65536

# es用户组可以打开的最大进程数
@es soft nproc 32000
@es hard nproc 32000

# 不限制锁定内存大小
@es hard memlock unlimited
@es soft memlock unlimited

● 修改文件 /etc/systemd/system.conf

DefaultLimitNOFILE=65536
DefaultLimitNPROC=32000
DefaultLimitMEMLOCK=infinity

5.2. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

● 修改 /etc/sysctl.conf,末尾添加如下配置

vm.max_map_count=262144

reboot重启后前两个异常解决了

5.3. the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

添加集群配置,参考官方配置文件

# 集群名称
cluster.name: deao-es-cluster
# 节点名称
node.name: node18
# 集群节点列表,多个节点逗号隔开
discovery.seed_hosts: ["192.168.2.18:9300"]
# 初始化master节点
cluster.initial_master_nodes: ["192.168.2.18:9300"]

6. 启动

# 以守护线程启动es
./bin/elasticsearch -d -p pid

# 结束进程
pkill -F pid

-d 以守护线程启动
-p 记录进程ID到pid文件

PS: 记得给防火墙开启 9200 的web端口和 9300 的通信端口

Elasticsearch-01 安装部署_第3张图片

OK,这算是部署完毕了

ps: 补充一下跨域配置,在elasticsearch中添加如下配置
以 / 开头的时候,支持正则匹配(这个我没测试)

http:
    cors:
        enabled: true
        allow-origin: "*"

你可能感兴趣的:(elasticsearch,elasticsearch,搜索引擎,大数据)