1.前言

下述所有部署都是基于elasticsearch8.3.3版本部署。其他版本请自行决定是否参考 :::success 后续部署发现,由于是新版本所以会导致各种分词插件没有匹配版本而无法使用。。。。
还是老老实实用稳定的版本吧。。。。。后来我改成了8.0版本 :::

2.windows单节点部署(无权限验证)

下载

下载地址:https://www.elastic.co/cn/downloads/elasticsearch
国内镜像地址(最新版本8.0):https://repo.huaweicloud.com/elasticsearch/
image.png

解压

压缩包解压即可
image.png

目录介绍

image.png

  1. bin:可执行脚本目录
  2. config:配置目录
  3. jdk:内置 JDK 目录(ES是采用Java语言开发的)
  4. lib:类库
  5. logs:日志目录
  6. modules:模块目录
  7. plugins:插件目录

    配置文件修改

    ElasticSearch-8.3.3默认启动是开启权限校验,并且要下载geo地理位置相关功能的库,如果不需要开启权限且下载geo相关库时,可关闭这些功能启动
    修改部分内容如下:
    其中 cluster.initial_master_nodes 选项默认为当前主机标识,每台电脑都不一样 ```yaml

    禁止启动时下载地图相关数据库

    ingest.geoip.downloader.enabled: false

Enable security features

xpack.security.enabled: false

xpack.security.enrollment.enabled: false

Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents

xpack.security.http.ssl: enabled: false keystore.path: certs/http.p12

Enable encryption and mutual authentication between cluster nodes

xpack.security.transport.ssl: enabled: false verification_mode: certificate keystore.path: certs/transport.p12 truststore.path: certs/transport.p12

Create a new cluster with the current node only

Additional nodes can still join the cluster later

cluster.initial_master_nodes: [“LAPTOP-KQB7KV6K”]

Allow HTTP API connections from anywhere

Connections are encrypted and require user authentication

http.host: 0.0.0.0

Allow other nodes to join the cluster from anywhere

Connections are encrypted and mutually authenticated

transport.host: 0.0.0.0

———————————- END SECURITY AUTO CONFIGURATION ————————————-

  1. <a name="frpKw"></a>
  2. ### 启动项目
  3. 进入bin目录下,双击elasticsearch.bat文件启动elasticsearch节点<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/28218714/1659844497580-55d10bcf-2087-4d44-8b30-4a59ea2d93f6.png#clientId=u24cc4df7-fce8-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=457&id=ue08e809e&margin=%5Bobject%20Object%5D&name=image.png&originHeight=686&originWidth=1166&originalType=binary&ratio=1&rotation=0&showTitle=false&size=72597&status=done&style=none&taskId=u178c9940-ee08-4913-8d51-dfb074506d9&title=&width=777.3333333333334)<br />出现如下图的started字样,代表节点启动成功<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/28218714/1659844560173-b127aa7a-8a74-43da-b683-be4b3457005b.png#clientId=u24cc4df7-fce8-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=636&id=u6d5427a8&margin=%5Bobject%20Object%5D&name=image.png&originHeight=954&originWidth=1730&originalType=binary&ratio=1&rotation=0&showTitle=false&size=241667&status=done&style=none&taskId=u3ac93581-d717-42e8-973a-6741d9538a4&title=&width=1153.3333333333333)
  4. > **9300 端口为 Elasticsearch 集群间组件的通信端口**
  5. > **9200 端口为浏览器访问的 http 协议的 RESTful 端口。**
  6. <a name="d89Fa"></a>
  7. ### 验证
  8. 浏览器输入http://localhost:9200,出现如下json返回,启动成功<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/28218714/1659855510451-bfb84c3e-e465-40df-9c9b-f376bdc903e9.png#clientId=u0ce5f5e6-4c10-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=276&id=u9b3e27b2&margin=%5Bobject%20Object%5D&name=image.png&originHeight=414&originWidth=664&originalType=binary&ratio=1&rotation=0&showTitle=false&size=52579&status=done&style=none&taskId=uc6b0a101-4f69-417b-81fc-6448e05f71d&title=&width=442.6666666666667)
  9. <a name="ecIEw"></a>
  10. ## 3.linux单节点部署(无权限验证)
  11. <a name="RudTM"></a>
  12. ### 进入目录
  13. cd /usr/local
  14. <a name="pvro6"></a>
  15. ### 下载
  16. 下载地址:[https://www.elastic.co/cn/downloads/elasticsearch](https://www.elastic.co/cn/downloads/elasticsearch)<br />国内镜像地址(最新版本8.0):[https://repo.huaweicloud.com/elasticsearch/](https://repo.huaweicloud.com/elasticsearch/)<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/28218714/1659845966868-65146aae-aee1-4fb2-b2f2-563cdb605ab0.png#clientId=u16cf86aa-612d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=765&id=DYXcR&margin=%5Bobject%20Object%5D&name=image.png&originHeight=1147&originWidth=2244&originalType=binary&ratio=1&rotation=0&showTitle=false&size=293258&status=done&style=none&taskId=ued3bb96b-3e5c-4c71-9e9f-01bda0bd5b3&title=&width=1496)<br />如图复制下载链接即可<br />下载命令示例:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.3-linux-x86_64.tar.gz
  17. <a name="fYIp9"></a>
  18. ### 解压
  19. 1. tar -zxvf elasticsearch-8.3.3-linux-x86_64.tar.gz
  20. 2. rm -rf elasticsearch-8.3.3-linux-x86_64.tar.gz
  21. 3. mv elasticsearch-8.3.3/ elasticsearch
  22. 4. ls
  23. ![image.png](https://cdn.nlark.com/yuque/0/2022/png/28218714/1659846798609-5c15f74e-2cb8-4b3b-80b0-86e162e85ffa.png#clientId=u16cf86aa-612d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=47&id=u6f2f2d00&margin=%5Bobject%20Object%5D&name=image.png&originHeight=70&originWidth=1803&originalType=binary&ratio=1&rotation=0&showTitle=false&size=17369&status=done&style=none&taskId=u7c2b00ae-cc5a-4c36-8c03-8dd075c377b&title=&width=1202)
  24. <a name="j9hfK"></a>
  25. ### 建立存储数据和日志的文件夹
  26. 1. cd elasticsearch
  27. 2. mkdir data
  28. 3. mkdir logs(如果存在就不用创建了)
  29. 4. ls
  30. ![image.png](https://cdn.nlark.com/yuque/0/2022/png/28218714/1659854813265-57ed524e-c11e-4cd7-be68-607d5cb62373.png#clientId=u0ce5f5e6-4c10-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=45&id=MMyX3&margin=%5Bobject%20Object%5D&name=image.png&originHeight=68&originWidth=1342&originalType=binary&ratio=1&rotation=0&showTitle=false&size=18567&status=done&style=none&taskId=u96704ebc-28c0-4947-a717-062e5e9f7b8&title=&width=894.6666666666666)
  31. <a name="yybIP"></a>
  32. ### 修改jvm启动参数
  33. elasticsearch默认启动jvm堆内存大小=4g,对于学习而言这种内存要求过高,因此我们改为512m即可
  34. 1. vim /usr/local/elasticsearch/config/jvm.options
  35. 2. 找到IMPORTANT: JVM heap size配置项,并修改为以下内容
  36. ```properties
  37. -Xms512m
  38. -Xmx512m

