Skip to content

安装部署

插件

分词插件

官方版本发布会有延迟,如果版本一致,修改插件配置文件即可,一般都可以正常使用。

bash
# 官网
https://release.infinilabs.com
# 8.x
https://release.infinilabs.com/analysis-ik/stable/elasticsearch-analysis-ik-8.14.0.zip
# 7.x
https://release.infinilabs.com/analysis-ik/stable/elasticsearch-analysis-ik-7.17.21.zip

RHEL

安装目录

|---data                                    --     
|---|---app                                 -- 应用目录    
|---|---|---data                            -- 数据目录
|---|---|---|---elasticsearch               -- ElasticSearch
|---|---|---|---|---data                    -- ElasticSearch数据目录
|---|---|---|---|---logs                    -- ElasticSearch日志目录 
|---|---|---temp                            -- 临时目录

安装

bash
# 安装
yum install -y elasticsearch-8.14.0-x86_64.rpm

初始化数据目录并授权

bash
# 新建数据目录和日志目录 
mkdir -p /data/app/data/elasticsearch/data
mkdir -p /data/app/data/elasticsearch/logs
# 赋予目录权限
chown -R elasticsearch.elasticsearch /data/app/data/elasticsearch/

编辑配置文件

bash
vi /etc/elasticsearch/elasticsearch.yml

内容参考如下

bash
# ----------------------------------------------------------------------------------------
# Elasticsearch Configuration
# ----------------------------------------------------------------------------------------
# 集群名称
cluster.name: es
# 节点名称
node.name: main
# 数据目录
path.data: /Users/elvea/Tools/elastic/data/elasticsearch/data
# 日志目录
path.logs: /Users/elvea/Tools/elastic/data/elasticsearch/logs
# 安全控制
xpack.security.enabled: false
xpack.security.transport.ssl.enabled: false
xpack.security.http.ssl.enabled: false
# Cluster
discovery.type: single-node

安装分词插件

bash
unzip elasticsearch-analysis-ik-8.14.0.zip -d /usr/share/elasticsearch/plugins/ik
unzip elasticsearch-analysis-ik-7.17.21.zip -d /usr/share/elasticsearch/plugins/ik

修改内存配置

bash
# 打开编辑配置文件
vi /etc/elasticsearch/jvm.options

配置参考如下

bash
-Xms2g
-Xmx2g

系统服务

bash
# 随系统启动
sudo systemctl enable elasticsearch.service
# 启动服务
sudo systemctl start elasticsearch.service
# 停止服务
sudo systemctl stop elasticsearch.service

添加用户

bash
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
bash
/usr/share/elasticsearch/bin/elasticsearch-reset-password interactive -u elastic

测试是否安装成功

bash
# 没开启安全认证
curl -XGET "127.0.0.1:9200"
# 已开启安全认证
curl -XGET "127.0.0.1:9200"

MacOS

最新版本已经不支持HomeBrew直接安装,所以使用手工安装的方式。

