Shipping with Rsyslog
Most Unix systems these days come with pre-installed rsyslog, which is a great lightweight service to consolidate logs.
You can configure rsyslog to monitor a single log file or directory and ship them over to Layerlog over TLS. For directories, all the first level files are monitored.
Configuration
Before you begin, you’ll need:
- Sudo access
- Rsyslog version 5.8.0 and above
- Outgoing TCP traffic to destination port 5001 allowed
- A common linux distribution
Install the rsyslog-gnutls add-on
On your Debian or Ubuntu Linux machine, run:
sudo apt-get install rsyslog-gnutls
For distributions based on Red Hat, use rpm or yum in place of apt-get.
Download the Layerlog public certificate to your credentials server
For HTTPS shipping, download the Layerlog public certificate to your certificate authority folder.
sudo curl https://raw.githubusercontent.com/logzio/public-certificates/master/AAACertificateServices.crt --create-dirs -o /etc/pki/tls/certs/COMODORSADomainValidationSecureServerCA.crt
Configure rsyslog file spooling
To ship a log to Layerlog, SSH to your Linux server, and run the command below. The code verifies the working directory exists. For an Ubuntu server, it will set the proper permissions.
sudo mkdir -v /var/spool/rsyslog
if [ "$(lsb_release -ds | grep Ubuntu)" != "" ]; then
sudo chown -R syslog:adm /var/spool/rsyslog
fi
Create a new configuration file for Layerlog
sudo vim /etc/rsyslog.d/21-logzio-sample.conf
Add the additional configuration:
# -------------------------------------------------------
# File Logging Directives for Layerlog
# -------------------------------------------------------
$ModLoad imfile
$InputFilePollInterval 10
$PrivDropToGroup adm
$WorkDirectory /var/spool/rsyslog
# File access file:
$InputFileName <<PATH_TO_FILE>>
$InputFileTag TYPE:
$InputFileStateFile stat-TYPE
$InputFileSeverity info
$InputFilePersistStateInterval 20000
$InputRunFileMonitor
$DefaultNetstreamDriverCAFile /etc/pki/tls/certs/COMODORSADomainValidationSecureServerCA.crt
$ActionSendStreamDriver gtls
$ActionSendStreamDriverMode 1
$ActionSendStreamDriverAuthMode x509/name
$ActionSendStreamDriverPermittedPeer *.layerlog.com
$template logzFormatFileTagName,"[<<LOG-SHIPPING-TOKEN>>] <%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [type=<<TYPE>>] %msg%\n"
if $programname == 'TYPE' then @@<<LISTENER-HOST>>:5001;logzFormatFileTagName
if $programname == 'TYPE' then ~
Replace the placeholders to match your specifics. (They are indicated by the double angle brackets << >>):
-
Replace
<<LOG-SHIPPING-TOKEN>>with the token of the account you want to ship to. - Replace
<<LISTENER-HOST>>with the host for your region. For example,listener.layerlog.comif your account is hosted on AWS US East, orlistener-nl.layerlog.comif hosted on Azure West Europe. <<PATH_TO_FILE>>: Path to your file or directory.<<TYPE>>: Declare your log type for parsing purposes. Layerlog applies default parsing pipelines to the following list of built-in log types. If you declare another type, contact support for assistance with custom parsing. Can’t contain spaces.
Restart rsyslog
sudo service rsyslog restart
Check Layerlog for your logs
Give your logs some time to get from your system to ours, and then open Kibana.
If you still don’t see your logs, see our rsyslog troubleshooting guide.