Linux系统
下载&解压
下载地址:www.elastic.co/cn/download…
[root@localhost local]# tar -xvf elasticsearch-8.1.0-linux-x86_64.tar.gz
[root@localhost local]# rm -rf elasticsearch-8.1.0-linux-x86_64.tar.gz && mv elasticsearch-8.1.0 es
创建用户
创建 Elasticsearch用户 并赋予 Elasticsearch安装目录 权限,这是 Elasticsearch 的一种安全措施(不能使用
root用户)。
创建一个esroot用户并设置初始密码
[root@localhost es]# useradd -c 'ES user' -d /home/esroot esroot
[root@localhost es]# passwd esroot
更改用户 esroot 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
将Elasticsearch安装目录属主权限改为 esroot 用户
[root@localhost es]# chown -R esroot:esroot /usr/local/es
切换用户到 esroot
[root@localhost es]# su esroot
目录结构
[esroot@localhost es]$ mkdir data
[esroot@localhost es]$ ll
总用量 860
drwxr-xr-x. 2 esroot esroot 4096 3月 3 2022 bin
drwxr-xr-x. 3 esroot esroot 210 9月 4 20:41 config
drwxrwxr-x. 2 esroot esroot 6 9月 4 20:53 data
drwxr-xr-x. 9 esroot esroot 121 3月 3 2022 jdk
drwxr-xr-x. 3 esroot esroot 4096 3月 3 2022 lib
-rw-r--r--. 1 esroot esroot 3860 3月 3 2022 LICENSE.txt
drwxr-xr-x. 2 esroot esroot 6 3月 3 2022 logs
drwxr-xr-x. 66 esroot esroot 4096 3月 3 2022 modules
-rw-r--r--. 1 esroot esroot 858797 3月 3 2022 NOTICE.txt
drwxr-xr-x. 2 esroot esroot 6 3月 3 2022 plugins
-rw-r--r--. 1 esroot esroot 2710 3月 3 2022 README.asciidoc
bin:脚本文件,包括启动 elasticsearch,安装插件。运行统计数据等
config:配置文件
jdk:Java 运行环境
data:数据文件
lib:Java 类库
logs:日志文件
modules:包含所有 ES 模块
plugins:包含所有已安装插件
配置
[esroot@localhost es]$ cd config/
[esroot@localhost config]$ ll
总用量 40
-rw-rw----. 1 esroot esroot 1042 3月 3 2022 elasticsearch-plugins.example.yml
-rw-rw----. 1 esroot esroot 2730 3月 3 2022 elasticsearch.yml
-rw-rw----. 1 esroot esroot 2992 3月 3 2022 jvm.options
drwxr-x---. 2 esroot esroot 6 3月 3 2022 jvm.options.d
-rw-rw----. 1 esroot esroot 16644 3月 3 2022 log4j2.properties
-rw-rw----. 1 esroot esroot 473 3月 3 2022 role_mapping.yml
-rw-rw----. 1 esroot esroot 197 3月 3 2022 roles.yml
-rw-rw----. 1 esroot esroot 0 3月 3 2022 users
-rw-rw----. 1 esroot esroot 0 3月 3 2022 users_roles
elasticsearch.yml:ES 启动基础配置
jvm.options:ES 启动JVM配置
log4j2.properties:ES 日志输出配置文件
jvm.options
配置建议
- Xms、Xmx设置为一致
- Xmx不要超过机器内存50%
- 不要超过30GB(JVM 在内存小于 32 GB 的时候会采用一个内存对象指针压缩技术)
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## which should be named with .options suffix, and the min and
## max should be set to the same value. For example, to set the
## heap to 4 GB, create a new file in the jvm.options.d
## directory containing these lines:
##
-Xms256m
-Xmx256m
进程数&线程数
该配置会在下个会话生效,需要重新连接。
在/etc/security/limits.conf 文件最后添加(root用户)
每个进程最大同时打开文件数太小
# 每个进程最大同时打开文件数太小
* soft nofile 65536
* hard nofile 65536
# 最大线程个数太低
* soft nproc 4096
* hard nproc 4096
root soft nofile 65536
root hard nofile 131072
elasticsearch soft nofile 65536
elasticsearch hard nofile 131072
elasticsearch.yml
集群名称
默认是被注释的,并且默认有一个集群名
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
节点名称
默认是被注释的,并且默认有一个节点名
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
路径
用逗号分隔多个位置
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch/logs
#
network
设置0.0.0.0可以让任何人访问到你的 Elasticsearch(生产环境设置安全组),设置一个http请求端口(默认 9200)
# ---------------------------------- 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
#
# For more information, consult the network module documentation.
#
master节点列表
集群启动时,master节点列表(用逗号分隔,目前单机所以只配置了一个)
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
vm.max_map_count
[root@localhost logs]# vi /etc/sysctl.conf
vm.max_map_count=655360
查看是否修改成功
[root@localhost ~]# sysctl -p
vm.max_map_count = 655360
启动
[esroot@localhost es]$ /usr/local/es/bin/elasticsearch -d
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.
ℹ️ Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
aRngyBFJ4KTO1FKRKeL_
ℹ️ HTTP CA certificate SHA-256 fingerprint:
4bcdd2a5e9d6c90a2047baf7a8b0b656d1239dc2f53d964588a6824d9336f6f0
ℹ️ Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjEuMCIsImFkciI6WyIxOTIuMTY4LjEuOTo5MjAwIl0sImZnciI6IjRiY2RkMmE1ZTlkNmM5MGEyMDQ3YmFmN2E4YjBiNjU2ZDEyMzlkYzJmNTNkOTY0NTg4YTY4MjRkOTMzNmY2ZjAiLCJrZXkiOiIwQUYzWUlvQmw1Ujd0cUNNcXdnQTp0OC0wYXgyeFRUU1F3UTdnVnVZcTRBIn0=
ℹ️ Configure other nodes to join this cluster:
• Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjEuMCIsImFkciI6WyIxOTIuMTY4LjEuOTo5MjAwIl0sImZnciI6IjRiY2RkMmE1ZTlkNmM5MGEyMDQ3YmFmN2E4YjBiNjU2ZDEyMzlkYzJmNTNkOTY0NTg4YTY4MjRkOTMzNmY2ZjAiLCJrZXkiOiJ6Z0YzWUlvQmw1Ujd0cUNNcWdqVzpKODNlSm94bFI4S25nTlpBM1ZPeWpnIn0=
If you're running in Docker, copy the enrollment token and run:
`docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.1.0`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
开放9200端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
重置密码
[root@localhost ~]# /usr/local/es/bin/elasticsearch-reset-password -u elastic -i
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Re-enter password for [elastic]:
Password for the [elastic] user successfully reset.
登录
Windows系统
下载
下载地址:www.elastic.co/cn/download…
目录结构
获取密码
点击elasticsearch-8.2.2\bin\elasticsearch.bat
会自动生成一个账号为elastic,密码为随机字符串的账户。记住此密码后关闭程序。
重置密码
在bin目录输入.\elasticsearch-reset-password -u elastic启动服务
注册服务
在bin目录输入.\elasticsearch-service.bat install启动服务
启动服务
在bin目录输入.\elasticsearch-service.bat start启动服务