CentOS安装最新版 Elasticsearch和Filebeat

以下是在基于 RPM 的 Linux 系统(如 CentOS、RHEL、Oracle Linux 等)上安装最新版 Elasticsearch 和 Filebeat(当前为 8.18.1)的完整步骤。

一、安装 Elasticsearch

1. 下载并安装 RPM 包

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.18.1-x86_64.rpm
sudo rpm --install elasticsearch-8.18.1-x86_64.rpm

安装的时候,终端将输出 elastic 用户的默认密码和 TLS 证书路径。请妥善保存这些信息。

2. 启动并设置开机自启

sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service

3. 配置 Elasticsearch(可选)

编辑配置文件 /etc/elasticsearch/elasticsearch.yml,根据需求进行以下修改:

network.host: 0.0.0.0
http.port: 9200

修改后,重启服务以应用配置:

sudo systemctl restart elasticsearch

二、安装 Filebeat

1. 下载并安装 RPM 包

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.18.1-x86_64.rpm
sudo rpm -vi filebeat-8.18.1-x86_64.rpm

2. 启动并设置开机自启

sudo systemctl enable filebeat.service
sudo systemctl start filebeat.service

3. 配置 Filebeat

编辑配置文件 /etc/filebeat/filebeat.yml,设置日志输入和输出。例如,采集 Nginx 日志并发送到 Elasticsearch:

filebeat.inputs:
  - type: log
    enabled: true
    paths:
      - /var/log/nginx/access.log
      - /var/log/nginx/error.log

output.elasticsearch:
  hosts: ["http://localhost:9200"]
  username: "elastic"
  password: "your_elastic_password"