
一介闲人
一介闲人
Elasticsearch不允许使用root安装启动运行,所以需要创建一个普通用户
# 创建用户
adduser es
# 修改密码
passwd es
# 切换到es用户
su es
# 下载安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.17.0-linux-x86_64.tar.gz
# 解压
tar -vzxf elasticsearch-8.17.0-linux-x86_64.tar.gz
# 进入根目录
cd elasticsearch-8.17.0
# 展示目录
ls
目录 | 说明 |
---|---|
bin | 脚本文件,包括启动Elasticsearch,安装插件,运行统计数据等 |
config | 配置文件目录,如Elasticsearch配置、角色配置、jvm配置等 |
jdk | 7.x版本以后特有的,自带jdk环境 |
data | 默认的数据存放目录,包含节点、分片、索引、文档的所有数据,生产环境需要按需修改 |
lib | Elasticsearch依赖的java类库 |
logs | 默认的日志文件存放路径,生产环境需要按需修改 |
modules | 包含所有的Elasticsearch模块,如Cluster、Discovery、Indices等 |
plugins | 已安装插件目录 |
环境配置
# 进入用户主目录
cd
# 打开环境配置文件
vim .bash_profile
# 设置ES_JAVA_HOME和ES_HOME路径
export ES_JAVA_HOME=/home/es/elasticsearch-8.17.0/jdk/
export ES_HOME=/home/es/elasticsearch-8.17.0/
# 保存退出
:wq
# 重新加载配置文件,使配置生效
source .bash_profile
Elasticserach配置
# 进入配置文件存放目录
cd /home/es/elasticsearch-8.17.0/config
# 编辑Elasticsearch配置文件
vim elasticsearch.yml
# 配置节点对外提供服务的地址以及集群内通信的IP地址,默认为127.0.0.1和[::1]
# 配置为0.0.0.0开启远程支持访问
network.host: 0.0.0.0
# 指定节点为单节点,可以绕过引导检查 初学者建议设置为开发模式(单节点模式)
discovery.type: single-node
#初学者建议关闭security安全认证
xpack.security.enabled: false
# 保存退出
:wq
jvm堆内存配置
# 进入配置文件存放目录
cd /home/es/elasticsearch-8.17.0/config
# 编辑JVM配置文件
vim jvm.options
# 分配内存大小,建议Xms和Xmx设置一样的,降低性能耗费,设置的值一般为所在机器内存的一半,且不小于1g和不大于32g
-Xms4g
-Xmx4g
# 保存退出
:wq
注意:ElasticSearch不能用root账户启动
# 直接启动
cd /home/es/elasticsearch-8.17.0/bin
./elasticsearch
# 后台启动
cd /home/es/elasticsearch-8.17.0/bin
./elasticsearch -d
浏览器访问http://ip:9200
,能正常返回即启动成功。
cd es安装路径/bin
执行
./elasticsearch-setup-passwords interactive
如果不配置开发模式(单节点模式):discovery.type: single-node,在ElasticSerach启动的时候可能会报错:
bootstrap check failure [1] of [3]: max file descriptors [20000] for elasticsearch process is too low, increase to at least [65535];for more information see [https://www.elastic.co/guide/en/elasticsearch/reference/8.17/_file_descriptor_check.html]
bootstrap check failure [2] of [3]: max virtual memory areas vm.max_map_count [65530] is to low, increase to at least [262144];for more information see [https://www.elastic.co/guide/en/elasticsearch/reference/8.17/_maximum_map_count_check.html]
bootstrap check failure [3] of [3]: the default discovery settings are unsuitable for production use; at least one of[discovery.seed_providers, cluster.initial_master_nodes]must be configure; for more information see [https://www.elastic.co/guide/en/elasticsearch/reference/8.17/_discovery_configuration_check.html]
ERROR: Elastcsearch did not exit normally - check the logs at /home/es/elasticsearch-8.17.0/logs/elasticsearch.log
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least[65535]
Elasticserach需要大量的创建索引文件,需要打开大量的系统文件,所以Linux系统中需要解除打开文件最大数目的限制。
# 切换root用户
su -
# 编辑limits.conf文件
vim /etc/security/limits.conf
# 在文末添加
* soft nofile 65535
* hard nofile 65535
* soft nproc 4096
* hard nproc 4096
# 保存退出
:wq
[2]: max number of threads [1024] for user[es] is too low, increase to at least[4096]
无法创建本地线程问题,用户最大可创建线程数太小
# 切换root用户
su -
# 编辑20-nproc.conf文件
vim /etc/security/limits.d/20-nproc.conf
# 修改一下配置
* soft nproc 4096
# 保存退出
:wq
[3]: max virtual memory areas vm.max_map_count [65530] is to low, increase to at least [262144]
最大虚拟内存太小,调大系统的虚拟内存
# 切换root用户
su -
# 编辑sysctl.conf文件
vim /etc/sysctl.conf
# 追加一下内容
vm.max_map_count=262144
# 保存退出
:wq
# 执行命令,使配置生效
sysctl -p
[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 configure
缺少默认配置,至少需要配置discovery.seed_hosts,discovery.seed_providers, cluster.initial_master_nodes中的一个参数
# 普通用户
su es
# 配置elasticserach.yml文件
cd /home/es/elasticsearch-8.17.0/config
vim elasticserach.yml
# 添加配置
discovery.seed_hosts: ["127.0.0.1"]
cluster.initial_master_nodes: ["node-1"]
#或者设置开发模式/单点模式,绕过检查
discovery.type: single-node
评论