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

Linux rsyslogd Configuration File (Format And Content)

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.

  • Structure of rsyslogd configuration file:

The /etc/rsyslog.conf file consists of global directives, modules, and rules.

  • Global directives: These control the overall behavior of rsyslogd. Example: $IncludeConfig /etc/rsyslog.d/*.conf.
  • Modules: These are loaded to provide additional functionality, such as input and output plugins. Example: $ModLoad imuxsock.
  • Rules: These define how rsyslogd processes log messages, including filtering and forwarding. Rules are made up of selectors and actions.
  • Basic rules syntax:

A rule in the rsyslogd configuration file is made up of selectors and actions, separated by whitespace:

selector action
  • Selector: Specifies which log messages to process, based on their facility and priority. Examples: auth.info, *.err.
  • Action: Determines what to do with the selected log messages. Examples: /var/log/auth.log, @remote-host:514.
  • Examples:

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.

  • Apply changes and restart rsyslogd:

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.

  1. 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
    
  2. 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")
    
  3. rsyslogd.conf examples and usage in Linux: Configure rsyslogd to log messages to a specific file. Example in rsyslog.conf:

    *.info /var/log/messages
    
  4. 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
    
  5. 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
    
  6. Advanced options and settings in rsyslog.conf: Advanced options include template customization, rate-limiting, and disk queue configuration. Example:

    $ActionQueueMaxDiskSpace 1g
    
  7. Troubleshooting rsyslogd configuration issues in Linux: Check the syslog configuration syntax using:

    sudo rsyslogd -N1