close

Log Server在實際維運環境上除錯有著至關重要的作用,

有很多後續的功能也都需要收集log,

有很多監控系統也有收集log的相關掛件或功能.

Ex : cacti, icinga, ELK等等,

但這邊只介紹最簡單就可以實現的log collection solution. => Rsyslog

 

安裝步驟很簡單

1. Server安裝rsyslog ; Client安裝rsyslog或syslog

yum install -y rsyslog

yum install -y syslog

2. Server啟用remote log server

vi /etc/rsyslog.conf

$ModLoad imudp 
$UDPServerRun 514

$ModLoad imtcp 
$InputTCPServerRun 514 

3. Client設定reomote log address

vi /etc/rsyslog.conf

*.*   @logserver:port

(@ = UDP ; @@ = TCP)

4. 設定防火牆

firewall-cmd --permanent --zone=public --add-port=514/udp
firewall-cmd --permanent --zone=public --add-port=514/tcp
firewall-cmd --reload

5. Rsyslog Server設定template,說明如下,可參考Template processing

$template TemplateName,"/var/log/hosts/%HOSTNAME%-%PROGRAMNAME%-%YEAR%-%MONTH%-%DAY%.log"
*.*  ?RemoteLogs 
& ~

第一行設定一個$template 叫 TemplateName (可以自訂) ,記錄檔案存存放位置
第二行的*.*說明所有收到的logs應用TemplateName template
第三行說明僅記錄在log server上,也就是client本身不記錄 

這樣就可以陽春的收集log資料了.

額外補充,將nginx log也加入收集的行列

兩種方式皆可

1. rsyslog => imfile module

2. nginx => ngx_http_log_module

 

How to configure a syslog server with rsyslog on Linux
CentOS 啟動 Log Server 功能
Configuring a Syslog Agent in Windows Server 2012

arrow
arrow
    文章標籤
    rsyslog log server
    全站熱搜

    abcg5 發表在 痞客邦 留言(0) 人氣()