Chat now with support
Chat with Support

syslog-ng Premium Edition 6.0.17 - Administration Guide

Preface Chapter 1. Introduction to syslog-ng Chapter 2. The concepts of syslog-ng Chapter 3. Installing syslog-ng Chapter 4. The syslog-ng PE quick-start guide Chapter 5. The syslog-ng PE configuration file Chapter 6. Collecting log messages — sources and source drivers Chapter 7. Sending and storing log messages — destinations and destination drivers Chapter 8. Routing messages: log paths, reliability, and filters Chapter 9. Global options of syslog-ng PE Chapter 10. TLS-encrypted message transfer Chapter 11. FIPS-compliant syslog-ng Chapter 12.  Reliable Log Transfer Protocol™ Chapter 13. Reliability and minimizing the loss of log messages Chapter 14. Manipulating messages Chapter 15. Parsing and segmenting structured messages Chapter 16. Processing message content with a pattern database Chapter 17. Statistics and metrics of syslog-ng Chapter 18. Multithreading and scaling in syslog-ng PE Chapter 19. Troubleshooting syslog-ng Chapter 20. Best practices and examples

Chapter 4. The syslog-ng PE quick-start guide

This chapter provides a very brief introduction into configuring the syslog-ng PE application. For details on the format of the configuration file and how to configure sources, destinations, and other features, refer to the subsequent chapters.

Procedure 4.1. Configuring syslog-ng on client hosts

Purpose: 

To configure syslog-ng on a client host, complete the following steps.

Steps: 

  1. Install the syslog-ng application on the host. For details installing syslog-ng on specific operating systems, see Chapter 3, Installing syslog-ng.

  2. Configure the local sources to collect the log messages of the host. Starting with version 3.2, syslog-ng PE automatically collects the log messages that use the native system logging method of the platform, for example, messages from /dev/log on Linux, or /dev/klog on FreeBSD. For a complete list of messages that are collected automatically, see the section called “Collecting the system-specific log messages of a platform”.

    Add sources to collect the messages from your log files. File sources look like this:

    source s_myfilesource {
            file("/var/log/myapplication.log" follow-freq(1)); };

    Name every source uniquely. For details on configuring file sources, see the section called “Collecting messages from text files”.

    TIP:

    Many applications send log messages to logfiles by default (for example, the Roundcube webmail client, or the ProFTPD FTP server), but can be configured to send them to syslog instead. If possible, it is recommended to reconfigure the application that way.

    NOTE:

    The default configuration file of syslog-ng PE collects platform-specific log messages and the internal log messages of syslog-ng PE.

    source s_local {
            system();
            internal();
    };
  3. Create a network destination that points directly to the syslog-ng server, or to a local relay. The network destination greatly depends on the protocol that your log server or relay accepts messages. Many systems still use the legacy BSD-syslog protocol (RFC3162) over the unreliable UDP transport:

    destination d_network { network("10.1.2.3" transport("udp")); };

    However, if possible, use the much more reliable IETF-syslog protocol over TCP transport:

    destination d_network { syslog("10.1.2.3" transport("tcp")); };
  4. Create a log statement connecting the local sources to the syslog-ng server or relay. For example:

    log {
            source(s_local); destination(d_network); };
  5. If the logs will also be stored locally on the host, create local file destinations.

    NOTE:

    The default configuration of syslog-ng PE places the collected messages into the /var/log/messages file:

    destination d_local {
        file("/var/log/messages"); };
  6. Create a log statement connecting the local sources to the file destination.

    NOTE:

    The default configuration of syslog-ng PE has only one log statement:

    log {
        source(s_local); destination(d_local); };
  7. Set filters, macros and other features and options (for example TLS encryption) as necessary.

    Example 4.1. The default configuration file of syslog-ng PE

    The following is a simple configuration file that collects local log messages to the /var/log/messages file.

    @version: 6.0
    @include "scl.conf"
    source s_local { system(); internal(); };
    destination d_local {
                file("/var/log/messages"); };
    log { source(s_local); destination(d_local); };

    Example 4.2. A simple configuration for clients

    The following configuration file collects local log messages and the log messages of syslog-ng PE, and forwards them to a log server using the IETF-syslog protocol.

    @version: 6.0
    @include "scl.conf"
    source s_local { system(); internal(); };
    destination d_syslog_tcp {
                 syslog("192.168.1.1" transport("tcp") port(2010)); };
    log { source(s_local);destination(d_syslog_tcp); };

    If you experience difficulties, see Chapter 19, Troubleshooting syslog-ng for tips on solving common problems.

Procedure 4.2. Configuring syslog-ng on server hosts

