1. 下载并解压安装

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.17.22-linux-x86_64.tar.gz
tar xzvf filebeat-7.17.22-linux-x86_64.tar.gz
mv filebeat-7.17.22-linux-x86_64 /usr/local/filebeat

编写 filebeat.service

vi /usr/local/filebeat/filebeat.service
[Unit]
Description=Filebeat sends log files to Logstash or directly to Elasticsearch.
Documentation=https://www.elastic.co/beats/filebeat
Wants=network-online.target
After=network-online.target

[Service]

Environment="GODEBUG='madvdontneed=1'"
Environment="BEAT_LOG_OPTS="
Environment="BEAT_CONFIG_OPTS=-c /etc/filebeat/filebeat.yml"
Environment="BEAT_PATH_OPTS=--path.home /usr/share/filebeat --path.config /etc/filebeat --path.data /var/lib/filebeat --path.logs /var/log/filebeat"
ExecStart=/usr/share/filebeat/bin/filebeat --environment systemd $BEAT_LOG_OPTS $BEAT_CONFIG_OPTS $BEAT_PATH_OPTS
Restart=always

[Install]
WantedBy=multi-user.target

创建服务链接

ln -s /usr/local/filebeat/filebeat.service /usr/lib/systemd/system/filebeat.service

使服务生效

systemctl deamon-reload

2. 使用源安装

2.1 yum/dnf 中安装

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

安装 elastic 7.x 源

vi /etc/yum.repos.d/elastic.repo

[elastic-7.x]
name=Elastic repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

安装 filebeat

yum install filebeat

systemctl enable filebeat

# 如果不是使用 system
chkconfig --add filebeat

2.2 apt/apt-get 中安装

下载并安装公共签名密钥:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

在继续之前,您可能需要在Debian上安装 apt-transport-https 包:

sudo apt-get install apt-transport-https

将存储库定义保存到/etc/apt/sources.list.d/elastic-7.x.list

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

安装

sudo apt-get update && sudo apt-get install filebeat

sudo systemctl enable filebeat
# 或(如果不是使用 systemctl)
sudo update-rc.d filebeat defaults 95 10
作者:admin  创建时间:2023-10-19 19:19
最后编辑:admin  更新时间:2024-06-28 10:25