Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
rsyslogd
is a popular syslog daemon for Linux systems, providing a way to receive, process, and forward system logs. The configuration file for rsyslogd, usually located at /etc/rsyslog.conf
, controls the behavior of the daemon. In this tutorial, we'll cover the basics of the rsyslogd configuration file and how to set up log forwarding and filtering.
The /etc/rsyslog.conf
file consists of global directives, modules, and rules.
$IncludeConfig /etc/rsyslog.d/*.conf
.$ModLoad imuxsock
.A rule in the rsyslogd configuration file is made up of selectors and actions, separated by whitespace:
selector action
auth.info
, *.err
./var/log/auth.log
, @remote-host:514
.a) Forward all logs to a remote host:
To forward all log messages to a remote host (e.g., logserver.example.com
), add the following line to the /etc/rsyslog.conf
file:
*.* @logserver.example.com:514
Here, *.*
is the selector that matches all facilities and priorities, and @logserver.example.com:514
is the action that forwards logs to the specified remote host and port.
b) Save logs to different files based on facility:
To save logs from different facilities to separate log files, add the following lines to the /etc/rsyslog.conf
file:
auth.* /var/log/auth.log cron.* /var/log/cron.log
In this example, all logs from the auth
facility will be saved to /var/log/auth.log
, and logs from the cron
facility will be saved to /var/log/cron.log
.
c) Filter logs based on priority:
To save logs based on their priority, use a selector that matches the desired priority level:
*.err /var/log/errors.log
In this example, all log messages with a priority of err
or higher (more severe) will be saved to /var/log/errors.log
.
After making changes to the /etc/rsyslog.conf
file, restart the rsyslogd service for the changes to take effect:
sudo systemctl restart rsyslog
In this tutorial, we've covered the basics of the rsyslogd configuration file, including its structure, rules syntax, and examples.
How to configure rsyslogd
in Unix-like systems:
rsyslogd
is a system logger used to manage logs. Edit the configuration file, typically located at /etc/rsyslog.conf
or /etc/rsyslog.d/*.conf
. Example:
sudo nano /etc/rsyslog.conf
Common directives in the rsyslogd
configuration file:
Directives in the rsyslog.conf
file include options like input
, output
, and template
. Example:
input(type="imudp" port="514") output("/var/log/messages")
rsyslogd.conf
examples and usage in Linux:
Configure rsyslogd
to log messages to a specific file. Example in rsyslog.conf
:
*.info /var/log/messages
Configuring log forwarding with rsyslogd
in Linux:
Forward logs to a remote server using the @@
symbol followed by the remote server's IP or hostname. Example:
*.* @@remote-server:514
Filtering and routing logs in the rsyslogd
configuration:
Use filters to route logs based on criteria. Example:
if $programname == 'apache2' then /var/log/apache2.log
Advanced options and settings in rsyslog.conf
:
Advanced options include template customization, rate-limiting, and disk queue configuration. Example:
$ActionQueueMaxDiskSpace 1g
Troubleshooting rsyslogd
configuration issues in Linux:
Check the syslog configuration syntax using:
sudo rsyslogd -N1