修改配置文件

修改部分与windows大致一样,修改部分yml如下
其中集群名称与节点名称自定义即可,文档只提供参考

  1. # ======================== Elasticsearch Configuration =========================
  2. # ---------------------------------- Cluster -----------------------------------
  3. #
  4. # Use a descriptive name for your cluster:
  5. #
  6. cluster.name: es-cluster
  7. #
  8. # ------------------------------------ Node ------------------------------------
  9. #
  10. # Use a descriptive name for the node:
  11. #
  12. node.name: es-node-1
  13. #
  14. # Add custom attributes to the node:
  15. #
  16. #node.attr.rack: r1
  17. #
  18. # ----------------------------------- Paths ------------------------------------
  19. #
  20. # Path to directory where to store the data (separate multiple locations by comma):
  21. #
  22. path.data: /usr/local/elasticsearch/data
  23. #
  24. # Path to log files:
  25. #
  26. path.logs: /usr/local/elasticsearch/logs
  27. #
  28. # ---------------------------------- Network -----------------------------------
  29. #
  30. # By default Elasticsearch is only accessible on localhost. Set a different
  31. # address here to expose this node on the network:
  32. #
  33. network.host: 0.0.0.0
  34. #
  35. # By default Elasticsearch listens for HTTP traffic on the first free port it
  36. # finds starting at 9200. Set a specific HTTP port here:
  37. #
  38. http.port: 9200
  39. #
  40. # For more information, consult the network module documentation.
  41. #stop download geo
  42. ingest.geoip.downloader.enabled: false
  43. # Enable security features
  44. xpack.security.enabled: false
  45. xpack.security.enrollment.enabled: false
  46. # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
  47. xpack.security.http.ssl:
  48. enabled: false
  49. keystore.path: certs/http.p12
  50. # Enable encryption and mutual authentication between cluster nodes
  51. xpack.security.transport.ssl:
  52. enabled: false
  53. verification_mode: certificate
  54. keystore.path: certs/transport.p12
  55. truststore.path: certs/transport.p12
  56. # Create a new cluster with the current node only
  57. # Additional nodes can still join the cluster later
  58. cluster.initial_master_nodes: ["es-node-1"]
  59. #----------------------- END SECURITY AUTO CONFIGURATION -------------------------

修改系统进程内存限制

  1. vim /etc/security/limits.conf
  2. 文档末尾改为如下内容即可,未修改时soft nofile和hard nofile都为65535 ```shell

    End of file

    root soft nofile 65535 root hard nofile 65535
  • soft nofile 65536
  • hard nofile 65536 ```
  1. vim /etc/sysctl.conf
  2. 新增如下内容即可

    1. # 修改属性
    2. vm.max_map_count=655360
  3. sysctl -p

    新建用户并授权

    因为es不允许用root用户启动,因此需要新建es用户

  4. useradd esuser

  5. passwd esuser
  6. 输入密码
  7. 再次输入确认密码
  8. chgrp -R esuser /usr/local/elasticsearch
  9. chown -R esuser /usr/local/elasticsearch
  10. chmod 777 /usr/local/elasticsearch

    切换用户启动测试

  11. su esuser

  12. /usr/local/elasticsearchbin/elasticsearch

如图,启动成功
image.png
浏览器输入http://120.48.107.224:9200/,出现如下JSON字样,启动成功
image.png

后台运行

可以通过:/usr/local/elasticsearch/bin/elasticsearch -d 来直接后台运行elasticsearch服务
个人更倾向用supervisor来管理java服务后台运行

  1. supervisor下载与配置。参考:Boot项目 CI/CD 部署流程
  2. cd /usr/local/elasticsearch/logs
  3. touch run.log
  4. supervisor配置文件如下

    1. [program:elastic-search-single]
    2. directory=/usr/local/elasticsearch
    3. command=/usr/local/elasticsearch/bin/elasticsearch
    4. autorestart=true
    5. redirect_stderr=true
    6. stdout_logfile=/usr/local/elasticsearch/logs/run.log
    7. user=esuser
  5. supervisorctl update

  6. supervisorctl status

image.png

  1. ps -ef|grep elasticsearch

image.png

  1. 浏览器输入:浏览器输入http://120.48.107.224:9200/,出现如下JSON字样,后台启动成功

