安装Elasticsearch 8.3.3

安装Elasticsearch 8.3.3

  • 一 准备环境
    • 1.创建用户
    • 2.修改系统设置(root用户)
  • 二 下载ElasticSearch安装包
  • 三 安装ElasticSearch
    • 1. 准备安装的文件夹
    • 2. 解压安装包
    • 3.配置使用es的默认jdk
    • 4.修改jvm内存设置
    • 5.配置传输层TLS/SSL加密传输
    • 6.修改 elasticsearch.yml这个文件
    • 7.用创建的用户进行启动(root用户启动会失败)
    • 8.查看elasticsearch运行状态
    • 9.浏览器访问elasticsearch
    • 10.正常状态下如果浏览器访问不到,需要开放elasticsearch对应的端口
    • 11.设置开机启动和后台运行(root用户)
  • 四 可视化服务
    • ElasticView

一 准备环境 1.创建用户

因为es不能用root用户直接启动。需要单独创建用户

1# 创建用户useradd es# 设置密码passwd# 切换用户su - es

2.修改系统设置(root用户)

(1)修改最大虚拟内存区域 vm.max_map_count

1vim /etc/sysctl.conf

文件最后添加一行

12#增加这样一条配置,一个进程在VMAs(虚拟内存区域)创建内存映射最大数量vm.max_map_count=262144

重启生效

1sysctl -p

注:如果不修改,Elasticsearch启动时候出现vm.max_map_count异常的处理方法
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

(2)修改配置文件可限制文件打开数,系统进程等资源

1vim /etc/security/limits.conf
12345678//追加下面的内容* soft nofile 65536* hard nofile 131072* soft nproc 4096* hard nproc 4096 //重启服务器生效配置shutdown -r now

不配置会报如下错误:
[1]:max file descriptors [4096] for elasticsearch process is too low, increase to at least[65536]

每个进程最大同时打开文件数太小
如不方便重启服务器生效配置,可以先配置,在用临时生效

12ulimit -u 4096(将用户进程数最大值修改为4096ulimit -n 65536

二 下载ElasticSearch安装包

123https://www.elastic.co/cn/downloads/past-releases#elasticsearch或:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.3-linux-x86_64.tar.gz

三 安装ElasticSearch 1. 准备安装的文件夹

1mkdir -p /opt/software/elasticsearch

2. 解压安装包

1tar -zxvf elasticsearch-8.3.3-linux-x86_64.tar.gz -C /opt/software/elasticsearch

3.配置使用es的默认jdk

进入解压目录

1cd /opt/software/elasticsearch/elasticsearch-8.3.3/bin

打开elasticsearch,加入下面的命令,可以使用es的默认jdk

1vim elasticsearch
12345678910############## 添加配置解决jdk版本问题 ############### 将jdk修改为es中自带jdk的配置目录export JAVA_HOME=/opt/software/elasticsearch/elasticsearch-8.3.3/jdkexport PATH=$JAVA_HOME/bin:$PATH if [ -x "$JAVA_HOME/bin/java" ]; then        JAVA="/opt/software/elasticsearch/elasticsearch-8.3.3/jdk/bin/java"else        JAVA=`which java`fi

4.修改jvm内存设置

进入config目录

1cd /opt/software/elasticsearch/elasticsearch-8.3.3/config/

根据配置的内存设置,修改文件jvm.options

12-Xms8g-Xmx8g

5.配置传输层TLS/SSL加密传输

Elasticsearch有两个级别的通信:传输层通信和HTTP层通信。传输协议用于Elasticsearch节点之间的内部通信,HTTP协议用于从客户端到Elasticsearch集群的通信。由于Elasticsearch集群中的每个节点都是客户端和集群中其他节点的服务器,因此所有传输证书都必须是客户端和服务器证书。

Elasticsearch附带了一个名为elasticsearch-certutil的实用程序,可用于生成加密Elasticsearch集群内部通信的自签名证书,证书生成命令如下:

输入密码那一块直接回车,不要设置密码 假如在生成证书的时候设置了密码,会导致无法启动ES

12bin/elasticsearch-certutil caENTER ENTER
12bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12ENTER ENTER ENTER

将生成的elastic-certificates.p12文件,放到
/opt/software/elasticsearch/elasticsearch-8.3.3/config的certs文件夹下6.修改 elasticsearch.yml这个文件

1vim /opt/software/elasticsearch/elasticsearch-8.3.3/config/elasticsearch.yml
1#节点名称node.name: node-1#允许所有ip访问network.host: 0.0.0.0#端口(默认9200)http.port: 9200#日志信息输出目录(按需求修改)path.data: /datalog/es/datapath.logs: /datalog/es/logs# 集群发现种子节点列表(集群部署配多个),默认["127.0.0.1"]discovery.seed_hosts: ["localhost"]# 手动指定可以成为 mater 的所有节点的 name 或者 ip,这些配置将会在第一次选举中进行计算(可配多>个)cluster.initial_master_nodes: ["node-1"]#自动写入的安全配置#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------# The following settings, TLS certificates, and keys have been automatically     # generated to configure Elasticsearch security features on 16-06-2022 06:41:20# --------------------------------------------------------------------------------# Enable security featuresxpack.security.enabled: truexpack.security.enrollment.enabled: true# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agentsxpack.security.http.ssl:  enabled: false  keystore.path: certs/elastic-certificates.p12# Enable encryption and mutual authentication between cluster nodesxpack.security.transport.ssl:  enabled: true  verification_mode: certificate  keystore.path: certs/elastic-certificates.p12  truststore.path: certs/elastic-certificates.p12

7.用创建的用户进行启动(root用户启动会失败)

进入 es 用户,执行以下操作

1234#启动sh /opt/software/elasticsearch/elasticsearch-8.3.3/bin/elasticsearch#后台启动sh /opt/software/elasticsearch/elasticsearch-8.3.3/bin/elasticsearch -d

运行后,等待一会,会出现下面的auth信息,可以把密码保存下 或者到时候重置

12Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):  tJIXQCjnPGP7IvY9C1nP

