Elasticsearch 安装
1、本地安装
1.1、环境准备
Elasticsearch 压缩包
# 这里使用的 7.8.0 版本
wget https://repo.huaweicloud.com/elasticsearch/7.8.0/elasticsearch-7.8.0-linux-x86_64.tar.gz
# 解压到 /usr/local/bin/
tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /usr/local/bin/
JDK
1、# JDK(Elasticsearch 版本 7 之后,就自带 JDK)
创建用户
# 添加用户(es 不允许 root 用户启动)
adduser es
# 设置密码
passwd es
# 赋予 es 用户执行的权限
chown -R es /usr/local/bin/elasticsearch-7.8.0/
其他
如果遇到
问题:[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
问题:[2]: max number of threads [3795] for user [es] is too low, increase to at least [4096]
解决:使用 root 用户,vim /etc/security/limits.conf
添加以下两条配置,表示允许所有用户打开的文件数为 65536
soft nofile 65536
hard nofile 65536
重新打开会话才生效
1.2、配置
vim config/elasticsearch.yml
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["127.0.0.1"]
cluster.initial_master_nodes: ["node-1"]
配置密码
# 添加以下配置
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
# 添加配置之后,重启 es,然后进入 es 的 bin 目录
./elasticsearch-setup-passwords interactive
1.3、启动
# 切换 es 用户
su - es
# 启动
/usr/local/bin/elasticsearch-7.8.0/bin/elasticsearch -d
2、Docker
services:
elasticsearch:
image: elasticsearch:7.7.0
volumes:
- /etc/localtime:/etc/localtime
- ./es/plugins:/usr/share/elasticsearch/plugins
- ./es/data:/usr/share/elasticsearch/data
ports:
- '9200:9200'
- '9300:9300'
container_name: elasticsearch
restart: always
environment:
- 'cluster.name=elasticsearch'
- 'discovery.type=single-node'
- 'ES_JAVA_OPTS=-Xms1024m -Xmx1024m'
kibana:
image: kibana:7.7.0
container_name: kibana
restart: always
volumes:
- /etc/localtime:/etc/localtime
- ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- '5601:5601'
links:
- elasticsearch:es
environment:
- ELASTICSEARCH_URL=http://10.1.1.1:9200
- I18N_LOCALE=zh-CN
depends_on:
- elasticsearch
kibana 配置
server.host: '0.0.0.0'
# Elasticsearch 地址
elasticsearch.hosts: ['http://127.0.0.1:9200']
monitoring.ui.container.elasticsearch.enabled: true