首页
/ 项目技术文档:remote_syslog

项目技术文档:remote_syslog

2024-12-20 19:23:54作者:贡沫苏Truman

1. 安装指南

安装步骤

  1. 使用以下命令安装 remote_syslog gem:

    $ [sudo] gem install remote_syslog
    
  2. 可选步骤:创建一个 log_files.yml 文件,指定要读取的日志文件路径以及日志发送的目标主机和端口(参考 examples/log_files.yml.example)。这些配置也可以通过命令行参数指定。

自动启动

  1. 将示例的 init 文件复制到系统中:

    $ cp examples/remote_syslog.init.d /etc/init.d/remote_syslog
    $ chmod 755 /etc/init.d/remote_syslog
    
  2. 确保 remote_syslog 在系统启动时自动启动:

    $ sudo update-rc.d remote_syslog defaults
    

    或者手动创建链接:

    $ sudo ln -s /etc/init.d/remote_syslog /etc/rc3.d/S30remote_syslog
    

使用 RVM

如果使用 Ruby 版本管理器(如 RVM),需要在 init 文件中加载 RVM 环境。可以参考 RVM 的 init.d 集成指南 创建一个 wrapper 脚本。

2. 项目使用说明

基本用法

$ remote_syslog [OPTION]... <FILE>...

常用选项

  • -c, --configfile PATH:指定配置文件路径(默认 /etc/log_files.yml
  • -d, --dest-host HOSTNAME:指定目标 syslog 主机名或 IP(默认 logs.papertrailapp.com
  • -p, --dest-port PORT:指定目标 syslog 端口(默认 514
  • -D, --no-detach:不以守护进程方式运行
  • -f, --facility FACILITY:指定设施(默认 user
  • --hostname HOST:指定本地主机名
  • -P, --pid-dir DIRECTORY:已弃用:指定 PID 文件目录
  • --pid-file FILENAME:指定 PID 文件路径(默认 /var/run/remote_syslog.pid
  • --parse-syslog:解析文件为 syslog 格式
  • -s, --severity SEVERITY:指定日志级别(默认 notice
  • --strip-color:去除颜色代码
  • --tls:通过 TLS 连接
  • --tcp:通过 TCP 连接(无 TLS)
  • --new-file-check-interval INTERVAL:检查新文件的时间间隔

示例

  1. 使用配置文件 configs/logs.yml 和端口 12345 发送 /var/log/mysqld.log 的日志:

    $ remote_syslog -c configs/logs.yml -p 12345 /var/log/mysqld.log
    
  2. 不以守护进程方式运行,使用 /etc/log_files.yml 配置文件,PID 文件路径为 /tmp/remote_syslog.pid,发送日志到 a.example.com:514

    $ remote_syslog -D -d a.example.com -f local0 --pid-file /tmp/remote_syslog.pid /var/log/mysqld.log
    

3. 项目API使用文档

配置文件格式

log_files.yml 文件格式如下:

files:
  - /var/log/httpd/access_log
  - /var/log/httpd/error_log
  - /var/log/mysqld.log
  - /var/run/mysqld/mysqld-slow.log
destination:
  host: logs.papertrailapp.com
  port: 12345

高级配置

  1. 覆盖主机名

    hostname: somehostname
    
  2. 验证服务器证书

    ssl_server_cert: syslog.crt
    
  3. 使用客户端证书

    ssl_client_cert_chain: syslog_client.crt
    ssl_client_private_key: syslog_client.key
    
  4. 排除文件

    exclude_files:
      - \.\d$
      - .bz2
      - .gz
    

4. 项目安装方式

安装命令

$ [sudo] gem install remote_syslog

配置文件

默认情况下,remote_syslog 会查找 /etc/log_files.yml 配置文件。可以参考 examples/log_files.yml.example 创建配置文件。

启动命令

$ remote_syslog -c configs/logs.yml -p 12345 /var/log/mysqld.log

自动启动

通过 init 文件或手动启动脚本实现自动启动。

登录后查看全文
热门项目推荐