CentOS 7.6 在线安装 Elasticsearch 8.13.3 并进行配置

以下是关于在CentOS 7上在线安装Elasticsearch 8.13.3、配置密码、配置内存大小、禁用HTTPS以及修改数据目录的完整文档。


CentOS 7.6 在线安装 Elasticsearch 8.13.3 并进行配置

1. 安装依赖

1.1 安装 Java

Elasticsearch 需要 Java 运行环境。推荐使用 OpenJDK 11。

bash 复制代码
sudo yum install java-11-openjdk-devel -y

1.2 导入 Elasticsearch GPG 密钥

bash 复制代码
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

1.3 添加 Elasticsearch 仓库

创建并编辑仓库配置文件 /etc/yum.repos.d/elasticsearch.repo

bash 复制代码
sudo vi /etc/yum.repos.d/elasticsearch.repo

添加以下内容:

ini 复制代码
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

2. 安装 Elasticsearch 8.13.3

使用 yum 安装 Elasticsearch:

bash 复制代码
sudo yum install elasticsearch-8.13.3

3. 配置 Elasticsearch

3.1 配置 Elasticsearch

编辑 Elasticsearch 配置文件 /etc/elasticsearch/elasticsearch.yml

bash 复制代码
sudo vi /etc/elasticsearch/elasticsearch.yml

修改或添加以下配置项:

yaml 复制代码
# 集群名称
cluster.name: my-application

# 节点名称
node.name: node-1

# 数据目录
path.data: /path/to/your/data

# 日志目录
path.logs: /path/to/your/logs

# 网络绑定地址
network.host: 0.0.0.0

# HTTP 端口
http.port: 9200

# 禁用 HTTPS
xpack.security.http.ssl:
  enabled: false

注意:将 /path/to/your/data/path/to/your/logs 替换为您希望使用的数据和日志目录路径。

3.2 配置 JVM 内存大小

编辑 JVM 配置文件 /etc/elasticsearch/jvm.options.d/jvm.options(如果该目录下没有配置文件,则编辑 /etc/elasticsearch/jvm.options):

bash 复制代码
sudo vi /etc/elasticsearch/jvm.options

找到并修改以下内容,以配置内存大小(例如:将其设置为 4GB):

bash 复制代码
-Xms4g
-Xmx4g

-Xms-Xmx 分别设置最小和最大堆内存大小。建议这两个值设置相同。

4. 启动并启用 Elasticsearch

启动 Elasticsearch 服务并设置为开机启动:

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch

5. 设置 Elasticsearch 用户密码

Elasticsearch 8.x 默认启用了安全功能。启动后需要为默认用户(如 elastic 用户)设置密码:

bash 复制代码
/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic -i

输入您希望设置的密码(例如:slsakajka87)。

6. 验证 Elasticsearch 安装

通过以下命令验证 Elasticsearch 是否已成功安装和配置:

bash 复制代码
curl -u elastic:slsakajka87 -X GET "http://localhost:9200/"

如果配置正确,您将看到 Elasticsearch 的版本信息。

7. 配置防火墙

确保防火墙允许 Elasticsearch 的默认端口 9200:

bash 复制代码
sudo firewall-cmd --zone=public --add-port=9200/tcp --permanent
sudo firewall-cmd --reload

8. 测试 Elasticsearch

您可以通过浏览器访问 http://<your-server-ip>:9200,使用 elastic 用户和您设置的密码 slsakajka87 进行访问。如果一切正常,您将看到 Elasticsearch 的欢迎页面和版本信息。


这样,您就完成了在 CentOS 7 上安装 Elasticsearch 8.13.3,并完成了密码配置、内存大小设置、禁用 HTTPS 以及修改数据目录的所有步骤。这将确保您的 Elasticsearch 部署运行良好且符合您的特定需求。

相关推荐
知秋正在9963 分钟前
ElasticSearch服务端报错:FileSystemException: No space left on device
大数据·elasticsearch·搜索引擎
一个大专生的淘汰之路2 小时前
Elasticsearch 如何确保新增文档立即可见?
elasticsearch
知秋正在9963 小时前
ElasticSearch服务端报错:system call filters failed to install
大数据·elasticsearch·搜索引擎
Elasticsearch4 小时前
Elastic Streams 介绍
elasticsearch
悟能不能悟5 小时前
登录jenkins默认用户密码
运维·jenkins
礼拜天没时间5 小时前
CentOS-7 修改网卡
centos
小锋学长生活大爆炸6 小时前
【教程】CentOS在不知道root密码的情况下进入shell和重置密码
linux·运维·centos
AL流云。7 小时前
MySQL安装【Centos, Ubuntu, Windows】
mysql·ubuntu·centos
知秋正在9968 小时前
ElasticSearch服务端报错:Unrecognized VM option ‘UseAVX=2‘
大数据·elasticsearch·jenkins
UVM_ERROR8 小时前
硅农VSCode 插件推荐
vscode·centos·ssh