image.png

4.linux单机集群部署(无权限校验)

集群预设

集群名称 节点name 端口号
ftc-es es-1 9201
ftc-es es-2 9202
ftc-es es-3 9203

进入目录

  1. cd /usr/local
  2. mkdir elasticsearch-set
  3. cd elasticsearch-set

    下载

    下载地址:https://www.elastic.co/cn/downloads/elasticsearch
    国内镜像地址(最新版本8.0):https://repo.huaweicloud.com/elasticsearch/
    image.png
    如图复制下载链接即可
    下载命令示例:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.3-linux-x86_64.tar.gz

    解压

  4. tar -zxvf elasticsearch-8.3.3-linux-x86_64.tar.gz

  5. rm -rf elasticsearch-8.3.3-linux-x86_64.tar.gz
  6. mv elasticsearch-8.3.3/ elasticsearch-1
  7. ls

image.png

建立存储数据和日志的文件夹

  1. cd elasticsearch-1
  2. mkdir data
  3. mkdir logs(如果存在就不用创建了)
  4. ls

image.png

修改jvm启动参数

  1. vim /usr/local/elasticsearch-set/elasticsearch-1/config/jvm.options
  2. 找到IMPORTANT: JVM heap size配置项,并修改为以下内容

    1. -Xms256m
    2. -Xmx256m

    复制多节点

  3. cd /usr/local/elasticsearch-set/

  4. cp -r elasticsearch-1/ elasticsearch-2
  5. cp -r elasticsearch-1/ elasticsearch-3
  6. ls

image.png