修改内置用户密码

修改密码需要在es启动,并cd到es的bin目录下执行:

1cd /opt/software/elasticsearch/elasticsearch-8.3.3/bin

1.重置密码并在控制台显示新密码(密码是自动生成的复杂度较高)

12./elasticsearch-reset-password -u 用户名例:重置 elastic 用户的密码 ./elasticsearch-reset-password -u elastic

2.自定义密码**==

1./elasticsearch-reset-password -u elastic -i admin123

8.查看elasticsearch运行状态

12345#方式1 jps5288 org.elasticsearch.bootstrap.Elasticsearch#方式2 ps aux | grep elasticsearch

9.浏览器访问elasticsearch

查看访问是否成功

1http://ip:9200/


用户名:elastic
密码:_=4xM2y8_oSZYMWJ5gp6
然后就登录成功了
10.正常状态下如果浏览器访问不到,需要开放elasticsearch对应的端口

#查看防火墙状态 :(active是绿的running表示防火墙开启)systemctl status firewalld.service#启动防火墙 :systemctl start firewalld.service#防火墙随系统开启启动 :systemctl enable firewalld.service#查询已经开放的端口 :firewall-cmd --list-port#开启端口 :firewall-cmd --zone=public --add-port=9200/tcp --permanent#重启防火墙 :firewall-cmd --reload

11.设置开机启动和后台运行(root用户)

1cd /usr/lib/system/system/

新建 elasticsearch.service

[Unit]Description=elasticsearchAfter=network.target [Service]Type=forkingUser=user-esExecStart=/opt/software/elasticsearch/elasticsearch-8.3.3/bin/elasticsearch -dPrivateTmp=true# 指定此进程可以打开的最大文件数LimitNOFILE=65535# 指定此进程可以打开的最大进程数LimitNPROC=65535# 最大虚拟内存LimitAS=infinity# 最大文件大小LimitFSIZE=infinity# 超时设置 0-永不超时TimeoutStopSec=0# SIGTERM是停止java进程的信号KillSignal=SIGTERM# 信号只发送给给JVMKillMode=process# java进程不会被杀掉SendSIGKILL=no# 正常退出状态SuccessExitStatus=143 [Install]WantedBy=multi-user. Target

执行设置开机启动

1systemctl enable elasticsearch.service
# 启动服务systemctl start elasticsearch.service# 重启服务systemctl restart elasticsearch.service# 停止服务systemctl stop elasticsearch.service# 禁止开机启动systemctl disable elasticsearch.service# 启用开机启动systemctl enable elasticsearch.service

四 可视化服务 ElasticView