centos7.2部署syslog服务

停止并禁用防火墙

  • firewall-cmd --state
  • systemctl stop firewalld.service
  • systemctl disable firewalld.service
  • systemctl status firewalld.service

停用iptables

  • systemctl status iptables.service
  • systemctl stop iptables.service

检查是否安装rsyslogd

[root@localhost sbin]$ rpm -qa|grep syslog
rsyslog-7.4.7-12.el7.x86_64
[root@localhost ~]# whereis rsyslogd
rsyslogd: /usr/sbin/rsyslogd /usr/share/man/man8/rsyslogd.8.gz 

rpm是redhat的包管理工具,即Redhat Package Manager。rpm is a powerful Package Manager, which can be used to build, install, query, verify, update, and erase individual software packages. A package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package. Packages come in two varieties: binary packages, used to encapsulate software to be installed, and source packages, containing the source code and recipe necessary to produce binary packages.`

  • rpm的默认安装路径
目录 说明
/etc 设置文件放置的目录,如/etc/httpd
/usr/bin 可执行文件
/usr/lib 程序使用的动态函数库
/usr/share/doc 基本的软件使用手册与帮助文档
/usr/share/man man page文件

rsyslog服务命令

  • yum install rsyslog
  • systemctl status rsyslog
  • systemctl start rsyslog
  • systemctl stop rsyslog
  • systemctl restart rsyslog
  • 检查是否启动成功
[root@localhost ~]# netstat -antup|grep syslog
tcp        0      0 0.0.0.0:514             0.0.0.0:*               LISTEN      22592/rsyslogd      
tcp6       0      0 :::514                  :::*                    LISTEN      22592/rsyslogd      
udp        0      0 0.0.0.0:514             0.0.0.0:*                           22592/rsyslogd      
udp6       0      0 :::514                  :::*                                22592/rsyslogd

关键的配置(/etc/rsyslog.conf)

#启用rsyslog从ud 514端口接收日志
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

#启用rsyslog从tcp 514端口接收日志
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
  • 日志默认记录在/var/log/messages
    当有客户端接入后,tail -f /var/log/messages就能看到日志。
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.debug;mail.none;authpriv.none;cron.none                /var/log/messages
  • 是否将日志转发到其它syslog服务器
    取消如下注释
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
*.* @10.41.4.89:514 #udp
*.* @@10.41.4.89:514 #tdp

/etc/rsyslog.conf

[root@116fumin log]# 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

#启用rsyslog从ud 514端口接收日志
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

#启用rsyslog从tcp 514端口接收日志
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514

#创建日志模板
#$template RemoteLogs,"/var/log/qiaosong_messages.log"
#*.* ?RemoteLogs
#& ~



#### 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!
*.debug;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


# ### 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
#*.* @10.10.10.89:514
# ### end of the forwarding rule ###

参考文章
https://blog.csdn.net/senlin1202/article/details/50800385/
https://blog.csdn.net/qq_40343772/article/details/94352893

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容