搭建rsyslog日志服务器记录RouterOS路由器日志

8 篇文章 1 订阅
2 篇文章 0 订阅

1.搭建原因:

        需要收集RouterOS路由的日志信息到mysql中,以便于后续查看

2.所需环境:

        RouterOS,centos7.6,mysql5.7.28

3.RouterOS路由器的日志设置:

        ①设置需要收集的日志类型

               因为我需要收集的是script的日志信息,所以我选择的topic是script

                action选择remote表示发送到远程日志服务器

        

         ②设置远程日志服务器的IP和端口

                注意:根据自己的实际情况设置自己的日志服务器的Ip和端口

                

 4.日志服务器配置:

        ①在服务器上安装好centos7.6的系统

        ②在安装好的centos7.6系统上安装rsyslog                  

# 安装rsyslog软件
[root@rsyslog_10_250 ~]# yum -y install rsyslog
# 安装rsyslog-mysql软件与mysql通信
[root@rsyslog_10_250 ~]# yum -y install rsyslog-mysql

        ③配置rsyslog,配置文件如下(/etc/rsyslog.conf):

          

[root@rsyslog_10_250 ~]# cat /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
# 开启udp 514收集日志
$ModLoad imudp
$UDPServerRun 514

# Provides TCP syslog reception

# 开启tcp 514收集日志
$ModLoad imtcp
$InputTCPServerRun 514

# 加载mysql模块,添加了此模块才能将收集到的日志写入到mysql中
$ModLoad ommysql

#### GLOBAL DIRECTIVES ####

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

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# 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.
#kern.*                                                 /dev/console

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog


# Log cron stuff
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

# 配置需要写入到数据库的日志类型及mysql的连接信息(syslog是库名,loguser是数据库用户,123456是用户密码)
user.*                                                    :ommysql:127.0.0.1,Syslog,loguser,123456

# ### 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 main # 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 ###

5.数据库配置:

①找到数据库的模板文件:

[root@rsyslog_10_250 ~]# rpm -ql rsyslog-mysql
/usr/lib64/rsyslog/ommysql.so
/usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql

②导入数据库文件(注意:根据实际情况填写数据库登录账号和密码)

[root@rsyslog_10_250 ~]# mysql -uroot -p123456 < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql

③添加数据授权(注意:根据实际情况填写数据库登录账号和密码)

mysql> GRANT ALL PRIVILEGES ON Syslog.* TO 'loguser'@'%'IDENTIFIED BY '123456';

6.启动服务:

# 启动数据库服务,启动失败检查数据库配置
[root@rsyslog_10_250 ~]# systemctl restart mysqld
[root@rsyslog_10_250 ~]# systemctl enable mysqld
# 启动rsyslog服务,启动失败检查rsyslog配置信息
[root@rsyslog_10_250 ~]# systemctl restart rsyslog.service
[root@rsyslog_10_250 ~]# systemctl enable rsyslog.service

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值