Centos7 配置rsyslog客戶端接收遠程日志


因為路由器我設定每天重啟,但是日志一重啟就會清除,並且路由器最多只能保存1024條記錄,所以我想把路由器的日志記錄到一台服務器上,發現路由器包含遠程日志功能

路由器遠程日志

於是我就在我的centos7服務器配置了下rsyslog,把日志記錄到這里

編輯服務端/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

客戶端直接填寫ip,端口默認是514,就完成了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM