中標麒麟V7.4環境下搭建rsyslog日誌服務器

由於網絡及安全設備等存儲空間很小,導致日誌存儲時間不足,因此需要搭建rsyslog日誌服務器。此日誌服務器爲簡約版,僅僅以文件方式存儲日誌。

一、搭建目標:
日誌文件存放在/var/log文件夾下,每天按日期創建日誌文件夾。`

二、測試環境:
服務端:Centos7 和中標麒麟V7.4版本下測試成功。
客戶端:華三45xx交換機、華爲2700交換機、銳捷20-X路由器、銳捷78xx交換機、網禦漏掃均能正常上報debug日誌。

編輯服務端的/etc/rsyslog.conf文件
注意下中文註釋地方

# rsyslog configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES ####

# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark  # provides --MARK-- message capability

# Provides UDP syslog reception
$ModLoad imudp  #** 引用udp協議的模塊**
$UDPServerRun 514  # **設置udp協議使用端口**

# Provides TCP syslog reception
$ModLoad imtcp  # **引用tcp協議的模塊**
$InputTCPServerRun 514  #** 設置tcp協議使用端口**

#### GLOBAL DIRECTIVES ####

# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

$template Remote,"/var/log/%$YEAR%-%$MONTH%-%$DAY%/%fromhost-ip%.log" # ****設置遠程日誌存放路徑和文件格式****
:fromhost-ip, !isequal, "127.0.0.1" ?Remote  #** 如果是本機日誌則不記錄**

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal
$IMJournalStateFile imjournal.state

#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
# **關於內核的所有日誌都放到/dev/console(控制檯)**
#kern.*                                                 /dev/console  

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
# 記錄所有日誌類型的info級別以及大於info級別的信息到/var/log/messages,但是mail郵件信息,authpriv驗證方面的信息和cron時間任務相關的信息除外
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.
# authpriv驗證相關的所有信息存放在/var/log/secure
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
# 郵件的所有信息存放在/var/log/maillog; 這裏有一個-符號, 表示是使用異步的方式記錄, 因爲日誌一般會比較大
mail.*                                                  -/var/log/maillog

# Log cron stuff
# 計劃任務有關的信息存放在/var/log/cron
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
# 啓動的相關信息
*.emerg                                                 :omusrmsg:*

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log

# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList   # run asynchronously
#$ActionResumeRetryCount -1    # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###```

三、重啓rsyslog
systemctl restart rsyslog
systemctl status rsyslog # 必須查看rsyslog是否正常啓動(很多按網上的問價格配置完後,查看狀態會提示沒有權限創建文件夾或文件信息,那此文檔就不能使用)

查看監聽端口
netstat -antup |grep 514
[root@localhost ~]# netstat -uanp|grep rsyslog
tcp 0 0 0.0.0.0:514 0.0.0.0: LISTEN 20228/rsyslogd
tcp 0 0 :::514 ::: LISTEN 20228/rsyslogd
udp 0 0 0.0.0.0:514 0.0.0.0: 20228/rsyslogd
udp 0 0 :::514 ::: 20228/rsyslogd*

四、關閉防火牆
systemctl stop firewalld #根據各自系統命令關閉防火牆
systemctl disable firewalld
systemctl status firewalld

五、查看日誌
cd /var/log
ll

六、客戶端配置(可供參考)

華爲設備syslog配置:
info-center loghost source Vlanif1
info-center loghost 1.1.1.1 #日誌服務地址

華三設備syslog配置:
info-center loghost source Vlan-interface30
info-center loghost 1.1.1.1 #日誌服務地址

銳捷設備syslog配置:
logging enable
logging trap debugging #銳捷debugging級別就是7,爲所有日誌
logging source interface GigabitEthernet 0/2
logging server 1.1.1.1 #日誌服務地址

以上部分內容參考此鏈接:
https://note.guotianyu.cn/linux/centos7-rsyslog.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章