Appearance
本文以演示环境如下:
操作系统 | 系统类型 | 作者 |
---|---|---|
kylinOS | x86_64 | 张世平 |
安装准备
工具准备(连接访问linux系统的工具)
WindTerm,远程访问Linux系统,输入命令使用;
下载地址:
https://sh.goodwaysoft.com:8257/WindTerm_2.6.0_Prerelease_2_Windows_Portable_x86_64.zip
WinSCP,远程访问Linux系统,复制代码文件、修改Nginx配置项使用;
下载地址:https://sh.goodwaysoft.com:8257/WinSCP-6.1.1-Setup.exe
使用方法:
用WindTerm、WinSCP远程连接Linux系统
解压WindTerm后,双击运行WindTerm.exe 在会话页面,右键‘新建会话’
主机:(H) Linux系统IP地址;端口:(P) 22 默认端口,可修改;OneKey:设置Linux系统的用户名,密码
添加完成后,双击会话列表中的linux系统地址,进入linux命令页面;
注意:双击linux系统地址时,此处需要下拉选择设置的密码;WinSCP远程连接Linux系统,在‘新建标签页’,添加Linux的访问方式,配置方式同WindTerm一样
搭建elasticsearch8.13.2
查看linux cpu类型,然后根据类型下载
uname -m
#结果是: Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
官网下载
下载对应版本的elasticsearch
https://www.elastic.co/cn/downloads/past-releases/elasticsearch-8-13-2
复制安装包到Linux
使用WinSCP远程工具,把安装包复制到linux系统中
/opt
解压软件
cd /opt
# 解压缩
tar -zxvf elasticsearch-8.13.2-linux-x86_64.tar.gz
创建用户
Elasticsearch 不允许 root 用户直接运行,所以要创建新用户,在 root 用户中创建新用户。
useradd es #新增 es 用户
passwd es #为 es 用户设置密码,例`elasticadmin`
chown -R es:es /opt/elasticsearch-8.13.2 #文件夹所有者
userdel -r es #如果错了,可以删除再加
前置准备
每个进程可以打开的文件数的限制,进入文件夹/etc/security/,打开文件limits.conf,在文件末尾新增
es hard nproc 4096
es soft nproc 4096
打开文件/etc/sysctl.conf,设置一个进程可以拥有的 VMA(虚拟内存区域)的数量,默认值为 65536,在文件末尾新增
vm.max_map_count=655360
保存后执以下命令使配置生效
sudo sysctl -p
第一个节点的配置文件
使用WinSCP远程工具,进入/opt/elasticsearch-8.13.2/config/目录下,双击打开elasticsearch.yml文件
注意此处可直接复制以下内容,粘贴覆盖替换原有的内容,如有疑问,可备份原有的elasticsearch.yml文件,在粘贴替换;
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /opt/elasticsearch-8.13.2/data
#
# Path to log files:
#
path.logs: /opt/elasticsearch-8.13.2/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: 127.0.0.1
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 20-05-2024 07:00:37
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: false
xpack.security.enrollment.enabled: true
xpack.security.http.ssl.enabled: false
xpack.security.transport.ssl.enabled: false
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
http.cors.enabled: true
http.cors.allow-origin: "*"
修改jvm.options文件,限制ES内存占用大小
使用WinSCP远程工具,进入到/opt/elasticsearch-8.13.2/config文件夹下,双击打开jvm.options文件
-Xms4g
-Xmx4g
启动elasticsearch
切换到es账号,使用WindTerm.exe工具,进入到/opt/elasticsearch-8.13.2文件夹下,启动es
cd /opt/elasticsearch-8.13.2
bin/elasticsearch -d
验证elasticsearch是否启动
使用WindTerm.exe工具,执行命令
curl 127.0.0.1:9200
或者直接在浏览器中输入:http://10.10.1.202:9200
重启elasticsearch
使用WindTerm.exe工具,执行命令
ps -ef|grep elasticsearch
kill 10897
设置elasticsearch开机自启
1.使用WinSCP远程工具,进入到/etc/systemd/system文件夹,新建文件es.service
2.修改es.service文件
[Unit]
Description=Elasticsearch
After=network.target
[Service]
Type=simple
User=es
Group=es
ExecStart=/opt/elasticsearch-8.13.2/bin/elasticsearch
Restart=on-failure
[Install]
WantedBy=multi-user.target
4.设置开机自启 注册并启动启动服务
sudo systemctl enable es.service
(启动服务)
sudo systemctl start es.service
检查服务状态:
sudo systemctl status es.service
重启服务:
sudo systemctl restart es.service
检查服务状态:
sudo systemctl status es.service
关闭服务:
sudo systemctl stop es.service