ES elasticsearch的安装和配置

1 资源下载

CSDN下载地址: https://download.csdn.net/download/qq_15769939/15465621

2 ES服务部署

目前安装的服务器是elasticsearch,下面简称为ES。它的版本号是 7.4.2,使用的Linux操作系统是Centos7

2.1 上传资源到服务器

将文件上传到服务器的 /opt/module/software目录下

[root@localhost ~]# cd /opt/module/software
[root@localhost software]# ll
总用量 289356
-rw-r--r--. 1 root   root   288775500 2月  22 21:45 elasticsearch-7.4.2-linux-x86_64.tar.gz.zip
[root@localhost software]# unzip elasticsearch-7.4.2-linux-x86_64.tar.gz.zip
[root@localhost software]# tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz 
[root@localhost software]# mv elasticsearch-7.4.2 /usr/local
[root@localhost local]# cd /usr/local/elasticsearch-7.4.2
[root@localhost elasticsearch-7.4.2]# mkdir data
[root@localhost elasticsearch-7.4.2]# ll
总用量 556
drwxr-xr-x.  2 esuser esuser   4096 10月 29 2019 bin
drwxr-xr-x.  2 esuser esuser    178 2月  22 23:08 config
drwxr-xr-x.  3 esuser esuser     19 2月  22 22:07 data
drwxr-xr-x.  9 esuser esuser    107 10月 29 2019 jdk
drwxr-xr-x.  3 esuser esuser   4096 10月 29 2019 lib
-rw-r--r--.  1 esuser esuser  13675 10月 29 2019 LICENSE.txt
drwxr-xr-x.  2 esuser esuser   4096 2月  24 10:39 logs
drwxr-xr-x. 37 esuser esuser   4096 10月 29 2019 modules
-rw-r--r--.  1 esuser esuser 523209 10月 29 2019 NOTICE.txt
drwxr-xr-x.  3 esuser esuser     16 2月  24 13:36 plugins
-rw-r--r--.  1 esuser esuser   8500 10月 29 2019 README.textile

2.2 ES目录介绍

  • bin:可执行脚本文件,包含ES的启动脚本
  • config:配置文件目录
  • JDK: java环境
  • lib:依赖的jar,类库
  • logs:日志文件
  • modules:ES相关模块
  • plugins:插件位置
  • data:自定义的索引存储目录

2.3 修改核心配置文件

[root@localhost config]#  vi /usr/local/elasticsearch-7.4.2/config/elasticsearch.yml 
  • 修改集群名称,默认是elasticsearch

  • 为当前的es节点设置名称,集群环境中需要特殊设置,不能重复

    # Use a descriptive name for your cluster:
    #
    cluster.name: auskat-elasticsearch
    
    #
    # Use a descriptive name for the node:
    #
    node.name: es-node1
    
  • 修改data数据保存路径

  • 修改日志数据保存路径

    # ----------------------------------- Paths ------------------------------------
    #
    # Path to directory where to store the data (separate multiple locations by comma):
    #
    path.data: /usr/local/elasticsearch-7.4.2/data
    #
    # Path to log files:
    #
    path.logs: /usr/local/elasticsearch-7.4.2/logs
    
  • 绑定es网络ip,允许外部访问

  • 默认端口号,看需要是否需要修改

  • 9200端口:Http协议,用于外部通讯

  • 9300端口:Tcp协议,ES集群之间的通讯

    # ---------------------------------- 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
    
  • 集群节点,当前单机版,填写上面的节点名称就可以

    # Bootstrap the cluster using an initial set of master-eligible nodes:
    #
    cluster.initial_master_nodes: ["es-node1"]
    

2.4 修改JVM参数

因为是虚拟机的linux下安装的elasticsearch服务,JVM内存设置太大会比较卡,看个人需求来定,我这里将默认的xms和xmx的1g大小都更改为514M。

[root@localhost config]#  vi /usr/local/elasticsearch-7.4.2/config/jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
# -Xms1g
# -Xmx1g
-Xms514m
-Xmx514m

2.5 添加用户

因为ES不允许使用root操作es,需要添加用户

[root@localhost config]# useradd esuser
[root@localhost config]# chown -R esuser:esuser /usr/local/elasticsearch-7.4.2

2.6 启动ES

2.6.1 启动报错

root@localhost config]# su esuser
[esuser@localhost config]$ whoami
esuser
root@localhost config]# cd /usr/local/elasticsearch-7.4.2/bin
root@localhost bin]# ./elasticsearch
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low,increase to at least [65535]
[2]: max number of threads [3756] for user [esuser] is too low,increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low,increase to at least [262144]

2.6.2 修改插入认证模式

Linux PAM: Pluggable Authentication Modules

[esuser@localhost config]$ su root
密码:
[root@localhost config]# vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
* 表示用户,* 表示所有用户
soft nproc 单个用户可用的最大进程数量(超过会警告);
hard nproc 单个用户可用的最大进程数量(超过会报错);
soft nofile 可打开的文件描述符的最大数(超过会警告);
hard nofile 可打开的文件描述符的最大数(超过会报错);

2.6.3 修改系统核心配置

[root@localhost config]# vi /etc/sysctl.conf
vm.max_map_count=262145
[root@localhost bin]# sysctl -p
vm.max_map_count = 262145

2.6.4 重新启动

root@localhost config]# su esuser
[esuser@localhost config]$ whoami
esuser
root@localhost config]# cd /usr/local/elasticsearch-7.4.2/bin

2.6.4.1 前台启动

root@localhost bin]# ./elasticsearch

2.6.4.2 后台启动

root@localhost bin]# ./elasticsearch -d

2.7 测试

虚拟机的IP + 9200即可访问ES服务

在这里插入图片描述

2.8 停止ES服务

2.8.1 前台启动停止

ctrl + c 直接停止命令行就可以

2.8.2 后台启动停止

[root@localhost config]# jps
28696 Elasticsearch
29977 Jps
[root@localhost config]# kill 28696

3 相关信息

  • 博文不易,辛苦各位猿友点个关注和赞,感谢

猜你喜欢

转载自blog.csdn.net/qq_15769939/article/details/114249211