修改配置文件

  1. 节点1:vim /usr/local/elasticsearch-set/elasticsearch-1/config/elasticsearch.yml ```yaml

    集群名称,保证唯一

    cluster.name: ftc-es

节点名称,必须不一样

node.name: es-1

ip地址.

network.host: 0.0.0.0

端口

http.port: 9201

内部节点之间沟通端口

transport.port: 9700

es7.x 之后新增的配置,节点发现

discovery.seed_hosts: [“127.0.0.1:9700”,”127.0.0.1:9800”,”127.0.0.1:9900”]

es7.x 之后新增的配置,初始化一个新的集群时需要次配置来选举master

cluster.initial_master_nodes: [“es-1”,”es-2”,”es-3”]

数据和存储路径

path.data: /usr/local/elasticsearch-set/elasticsearch-1/data path.logs: /usr/local/elasticsearch-set/elasticsearch-1/logs

禁止启动时下载地图相关数据库

ingest.geoip.downloader.enabled: false

Enable security features

xpack.security.enabled: false xpack.security.enrollment.enabled: false

Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents

xpack.security.http.ssl: enabled: false

Enable encryption and mutual authentication between cluster nodes

xpack.security.transport.ssl: enabled: false

  1. 2. 节点2vim /usr/local/elasticsearch-set/elasticsearch-2/config/elasticsearch.yml
  2. ```yaml
  3. #集群名称,保证唯一
  4. cluster.name: ftc-es
  5. # 节点名称,必须不一样
  6. node.name: es-2
  7. #ip地址.
  8. network.host: 0.0.0.0
  9. #端口
  10. http.port: 9202
  11. #内部节点之间沟通端口
  12. transport.port: 9800
  13. #es7.x 之后新增的配置,节点发现
  14. discovery.seed_hosts: ["127.0.0.1:9700","127.0.0.1:9800","127.0.0.1:9900"]
  15. #es7.x 之后新增的配置,初始化一个新的集群时需要次配置来选举master
  16. cluster.initial_master_nodes: ["es-1","es-2","es-3"]
  17. #数据和存储路径
  18. path.data: /usr/local/elasticsearch-set/elasticsearch-2/data
  19. path.logs: /usr/local/elasticsearch-set/elasticsearch-2/logs
  20. # 禁止启动时下载地图相关数据库
  21. ingest.geoip.downloader.enabled: false
  22. # Enable security features
  23. xpack.security.enabled: false
  24. xpack.security.enrollment.enabled: false
  25. # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
  26. xpack.security.http.ssl:
  27. enabled: false
  28. # Enable encryption and mutual authentication between cluster nodes
  29. xpack.security.transport.ssl:
  30. enabled: false
  1. 节点3:vim /usr/local/elasticsearch-set/elasticsearch-3/config/elasticsearch.yml ```yaml

    集群名称,保证唯一

    cluster.name: ftc-es

节点名称,必须不一样

node.name: es-3

ip地址.

network.host: 0.0.0.0

端口

http.port: 9203

内部节点之间沟通端口

transport.port: 9900

es7.x 之后新增的配置,节点发现

discovery.seed_hosts: [“127.0.0.1:9700”,”127.0.0.1:9800”,”127.0.0.1:9900”]

es7.x 之后新增的配置,初始化一个新的集群时需要次配置来选举master

cluster.initial_master_nodes: [“es-1”,”es-2”,”es-3”]

数据和存储路径

path.data: /usr/local/elasticsearch-set/elasticsearch-3/data path.logs: /usr/local/elasticsearch-set/elasticsearch-3/logs

禁止启动时下载地图相关数据库

ingest.geoip.downloader.enabled: false

Enable security features

xpack.security.enabled: false xpack.security.enrollment.enabled: false

Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents

xpack.security.http.ssl: enabled: false

Enable encryption and mutual authentication between cluster nodes

xpack.security.transport.ssl: enabled: false

  1. <a name="BJpq2"></a>
  2. ### 修改系统进程内存限制
  3. 1. vim /etc/security/limits.conf
  4. 2. 文档末尾改为如下内容即可,未修改时soft nofile和hard nofile都为65535
  5. ```shell
  6. # End of file
  7. root soft nofile 65535
  8. root hard nofile 65535
  9. * soft nofile 65536
  10. * hard nofile 65536
  1. vim /etc/sysctl.conf
  2. 新增如下内容即可

    1. # 修改属性
    2. vm.max_map_count=655360
  3. sysctl -p

    新建用户并授权

    因为es不允许用root用户启动,因此需要新建es用户

  4. useradd esuser

  5. passwd esuser
  6. 输入密码
  7. 再次输入确认密码
  8. chgrp -R esuser /usr/local/elasticsearch-set
  9. chown -R esuser /usr/local/elasticsearch-set
  10. chmod 777 /usr/local/elasticsearch-set

    切换用户启动测试

  11. su esuser

  12. /usr/local/elasticsearch-set/elasticsearch-1/bin/elasticsearch -d
  13. /usr/local/elasticsearch-set/elasticsearch-2/bin/elasticsearch -d
  14. /usr/local/elasticsearch-set/elasticsearch-3/bin/elasticsearch -d
  15. 每个节点都启动完成后,浏览器输入:http://120.48.107.224:9203/_cat/health?v

如图,集群启动成功。上述url输入集群任意一个节点地址即可image.png

后台运行

同理,还是通过supervisor来管理进程

