前置说明
elasticsearch-7.10
-
centos7
-
依赖jdk11
-
必须使用非root账户启动
创建用户
# 添加组appuser
groupadd appuser
# 添加用户appuser,并加入主组appuser,又归属于root
useradd -s /bin/sh -g appuser -G root appuser
# 修改appuser密码
passwd appuser
密码 yxkong
下载解压
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.0-linux-aarch64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.0-linux-aarch64.tar.gz
tar -zxvf elasticsearch-7.10.0-linux-aarch64.tar.gz -C /app/es/
修改配置
config/elasticsearch.yml
#集群名称
cluster.name: yxkong
#节点名称
node.name: node-1
#数据和日志的存储目录
path.data: /app/data/es
path.logs: /app/logs/es
#设置绑定的ip,设置为0.0.0.0可以让任何计算机节点访问
network.host: 0.0.0.0
#默认端口
http.port: 9200
#设置在集群中的所有节点名称
cluster.initial_master_nodes: ["node-1"]
# 新增配置xpack.ml.enabled: false 解决启动报Caused by: org.elasticsearch.ElasticsearchException: Failure running machine learning native code. This could be due to running on an unsupported OS or distribution, missing OS libraries, or a problem with the temp directory. To bypass this problem by running Elasticsearch without machine learning functionality set [xpack.ml.enabled: false]
xpack.ml.enabled: false
创建目录并授予权限
mkdir -p /app/data/es /app/logs/es
chown appuser.appuser -R /app/data/es/ /app/logs/es/
config/jvm.options
可以根据自己的需求调整 xms 和 xmx
修改bin/elasticsearch
由于我的环境默认是jdk8, 需要在启动文件中指定jdk11目录
export JAVA_HOME=/usr/local/java/jdk-11.0.10
修改系统配置文件
切换到root用户 修改sysctl.conf
【最后添加以下配置:注意等号两边有空格】
vm.max_map_count = 655360
【保存完毕后,从指定的文件加载系统参数(不指定即从/etc/sysctl.conf中加载)】
sysctl -p
修改limits
vim /etc/security/limits.conf
【末尾加上一下内容,首单词是用户名】
appuser soft nofile 65536
appuser hard nofile 65536
appuser soft nproc 4096
appuser hard nproc 4096
启动
#启动
sh elasticsearch-7.10.0/bin/elasticsearch
# 后台启动
sh elasticsearch-7.10.0/bin/elasticsearch -d
报错
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_251/jre] does not meet this requirement
elasticsearch-7.10.0/bin/elasticsearch-env: line 126: syntax error near unexpected token `<'
修改elasticsearch-env文件的第126行
done < < (env)
改为:
done <<< `env`
安装ik分词器
cd /app/es/elasticsearch-7.10.0/plugins
# ik的版本和es一定要匹配
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.0/elasticsearch-analysis-ik-7.10.0.zip
unzip elasticsearch-analysis-ik-7.10.0.zip -d ./ik
# 解压后将zip删除,否则会认为是一个插件,无法加载
rm -rf plugins/elasticsearch-analysis-ik-7.10.0.zip
开放端口(centos7)
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload