Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

RedHat/CentOS 安装 Fluentd 日志收集器:从 Ruby 环境准备到 Gem 安装

編輯:關於 Linux

Fluentd 是基于 Ruby 的统一日志收集层,RedHat 系列安装需先准备 Ruby 环境(建议 1.9.3+),再通过 Gem 安装 Fluentd 及插件。本文记录编译安装 Ruby、Gem 安装 Fluentd、生成配置与服务化全过程。

一、编译安装 Ruby 1.9.3-p0(系统自带版本过旧)

# 安装编译依赖
yum install -y gcc make zlib-devel openssl-devel readline-devel libyaml-devel

# 下载编译
cd /usr/local/src
wget https://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
tar zxvf ruby-1.9.3-p0.tar.gz
cd ruby-1.9.3-p0
./configure --disable-install-doc
make
make install

# 验证
ruby -v
# ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

二、Gem 安装 Fluentd

gem install fluentd --no-document
# 忽略 "missing psych" 警告(需 libyaml,已在编译 Ruby 时包含)

# 生成默认配置
fluentd --setup ./fluent
# 输出:Installed ./fluent/fluent.conf.

三、启动测试

fluentd -c ./fluent/fluent.conf -vv &
# 后台运行,详细日志输出

四、系统服务化(Systemd / SysVinit)

Systemd (CentOS 7+):

cat > /etc/systemd/system/fluentd.service <<'EOF'
[Unit]
Description=Fluentd Logger
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/fluentd -c /etc/fluent/fluent.conf -v
Restart=on-failure
User=fluentd
Group=fluentd

[Install]
WantedBy=multi-user.target
EOF

useradd -r -s /sbin/nologin fluentd
mkdir -p /etc/fluent /var/log/fluent
chown fluentd:fluentd /etc/fluent /var/log/fluent
systemctl daemon-reload
systemctl enable --now fluentd

SysVinit (CentOS 6):

cp /usr/local/src/fluentd-*/files/RedHat-initd /etc/init.d/fluentd
chmod +x /etc/init.d/fluentd
chkconfig --add fluentd
chkconfig fluentd on
service fluentd start

五、常见问题排查

  • rake aborted! Unable to determine name from existing gemspec:RubyGems 版本过新与旧版 Fluentd 源码包不兼容。直接用 Gem 安装 可避免此问题。
  • missing psych:安装 libyaml-devel 后重新编译 Ruby。
  • 端口冲突:默认 24224,修改 fluent.conf port 参数。

Fluentd 安装示意图

编译安装新版 Ruby 再 gem install fluentd 是 RedHat 系列最省心的部署方式,避免源码包 Rake 任务兼容性问题。生产环境建议配置 in_tail 采集日志、out_forward 转发至聚合节点、out_elasticsearch 写入 ES 集群。

Copyright © Windows教程網 All Rights Reserved