Purpose: 

To configure syslog-ng on a server host, complete the following steps.

Steps: 

  1. Install the syslog-ng application on the host. For details installing syslog-ng on specific operating systems, see Chapter 3, Installing syslog-ng.

  2. Starting with version 3.2, syslog-ng PE automatically collects the log messages that use the native system logging method of the platform, for example, messages from /dev/log on Linux, or /dev/klog on FreeBSD. For a complete list of messages that are collected automatically, see the section called “Collecting the system-specific log messages of a platform”.

  3. Configure the network sources that collect the log messages sent by the clients and relays. How the network sources should be configured depends also on the capabilities of your client hosts: many older networking devices support only the legacy BSD-syslog protocol (RFC3164) using UDP transport:

    source s_network { syslog(ip(10.1.2.3) transport("udp")); };

    However, if possible, use the much more reliable TCP transport:

    source s_network { syslog(ip(10.1.2.3) transport("tcp")); };

    For other options, see the section called “Collecting messages using the IETF syslog protocol (syslog() driver)” and the section called “Collecting messages from remote hosts using the BSD syslog protocol”.

    NOTE:

    Starting with syslog-ng PE version 3.2, the syslog() source driver can handle both BSD-syslog (RFC 3164) and IETF-syslog (RFC 5424-26) messages.

  4. Create local destinations that will store the log messages, for example file- or program destinations. The default configuration of syslog-ng PE places the collected messages into the /var/log/messages file:

    destination d_local {
        file("/var/log/messages"); };

    If you want to create separate logfiles for every client host, use the ${HOST} macro when specifying the filename, for example:

    destination d_local {
        file("/var/log/messages_${HOST}"); };

    For details on further macros and how to use them, see Chapter 14, Manipulating messages.

  5. Create a log statement connecting the sources to the local destinations.

    log {
            source(s_local); source(s_network); destination(d_local); };
  6. Set filters, options (for example TLS encryption) and other advanced features as necessary.

    NOTE:

    By default, the syslog-ng server will treat the relayed messages as if they were created by the relay host, not the host that originally sent them to the relay. In order to use the original hostname on the syslog-ng server, use the keep-hostname(yes) option both on the syslog-ng relay and the syslog-ng server. This option can be set individually for every source if needed.

    If you are relaying log messages and want to resolve IP addresses to hostnames, configure the first relay to do the name resolution.

    Example 4.3. A simple configuration for servers

    The following is a simple configuration file for syslog-ng Premium Edition that collects incoming log messages and stores them in a text file.

    @version: 6.0
    @include "scl.conf"
        options {
            time-reap(30);
            mark-freq(10);
            keep-hostname(yes);
            };
        source s_local { system(); internal(); };
        source s_network {
            syslog(transport(tcp));
            };
        destination d_logs {
            file(
                "/var/log/syslog-ng/logs.txt"
                owner("root")
                group("root")
                perm(0777)
                ); };
        log { source(s_local); source(s_network); destination(d_logs); };

    If you experience difficulties, see Chapter 19, Troubleshooting syslog-ng for tips on solving common problems.

Configuring syslog-ng relays

This section describes how to configure syslog-ng PE as a relay.

Procedure 4.3. Configuring syslog-ng on relay hosts

Purpose: 

To configure syslog-ng on a relay host, complete the following steps:

Steps: 

  1. Install the syslog-ng application on the host. For details installing syslog-ng on specific operating systems, see Chapter 3, Installing syslog-ng.

  2. Configure the network sources that collect the log messages sent by the clients.

  3. Create a network destination that points to the syslog-ng server.

  4. Create a log statement connecting the network sources to the syslog-ng server.

  5. Configure the local sources that collect the log messages of the relay host.

  6. Create a log statement connecting the local sources to the syslog-ng server.

  7. Enable the keep-hostname() and disable the chain-hostnames() options. (For details on how these options work, see the section called “chain-hostnames()”.)

    NOTE:

    It is recommended to use these options on your syslog-ng PE server as well.

  8. Set filters and options (for example TLS encryption) as necessary.

    NOTE:

    By default, the syslog-ng server will treat the relayed messages as if they were created by the relay host, not the host that originally sent them to the relay. In order to use the original hostname on the syslog-ng server, use the keep-hostname(yes) option both on the syslog-ng relay and the syslog-ng server. This option can be set individually for every source if needed.

    If you are relaying log messages and want to resolve IP addresses to hostnames, configure the first relay to do the name resolution.

    Example 4.4. A simple configuration for relays

    The following is a simple configuration file that collects local and incoming log messages and forwards them to a logserver using the IETF-syslog protocol.

    @version: 6.0
    @include "scl.conf"
        options {
            time-reap(30);
            mark-freq(10);
            keep-hostname(yes);
            chain-hostnames(no);
            };
        source s_local { system(); internal(); };
        source s_network {
            syslog(transport(tcp));
            };
    
        destination d_syslog_tcp {
            syslog("192.168.1.5" transport("tcp") port(2010));
        };
    
        log { source(s_local); source(s_network);
              destination(d_syslog_tcp);
            };