创建supervisor日志

  1. touch /usr/local/elasticsearch-set/elasticsearch-1/logs/run.log
  2. touch /usr/local/elasticsearch-set/elasticsearch-2/logs/run.log
  3. touch /usr/local/elasticsearch-set/elasticsearch-3/logs/run.log

    创建supervisor文件

  4. vim /etc/supervisord.d/elasticsearch-1.ini

    1. [program:elastic-1]
    2. directory=/usr/local/elasticsearch-set/elasticsearch-1
    3. command=/usr/local/elasticsearch-set/elasticsearch-1/bin/elasticsearch
    4. autorestart=true
    5. redirect_stderr=true
    6. stdout_logfile=/usr/local/elasticsearch-set/elasticsearch-1/logs/run.log
    7. user=esuser
  5. vim /etc/supervisord.d/elasticsearch-2.ini

    1. [program:elastic-2]
    2. directory=/usr/local/elasticsearch-set/elasticsearch-2
    3. command=/usr/local/elasticsearch-set/elasticsearch-2/bin/elasticsearch
    4. autorestart=true
    5. redirect_stderr=true
    6. stdout_logfile=/usr/local/elasticsearch-set/elasticsearch-2/logs/run.log
    7. user=esuser
  6. vim /etc/supervisord.d/elasticsearch-3.ini

    1. [program:elastic-3]
    2. directory=/usr/local/elasticsearch-set/elasticsearch-3
    3. command=/usr/local/elasticsearch-set/elasticsearch-3/bin/elasticsearch
    4. autorestart=true
    5. redirect_stderr=true
    6. stdout_logfile=/usr/local/elasticsearch-set/elasticsearch-3/logs/run.log
    7. user=esuser

    更新supervisor并运行

  7. supervisorctl update

image.png

  1. supervisorctl status

image.png

  1. 浏览器输入:http://120.48.107.224:9203/_cat/health?v

image.png

5.kibana部署

其实本来我是不想部署kibana的。但是我发现用apipost或postman来操作es,好多方法都有稀奇古怪的问题。虽然说es是基于restful形式进行调用,但是好多方法和预想的不一样。所以我屈服了,kibana作为elastic生态中原生的可视化工具,kibana你赢了!!!

进入目录

cd /usr/local

下载

下载地址:https://www.elastic.co/cn/downloads/kibana
国内镜像地址(最新版本8.0):https://repo.huaweicloud.com/kibana/
如图,复制下载链接即可
image.png
下载命令示例:wget https://artifacts.elastic.co/downloads/kibana/kibana-8.3.3-linux-x86_64.tar.gz

解压

  1. tar -zxvf kibana-8.3.3-linux-x86_64.tar.gz
  2. rm -rf kibana-8.3.3-linux-x86_64.tar.gz
  3. mv kibana-8.3.3 kibana
  4. ls

image.png

修改配置文件

  1. vim /usr/local/kibana/config/kibana.yml
  2. 修改链接地址

    1. # =================== System: Kibana Server ===================
    2. # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
    3. # The default is 'localhost', which usually means remote machines will not be able to connect.
    4. # To allow connections from remote users, set this parameter to a non-loopback address.
    5. server.host: "0.0.0.0"
  3. 修改es实例地址

    1. # =================== System: Elasticsearch ===================
    2. # The URLs of the Elasticsearch instances to use for all your queries.
    3. elasticsearch.hosts: ["http://localhost:9201"]

    新建用户并授权

    因为es不允许用root用户启动,因此需要新建es用户

  4. useradd esuser

  5. passwd esuser
  6. 输入密码
  7. 再次输入确认密码
  8. chgrp -R esuser /usr/local/kibana
  9. chown -R esuser /usr/local/kibana
  10. chmod 777 /usr/local/kibana

    启动测试

  11. /usr/local/kibana/bin/kibana

  12. 出现如图,kibana启动成功

image.png

  1. 浏览器输入:http://120.48.107.224:5601/。如图,kibana启动成功

image.png

后台运行

与ElasticSearch同理,kibana同样用supervisor管理进程

  1. su esuser
  2. touch /usr/local/kibana/logs/run.log
  3. su root
  4. vim /etc/supervisord.d/kibana.ini

    1. [program:kibana]
    2. directory=/usr/local/kibana
    3. command=/usr/local/kibana/bin/kibana
    4. autorestart=true
    5. redirect_stderr=true
    6. stdout_logfile=/usr/local/kibana/logs/run.log
    7. user=esuser
  5. supervisorctl update

  6. supervisorctl status

image.png

  1. 浏览器输入:http://120.48.107.224:5601/。如图,kibana启动成功

image.png