rsyslog
服務為 Client/Server
服務,可同時實現兩種角色。
它可以作為服務器運行並收集網路中其他設備傳輸的所有日誌。
可以將所有記錄到遠程終端系統
syslog server
的 internal system events 發送到 Client 運行。
environment
- Ubuntu 14.04 Rsyslog Server
- Ubuntu 14.04 Client
- D-link
Installation and configuration
預設上,只要安裝好 Ubuntu
都會有 rsyslog
verify
dpkg --list
查看已安裝的套件
itachi@ubuntu:~$ dpkg --list | grep rsyslog
ii rsyslog 7.4.4-1ubuntu2.6 amd64 reliable system and kernel logging daemon
rsyslogd -v
查看版本
itachi@ubuntu:~$ rsyslogd -v
rsyslogd 7.4.4, compiled with:
FEATURE_REGEXP: Yes
FEATURE_LARGEFILE: No
GSSAPI Kerberos 5 support: Yes
FEATURE_DEBUG (debug build, slow code): No
32bit Atomic operations supported: Yes
64bit Atomic operations supported: Yes
Runtime Instrumentation (slow code): No
uuid support: Yes
See http://www.rsyslog.com for more information.
configuration
- 配置檔所在位置
rsyslog.d/
是被 include
到 rsyslog.conf
itachi@ubuntu:~$ ll /etc/ | grep syslog
-rw-r--r-- 1 root root 1318 Oct 24 11:20 rsyslog.conf
drwxr-xr-x 2 root root 4096 Oct 24 10:50 rsyslog.d/
- 編輯
.conf
檔
514 Port
向 Rsyslog server
提供 UDP
TCP
傳輸和接收。 UDP
是由 Rsyslog
用於 log
傳輸的標準協定UDP
傳輸會比 TCP
要來的快,但 UDP
不能保證傳輸數據的可靠性。
itachi@ubuntu:~$ sudo vi /etc/rsyslog.conf
# 找到下四行取消註解
...
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
...
- 查看
514 Port
有無開啟
itachi@ubuntu:~$ sudo netstat -tulpn | grep rsyslog
tcp 0 0 0.0.0.0:514 0.0.0.0:* LISTEN 1907/rsyslogd
tcp6 0 0 :::514 :::* LISTEN 1907/rsyslogd
udp 0 0 0.0.0.0:514 0.0.0.0:* 1907/rsyslogd
udp6 0 0 :::514 :::* 1907/rsyslogd
Define template for the logs
itachi@ubuntu:~$ sudo vim /etc/rsyslog.conf
...
# 新增以下三行
$template RemoteLogs,"/var/log/%HOSTNAME%/%PROGRAMNAME%.log" *
*.* ?RemoteLogs
& ~
# provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
# Enable non-kernel facility klog messages
$KLogPermitNonKernelFacility on
###########################
#### GLOBAL DIRECTIVES ####
###########################
...
參數介紹
- RemoteLogs
- template name
- HOSTNAME
- client machine name
- PROGRAMNAME
- client machine application
- *.*
- . :代表比後面還要嚴重的等級(含該等級)都被記錄下來。
- .=:代表所需要的等級就是後面接的等級而已, 其他的不要。
- .!:即是低於這個等級的才會被紀錄的意思。
- *:表示所有等級(
priority
orfacility
)。
- & ~
- redirect rule(停止較舊的日誌記錄並啟用此新的日誌記錄)。
服務重啟
itachi@ubuntu:~$ sudo service rsyslog restart
rsyslog stop/waiting
rsyslog start/running, process 1907
Application
D-link
在 D-link
下設定 rsyslog
,輸入 rsyslog Server IP
Client
修改 Hostname
,為了好辨識。
itachi@logClient:~$ sudo vi /etc/hosts
127.0.0.1 localhost
127.0.1.1 logClient
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
itachi@logClient:~$ sudo vi /etc/hostname
logClient
系統 reboot。
- 新增
remoteIP
itachi@logClient:~$ sudo vim /etc/rsyslog.conf
*: * @192.168.7.137:514 #新增此行
必須重啟服務
rsyslog Server
- 驗證(無
template
)
itachi@ubuntu:/var/log$ tail -f /var/log/syslog
- 驗證(有
template
)
其中 擁有者和群組權限為 syslog
,是以 /etc/rsyslog.conf
設定如下:
beladmin@Rsyslog:/var/log$ cat /etc/rsyslog.conf
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog
beladmin@Rsyslog:~$ cd /var/log/
beladmin@Rsyslog:/var/log$ ls -lt
...
drwx------ 2 syslog syslog 4096 Nov 27 12:01 192.168.7.12 # 以 Client Hostname 命名的資料夾,亦即存放 ESXi Log 資料夾
drwx------ 2 syslog syslog 4096 Nov 27 11:54 192.168.7.1 # 以 Client Hostname 命名的資料夾,亦即存放 DHCP Log 資料夾
...
ESXi
setting
主機 > 組態 > 進階設定 > syslog > global,填入遠端rsyslog Server Host。
Syslog.global.logHost
設置 udp://192.168.7.19:514
checking
查看 loghost
是否有遠端
[root@localhost:~] cat /etc/vmsyslog.conf
[DEFAULT]
rotate = 8
check_ssl_certs = true
logdir = <none>
default_timeout = 180
drop_log_rotate = 10
queue_drop_mark = 90
size = 1024
logdir_unique = false
loghost = <none>
drop_log_size_kb = 100
[vmsyslog]
rotate = 8
size = 1024
logdir_unique = false
loghost = udp://192.168.7.19:514
參考資訊,ESXi 主機設定 syslog
額外資訊
facility
- auth = messages generated by authentication processes (login)
- cron= messages generated by scheduled processes (crontab)
- daemon = messages generated by daemons (internal services)
- kernel = messages generated by the Linux Kernel itself
- mail = messages generated by a mail server
- syslog = messages generated by the rsyslog daemon itself
- lpr = messages generated by local printers or a print server
- local0 – local7 = custom messages defined by an administrator (local7 is usually assigned for Cisco or Windows)
priority
- emerg = Emergency – 0
- alert = Alerts – 1
- err = Errors – 3
- warn = Warnings – 4
- notice = Notification – 5
- info = Information – 6
- debug = Debugging – 7
Special Rsyslog keywords:
- * = all facilities or priorities
- none = the facilities have no given priorities Eg: mail.none
資料參考
URL:https://www.wikiwand.com/en/Syslog