【问题标题】:Logrotate does not upload to S3Logrotate 不上传到 S3
【发布时间】:2015-02-21 05:34:29
【问题描述】:

我花了几个小时试图弄清楚为什么 logrotate 不能成功地将我的日志上传到 S3,所以我在这里发布我的设置。事情是这样的——当我像这样强制它时,logrotate 会将日志文件正确上传到 s3:

sudo logrotate -f /etc/logrotate.d/haproxy

Starting S3 Log Upload...
WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.
/var/log/haproxy-2014-12-23-044414.gz -> s3://my-haproxy-access-logs/haproxy-2014-12-23-044414.gz  [1 of 1]
 315840 of 315840   100% in    0s     2.23 MB/s  done

但作为正常 logrotate 过程的一部分,它不会成功。日志仍然被我的 postrotate 脚本压缩,所以我知道它正在运行。这是我的设置:

/etc/logrotate.d/haproxy =>

/var/log/haproxy.log {
    size 1k
    rotate 1
    missingok
    copytruncate
    sharedscripts
    su root root
    create 777 syslog adm
    postrotate
        /usr/local/admintools/upload.sh 2>&1 /var/log/upload_errors
    endscript
}

/usr/local/admintools/upload.sh =>

echo "Starting S3 Log Upload..."

BUCKET_NAME="my-haproxy-access-logs"

# Perform Rotated Log File Compression                                                                                                        
filename=/var/log/haproxy-$(date +%F-%H%M%S).gz                                                                                              \

tar -czPf "$filename" /var/log/haproxy.log.1

# Upload log file to Amazon S3 bucket                                                                                                         
/usr/bin/s3cmd put "$filename" s3://"$BUCKET_NAME"

这里是 logrotate 空运行的输出:

sudo logrotate -fd /etc/logrotate.d/haproxy
reading config file /etc/logrotate.d/haproxy

Handling 1 logs

rotating pattern: /var/log/haproxy.log  forced from command line (1 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/haproxy.log
  log needs rotating
rotating log /var/log/haproxy.log, log->rotateCount is 1
dateext suffix '-20141223'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/haproxy.log.1 to /var/log/haproxy.log.2 (rotatecount 1, logstart 1, i 1), 
renaming /var/log/haproxy.log.0 to /var/log/haproxy.log.1 (rotatecount 1, logstart 1, i 0), 
copying /var/log/haproxy.log to /var/log/haproxy.log.1
truncating /var/log/haproxy.log
running postrotate script
running script with arg /var/log/haproxy.log : "
        /usr/local/admintools/upload.sh 2>&1 /var/log/upload_errors
"
removing old log /var/log/haproxy.log.2

任何见解都值得赞赏。

【问题讨论】:

  • /var/log/upload_errors 的文件(或目录)是什么?如果是upload.sh的日志文件,那么命令应该是/usr/local/admintools/upload.sh >> /var/log/upload_errors 2>&1
  • set -x 添加为upload.sh 的第一行并查看消息
  • 是的,这让我畅通无阻。事实证明,我的 s3cmd 是为我的用户配置的,而不是为 root 配置的。 “错误:/root/.s3cfg:没有这样的文件或目录错误:配置文件不可用。错误:考虑使用 --configure 参数创建一个。”解决方案是复制我的配置文件。
  • 只是想评论一下,当您登录用户 ubuntu 并尝试执行 sudo s3cmd --configure 时,.s3cfg 文件仍会存储在 /home/ubuntu 中。如果您先执行sudo bash,则相同。我现在手动将.s3cfg 复制到/root/,我想明天我们会知道这是否有效。 @worker1138 如果您已解决此问题,请考虑将其添加为答案并标记为已解决。

标签: bash amazon-web-services amazon-s3 logrotate


【解决方案1】:

原来我的 s3cmd 是为我的用户配置的,而不是为 root 配置的。

ERROR: /root/.s3cfg: No such file or directory
ERROR: Configuration file not available.
ERROR: Consider using --configure parameter to create one.

解决方案是将我的配置文件复制过来。 – worker1138

【讨论】:

    猜你喜欢
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 2015-12-19
    • 2019-06-24
    • 2018-08-24
    • 2010-12-25
    • 2019-04-05
    相关资源
    最近更新 更多