ElasticSearch8.X安装

1. CentOS单机源码安装ES8

1.1 安装环境

  • CentOS 7
  • 4核8G
  • elasticsearch-8.4.1-linux-x86_64

1.2 下载资源

1.3 执行安装

  • 修改文件和进程最大打开数,需要root用户

    • vim /etc/security/limits.conf
    • 添加配置
1
2
* soft nofile 65535
* hard nofile 65535

image-20231112205935608

  • 修改虚拟内存空间,默认太小,max_map_count文件包含限制一个进程可以拥有的VMA虚拟内存区域的数量,默认值是65536

    • vim /etc/sysctl.conf
    • 添加vm.max_map_count=262144
    • 执行sysctl -p(立即生效)
  • 创建文件夹,mkdir -p /aacopy/elastic

  • 上传安装文件

  • 解压缩,tar -zxvf elasticsearch-8.4.1-linux-x86_64.tar.gz

  • 新建一个用户,elasticsearch默认不允许以root账号运行

    • 创建用户:useradd es_user
    • 设置密码:passwd es_user
    1
    2
    3
    4
    5
    6
    7
    [root@localhost elasticsearch-8.4.1]# useradd es_user
    [root@localhost elasticsearch-8.4.1]# passwd es_user
    Changing password for user es_user.
    New password:
    BAD PASSWORD: The password is shorter than 8 characters
    Retype new password:
    passwd: all authentication tokens updated successfully.
  • 机器内存不足,可以修改elasticsearch的JVM内存,常规线上推荐16到24G内存

    • vim config/jvm.options
    1
    2
    -Xms1g
    -Xmx1g
  • 修改 elasticsearch相关配置

    • vim config/elasticsearch.yml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    cluster.name: my-application
    node.name: node-1
    path.data: /aacopy/elastic/elasticsearch-8.4.1/data
    path.logs: /aacopy/elastic/elasticsearch-8.4.1/logs
    network.host: 0.0.0.0
    http.port: 9200
    cluster.initial_master_nodes: ["node-1"]
    xpack.security.enabled: false
    xpack.security.enrollment.enabled: false
    ingest.geoip.downloader.enabled: false
    • 配置说明
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    cluster.name: 指定Elasticsearch集群的名称。所有具有相同集群名称的节点将组成一个集群。
    node.name: 指定节点的名称。每个节点在集群中应该具有唯一的名称。
    path.data: 指定用于存储Elasticsearch索引数据的路径。
    path.logs: 指定Elasticsearch日志文件的存储路径。
    network.host: 指定节点监听的网络接口地址。0.0.0.0表示监听所有可用的网络接口,开启远程访问连接
    http.port: 指定节点上的HTTP服务监听的端口号。默认情况下,Elasticsearch的HTTP端口是9200。
    cluster.initial_master_nodes: 指定在启动集群时作为初始主节点的节点名称。
    xpack.security.enabled: 指定是否启用Elasticsearch的安全特性。在这里它被禁用(false),意味着不使用安全功能。
    xpack.security.enrollment.enabled: 指定是否启用Elasticsearch的安全认证和密钥管理特性。在这里它被禁用(false)。
    ingest.geoip.downloader.enabled: 指定是否启用GeoIP数据库下载功能。在这里它被禁用(false)
  • 添加权限

1
2
3
chgrp -R es_user /aacopy/elastic/elasticsearch-8.4.1
chown -R es_user /aacopy/elastic/elasticsearch-8.4.1
chmod -R 777 /aacopy/elastic/elasticsearch-8.4.1
  • 切换到es_user
    • su es_user
  • 启动es
    • ./bin/elasticsearch查看启动是否正常
    • ./bin/elasticsearch & 守护进程方式启动
  • 输入http://192.168.80.128:9200/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "BTK9oomeRXmtEaUIrNgPEw",
"version" : {
"number" : "8.4.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "2bd229c8e56650b42e40992322a76e7914258f0c",
"build_date" : "2022-08-26T12:11:43.232597118Z",
"build_snapshot" : false,
"lucene_version" : "9.3.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}

1.4 问题

  • [ERROR] [o.e.b.Elasticsearch ] [node-1] fatal exception while booting Elasticsearchjava.lang.RuntimeException: can not run elasticsearch as root
    • 没有切换到root用户启动
  • elasticsearch.keystore没有权限
    • 第一次启动生成该文件,需要对该文件也进行授权

docker 安装ES8

版本:8.13.4
创建文件夹

1
2
3
4
5
mkdir -p /home/dockerdata/es8/config
mkdir -p /home/dockerdata/es8/data
mkdir -p /home/dockerdata/es8/logs
mkdir -p /home/dockerdata/es8/plugins
chmod 777 -R /home/dockerdata/es8

添加/home/dockerdata/es8/config/elasticsearch.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.host: 0.0.0.0

#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 26-06-2024 01:07:50
#
# --------------------------------------------------------------------------------

# Enable security features
xpack.security.enabled: true

xpack.security.enrollment.enabled: true

# 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
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------

启动docker容器

1
2
3
4
5
6
7
8
9
docker run -d --name es8 -p 9200:9200 -p 9300:9300 \
-e ES_JAVA_OPS="-Xms1g -Xmx1g" \
-e discovery.type="single-node" \
-e ELASTIC_PASSWORD="cmyang" \
-v /home/dockerdata/es8/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /home/dockerdata/es8/data:/usr/share/elasticsearch/data \
-v /home/dockerdata/es8/logs:/usr/share/elasticsearch/logs \
-v /home/dockerdata/es8/plugins:/usr/share/elasticsearch/plugins \
elasticsearch:8.13.4

访问es验证
http://ip:9200
elastic/cmyang