环境准备
Anolis OS 8
Firewall关闭状态,端口自行处理
Elasticsearch:7.16.1(该版本需要jdk11)
JDK:11.0.19
JDK
bash
# 解压
tar -zxvf jdk-11.0.19_linux-x64_bin.tar.gz
# 编辑/etc/profile
vim /etc/profile
# 加入如下配置
export JAVA_HOME=/home/jdk-11.0.19
export JRE_HOME=/home/jdk-11.0.19/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin
# 保存退出后,使该配置文件即刻生效
source /etc/profile
# 使用如下命令,能正确显示信息,说明环境配置成功
java -version
Elasticsearch
bash
############ 安装 ############
# 下载elasticsearch
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.16.1-linux-x86_64.tar.gz
# 解压
tar -zxf elasticsearch-7.16.1-linux-x86_64.tar.gz -C /usr/local/
# 配置变量
# 编辑/etc/profile
vim /etc/profile
# 加入如下配置
export PATH=$PATH:/usr/local/elasticsearch-7.16.1/bin
# 保存退出后,使该配置文件即刻生效
source /etc/profile
############ 配置 ############
mkdir /home/elasticsearch/data
mkdir /home/elasticsearch/logs
# 注意授权
chmod -R 777 /home/elasticsearch/
# 修改 Elasticsearch配置文件
vim /usr/local/elasticsearch-7.16.1/config/elasticsearch.yml
cluster.name: my-application
node.name: node-1
# 自定义数据存储路径
path.data: /home/elasticsearch/data
# 自定义日志存在路径
path.logs: /home/elasticsearch/logs
network.host: 0.0.0.0
http.port: 9200
# 关闭密码认证
xpack.security.enabled: false
# 集群模式,single-node 是单节点
discovery.type: single-node
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
# 修改 Elasticsearch JVM的内存限制
vim /usr/local/elasticsearch-7.16.1/config/jvm.options
#建议调至当前可用内存的一半
-Xms2g
-Xmx2g
创建elastic用户、授予elastic权限,并启动服务
bash
# 添加elastic用户,禁止ssh登录
useradd -s /sbin/nologin elastic
# 授权
chown -R elastic:elastic /usr/local/elasticsearch-7.16.1/
# 切换 elastic 用户
su - elastic -s /bin/bash
# 验证版本
elasticsearch --version
# 启动服务
elasticsearch -d
# 查看端口是否监听
netstat -lntp |grep 9200
# 服务没问题后退出当前用户
exit
Elasticsearch开启密码(如有需要)
bash
/usr/local/elasticsearch-7.16.1/bin/elasticsearch-setup-passwords interactive
输入:y
输入自定义密码:123456
IK分词器安装
找到相对应的版本下载
https://github.com/medcl/elasticsearch-analysis-ik/releases
bash
mkdir /usr/local/elasticsearch-7.16.1/plugins/ik
cd /usr/local/elasticsearch-7.16.1/plugins/ik
unzip elasticsearch-analysis-ik-7.16.1.zip
重启Elasticsearch
bash
su - elastic -s /bin/bash
# 停止服务
ps -ef |grep -w elasticsearch-7.16.1 |grep -v grep | awk '{print $2}' |xargs kill
# 启动服务
elasticsearch -d