Fluentd 是基于 Ruby 的统一日志收集层,RedHat 系列安装需先准备 Ruby 环境(建议 1.9.3+),再通过 Gem 安装 Fluentd 及插件。本文记录编译安装 Ruby、Gem 安装 Fluentd、生成配置与服务化全过程。
# 安装编译依赖
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 install fluentd --no-document
# 忽略 "missing psych" 警告(需 libyaml,已在编译 Ruby 时包含)
# 生成默认配置
fluentd --setup ./fluent
# 输出:Installed ./fluent/fluent.conf.
fluentd -c ./fluent/fluent.conf -vv &
# 后台运行,详细日志输出
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 参数。
编译安装新版 Ruby 再 gem install fluentd 是 RedHat 系列最省心的部署方式,避免源码包 Rake 任务兼容性问题。生产环境建议配置 in_tail 采集日志、out_forward 转发至聚合节点、out_elasticsearch 写入 ES 集群。
利用 iptables 配置檔與腳本實現主備防火牆規則自動同步備份
Ubuntu 關閉螢幕自動鎖定:系統設定 → 亮度與鎖定 → 關閉鎖定選項
Xshell 與 Xftp 遠程管理工具安裝與連線設定圖文教學
Linux 終端機 11 個必學高效操作技巧:快捷鍵、sudo!!、背景執行、nohup、at 排程
Linux Apache 解決 GBK/GB2312 網頁亂碼:httpd.conf AddDefaultCharset 五種修正方案
Linux 安裝 fcitx 輸入法框架:套件管理器安裝、重啟、加入輸入法列表
ping 網路診斷基石:ICMP 回送請求、Linux/Windows 差異、參數全表、統計解讀、防火牆封鎖、回送封包結構、實戰排查