How relaying log messages works

Depending on your exact needs about relaying log messages, there are many scenarios and syslog-ng PE options that influence how the log message will look like on the log server. Some of the most common cases are summarized in the following example.

Consider the following example: client-host > syslog-ng-relay > syslog-ng-server, where the IP address of client-host is 192.168.1.2. The client-host device sends a syslog message to syslog-ng-relay. Depending on the settings of syslog-ng-relay, the following can happen.

  • By default, the keep-hostname() option is disabled, so syslog-ng-relay writes the IP address of the sender host (in this case, 192.168.1.2) to the HOST field of the syslog message, discarding any IP address or hostname that was originally in the message.

  • If the keep-hostname() option is enabled on syslog-ng-relay, but name resolution is disabled (the use-dns() option is set to no), syslog-ng-relay uses the HOST field of the message as-is, which is probably 192.168.1.2.

  • To resolve the 192.168.1.2 IP address to a hostname on syslog-ng-relay using a DNS server, use the keep-hostname(no) and use-dns(yes) options. If the DNS server is properly configured and reverse DNS lookup is available for the 192.168.1.2 address, syslog-ng PE will rewrite the HOST field of the log message to client-host.

    NOTE:

    It is also possible to resolve IP addresses locally, without relying on the DNS server. For details on local name resolution, see Procedure 20.1, “Resolving hostnames locally”.

  • The above points apply to the syslog-ng PE server (syslog-ng-server) as well, so if syslog-ng-relay is configured properly, use the keep-hostname(yes) option on syslog-ng-server to retain the proper HOST field. Setting keep-hostname(no) on syslog-ng-server would result in syslog-ng PE rewriting the HOST field to the address of the host that sent the message to syslog-ng-server, which is syslog-ng-relay in this case.

  • If you cannot or do not want to resolve the 192.168.1.2 IP address on syslog-ng-relay, but want to store your log messages on syslog-ng-server using the IP address of the original host (that is, client-host), you can enable the spoof-source() option on syslog-ng-relay. However, spoof-source() works only under the following conditions:

    • The syslog-ng PE binary has been compiled with the --enable-spoof-source option.

    • The log messages are sent using the highly unreliable UDP transport protocol. (Extremely unrecommended.)

Chapter 5. The syslog-ng PE configuration file

Location of the syslog-ng configuration file

The syslog-ng application is configured by editing the syslog-ng.conf file. Use any regular text editor application to modify the file.

  • On Linux and UNIX systems, the syslog-ng.conf and license.txt files are located in the /opt/syslog-ng/etc/ directory.

  • On Microsoft Windows, they are located in the C:\Program Files\syslog-ng\etc\ folder.

NOTE:

Earlier versions of syslog-ng PE stored the configuration and license files under different directories, depending on the platform, typically under /etc/syslog-ng/.

NOTE:

On Microsoft Windows platforms the syslog-ng Agent for Windows stores its configuration in the system registry or in an XML file, and can be configured from a graphical interface. However, syslog-ng PE uses a plain-text configuration file when running on Microsoft Windows. For details about the syslog-ng Agent for Windows, see Administration Guide for syslog-ng Agent for Windows.

The configuration syntax in detail

Every syslog-ng configuration file must begin with a line containing the version information of syslog-ng. For syslog-ng version 6 LTS, this line looks like:

@version: 6.0

Versioning the configuration file was introduced in syslog-ng 3.0. If the configuration file does not contain the version information, syslog-ng assumes that the file is for syslog-ng version 2.x. In this case it interprets the configuration and sends warnings about the parts of the configuration that should be updated. Version 3.0 and later will correctly operate with configuration files of version 2.x, but the default values of certain parameters have changed since 3.0.

Example 5.1. A simple configuration file

The following is a very simple configuration file for syslog-ng: it collects the internal messages of syslog-ng and the messages from /dev/log into the /var/log/messages_syslog-ng.log file.

@version: 6.0

source s_local { unix-dgram("/dev/log"); internal(); };

destination d_file { file("/var/log/messages_syslog-ng.log"); };

log { source(s_local); destination(d_file); };

As a syslog-ng user described on a mailing list:

The syslog-ng's config file format was written by programmers for programmers to be understood by programmers. That may not have been the stated intent, but it is how things turned out. The syntax is exactly that of C, all the way down to braces and statement terminators.

--Alan McKinnon
  • The main body of the configuration file consists of object definitions: sources, destinations, log paths define which log message are received and where they are sent. All identifiers, option names and attributes, and any other strings used in the syslog-ng configuration file are case sensitive. Objects must be defined before they are referenced in another statement. Object definitions (also called statements) have the following syntax:

    object_type object_id {<options>};
    • Type of the object: One of source, destination, log, filter, parser, rewrite rule, or template.

    • Identifier of the object: A unique name identifying the object. When using a reserved word as an identifier, enclose the identifier in quotation marks.

      TIP:

      Use identifiers that refer to the type of the object they identify. For example, prefix source objects with s_, destinations with d_, and so on.

    • Parameters: The parameters of the object, enclosed in braces {parameters}.

    • Semicolon: Object definitions end with a semicolon (;).

    For example, the following line defines a source and calls it s_internal.

    source s_internal { internal(); };

    The object can be later referenced in other statements using its ID, for example, the previous source is used as a parameter of the following log statement:

    log { source(s_internal); destination(d_file); };
  • The parameters and options within a statement are similar to function calls of the C programming language: the name of the option followed by a list of its parameters enclosed within brackets and terminated with a semicolon.

    option(parameter1, parameter2); option2(parameter1, parameter2);

    For example, the file() driver in the following source statement has three options: the filename (/var/log/apache/access.log), follow-freq(), and flags(). The follow-freq() option also has a parameter, while the flags() option has two parameters.

    source s_tail { file("/var/log/apache/access.log"
        follow-freq(1) flags(no-parse, validate-utf8)); };

    Objects may have required and optional parameters. Required parameters are positional, meaning that they must be specified in a defined order. Optional parameters can be specified in any order using the option(value) format. If a parameter (optional or required) is not specified, its default value is used. The parameters and their default values are listed in the reference section of the particular object.

    Example 5.2. Using required and optional parameters

    The unix-stream() source driver has a single required argument: the name of the socket to listen on. Optional parameters follow the socket name in any order, so the following source definitions have the same effect:

    source s_demo_stream1 {
            unix-stream("<path-to-socket>" max-connections(10) group(log)); };
    source s_demo_stream2 {
            unix-stream("<path-to-socket>" group(log) max-connections(10)); };

  • Some options are global options, or can be set globally, for example, whether syslog-ng PE should use DNS resolution to resolve IP addresses. Global options are detailed in Chapter 9, Global options of syslog-ng PE.

    options { use-dns(no); };
  • All identifiers, attributes, and any other strings used in the syslog-ng configuration file are case sensitive.

  • Objects can be used before definition.

  • To add comments to the configuration file, start a line with # and write your comments. These lines are ignored by syslog-ng.

    # Comment: This is a stream source
    source s_demo_stream {
            unix-stream("<path-to-socket>" max-connections(10) group(log)); };

TIP:

Before activating a new configuration, check that your configuration file is syntactically correct using the syslog-ng --syntax-only command.

To activate the configuration, reload the configuration of syslog-ng using the /etc/init.d/syslog-ng reload command.

Notes about the configuration syntax

When you are editing the syslog-ng configuration file, note the following points:

  • The configuration file can contain a maximum of 6665 source / destination / log elements.

  • When writing the names of options and parameters (or other reserved words), the hyphen (-) and underscore (_) characters are equivalent, for example max-connections(10) and max_connections(10) are both correct.

  • Numbers can be prefixed with + or - to indicate positive or negative values. Numbers beginning with zero (0) or 0x are treated as octal or hexadecimal numbers, respectively.

  • You can use commas (,) to separate options or other parameters for readability, syslog-ng completely ignores them. The following declarations are equivalent:

    source s_demo_stream {
            unix-stream("<path-to-socket>" max-connections(10) group(log)); };
    source s_demo_stream {
            unix-stream("<path-to-socket>", max-connections(10), group(log)); };
  • When enclosing object IDs (for example the name of a destination) between double-quotes ("mydestination"), the ID can include whitespace as well, for example:

    source "s demo stream" {
            unix-stream("<path-to-socket>" max-connections(10) group(log)); };

    NOTE:

    On Microsoft Windows platforms, enclose paths and filenames between single quotes, for example, 'C:\temp\logs\mylogs.log'

  • For notes on using regular expressions, see the section called “Regular expressions”.

Related Documents