Hugo博客公告弹窗

rsyslog配置方法

说明:日志中心指的是服务端,站点指的是客户端(你的网站)

日志中心配置

脚本

curl -sS -O https://raw.githubusercontent.com/woniu336/open_shell/main/deploy_server.sh && chmod +x deploy_server.sh

指定路径

./deploy_server.sh /data/log-center

日志轮转文件

cat /etc/logrotate.d/nginx-log-center

站点日志配置

  1. 添加日志格式

/etc/nginx/nginx.conf 在原本的log下方添加

    log_format syslog_combined
        '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $body_bytes_sent '
        '"$http_referer" "$http_user_agent" '
        'rt=$request_time '
        'uct=$upstream_connect_time '
        'uht=$upstream_header_time '
        'urt=$upstream_response_time';
  1. 站点日志脚本
curl -sS -O https://raw.githubusercontent.com/woniu336/open_shell/main/deploy_client.sh && chmod +x deploy_client.sh

运行脚本

./deploy_client.sh <日志中心IP> all

注意:转发后的日志不会保存在本地

站点恢复

BACKUP_DIR=$(ls -d /root/rsyslog_backup_* | tail -1) && \
cp -f "${BACKUP_DIR}/nginx.conf" /etc/nginx/ && \
cp -f "${BACKUP_DIR}/sites-available/"* /etc/nginx/sites-available/ && \
nginx -t && systemctl reload nginx && echo "✅ Nginx 配置已恢复并重载"

清理

curl -sS -O https://raw.githubusercontent.com/woniu336/open_shell/main/cleanup_rsyslog_client.sh && chmod +x cleanup_rsyslog_client.sh && ./cleanup_rsyslog_client.sh
CC BY-NC-SA 4.0 转载请注明
最后更新于 2026-01-22 14:49