Apache - 如何透過 rsyslog 服務同步寫 log
Published in:2022-08-03 | category: Web

“Apache 透過 rsyslog 同步寫 LOG 到其他台機器”

編輯 Apache 設定檔

vim /etc/httpd/conf/httpd.conf
ErrorLogFormat "[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %O %I %T %b \"%{Referer}i\" \"%{User-Agent}i\"" nreporter
</IfModule>
CustomLog "logs/access-NReporter_log" nreporter

重啟 Apache 服務和確認 Apache 服務狀態

systemctl restart httpd && systemctl status httpd

編輯 rsyslog 設定檔

vim /etc/rsyslog.conf
```    
    
   
    ###MODULES###
    $ModLoad imfile # provides support for file logging
    # Send Apache log to N-Reporter
    input(type="imfile" File="/var/log/httpd/access-NReporter_log" Tag="apache" Severity="info" Facility="local6"
    Ruleset="nreporter")
    input(type="imfile" File="/var/log/httpd/error_log" Tag="apache" Severity="warning" Facility="local6"
    Ruleset="nreporter")
    ruleset(name="nreporter"){action(type="omfwd" Target="192.168.2.69" Port="514" Protocol="udp")}


## 重啟 Rsyslog 服務和確認 Rsyslog 服務正常
    
```sql
systemctl restart rsyslog && systemctl status rsyslog

Prev:
SVN - error - undefined symbol: svn_fs_util__version
Next:
CentOS - 目錄沒顯示顏色