bash
# 准备安装目录
rm -rf /Users/elvea/Tools/elastic/elasticsearch
rm -rf /Users/elvea/Tools/elastic/data/elasticsearch
#
mkdir -p /Users/elvea/Tools/elastic/elasticsearch
mkdir -p /Users/elvea/Tools/elastic/data/elasticsearch/data
mkdir -p /Users/elvea/Tools/elastic/data/elasticsearch/logs
# 解压缩
tar zxvf elasticsearch-8.14.0-darwin-aarch64.tar.gz
# 复制到目标安装目录
mv elasticsearch-8.14.0/* /Users/elvea/Tools/elastic/elasticsearch
# 安装分词插件
unzip elasticsearch-analysis-ik-8.14.0.zip -d /Users/elvea/Tools/elastic/elasticsearch/plugins/ik

配置分词插件

这一步非必须,只有当插件版本跟安装版本不一致的情况,才需要修改。

bash
vi /Users/elvea/Tools/elastic/elasticsearch/plugins/ik/plugin-descriptor.properties

版本号跟实际安装的版本指定

properties
version=8.14.0
elasticsearch.version=8.14.0

编辑配置文件

bash
mv /Users/elvea/Tools/elastic/elasticsearch/config/elasticsearch.yml /Users/elvea/Tools/elastic/elasticsearch/config/elasticsearch.bak.yml
vi /Users/elvea/Tools/elastic/elasticsearch/config/elasticsearch.yml

内容参考如下

yaml
# ----------------------------------------------------------------------------------------
# Elasticsearch Configuration
# ----------------------------------------------------------------------------------------
# 集群名称
cluster.name: es
# 节点名称
node.name: main
# 数据目录
path.data: /Users/elvea/Tools/elastic/data/elasticsearch/data
# 日志目录
path.logs: /Users/elvea/Tools/elastic/data/elasticsearch/logs
# 绑定IP地址
network.host: 127.0.0.1
# 安全控制
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: false
xpack.security.http.ssl.enabled: false
# Cluster
discovery.type: single-node
# 忽略磁盘空间检测,避免服务无法正常运行
cluster.routing.allocation.disk.threshold_enabled: false

修改内存配置

默认内存占用太高

bash
vi /Users/elvea/Tools/elastic/elasticsearch/config/jvm.options

参考如下

bash
-Xms512M
-Xmx512M

测试启动

bash
cd /Users/elvea/Tools/elastic/elasticsearch/bin
elasticsearch

添加用户

bash
#
cd /Users/elvea/Tools/elastic/elasticsearch/bin
elasticsearch-setup-passwords interactive
#
elasticsearch-reset-password -i -u elastic

系统服务

bash
sudo vim ~/Library/LaunchAgents/elasticsearch.plist

内容参考如下

bash
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version='1.0'>
    <dict>
        <key>Label</key>
        <string>elasticsearch</string>
        <key>ProgramArguments</key>
        <array>
            <string>/Users/elvea/Tools/elastic/elasticsearch/bin/elasticsearch</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>/Users/elvea/Tools/elastic/elasticsearch</string>
        <key>StandardErrorPath</key>
        <string>/Users/elvea/Tools/elastic/elasticsearch-logs/elasticsearch-error.log</string>
        <key>StandardOutPath</key>
        <string>/Users/elvea/Tools/elastic/elasticsearch-logs/elasticsearch-out.log</string>
        <key>UserName</key>
        <string>elvea</string>
        <key>HardResourceLimits</key>
        <dict>
            <key>NumberOfFiles</key>
            <integer>10240</integer>
        </dict>
        <key>SoftResourceLimits</key>
        <dict>
            <key>NumberOfFiles</key>
            <integer>10240</integer>
        </dict>
    </dict>
</plist>

操作服务

bash
# 验证配置文件
plutil -lint ~/Library/LaunchAgents/elasticsearch.plist
# 添加开机启动并立刻启动
launchctl load -w ~/Library/LaunchAgents/elasticsearch.plist
# 取消开机启动并立刻停止 
launchctl unload -w ~/Library/LaunchAgents/elasticsearch.plist

Windows

安装目录

bash
|---D                                       
|---|---Tools                               -- 
|---|---|---elastic                         -- 
|---|---|---|---elasticsearch               -- ElasticSearch安装目录     
|---|---|---data                            -- 
|---|---|---|---elasticsearch               -- 
|---|---|---|---|---data                    -- ElasticSearch数据目录
|---|---|---|---|---logs                    -- ElasticSearch日志目录
bash
# 新建数据目录和日志目录
mkdir -p D:\Tools\Elastic\elasticsearch 
mkdir -p D:\Tools\Elastic\data\elasticsearch\data
mkdir -p D:\Tools\Elastic\data\elasticsearch\logs

内容参考如下

yaml
# ----------------------------------------------------------------------------------------
# Elasticsearch Configuration
# ----------------------------------------------------------------------------------------
# 集群名称
cluster.name: es
# 节点名称
node.name: main
# 数据目录
path.data: D:\Tools\Elastic\data\elasticsearch\data
# 日志目录
path.logs: D:\Tools\Elastic\data\elasticsearch\logs
# 绑定IP地址
network.host: 127.0.0.1
# 安全控制
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: false
# Cluster
discovery.type: single-node

操作命令

cmd
# 安装系统服务
elasticsearch-service.bat install
# 移除系统服务
elasticsearch-service.bat remove
# 启动服务
elasticsearch-service.bat start
# 停止服务
elasticsearch-service.bat stop
# 启动服务管理器
elasticsearch-service.bat manager
# 创建用户 - elastic
elasticsearch-setup-passwords interactive