This topic describes the required steps.
Limits
-
The Syslog protocol must be the standard RFC 5424. If you use other Syslog protocols, we recommend that you see Collect Syslog from Linux systems.
-
The maximum size of a log entry is 64 KB.
-
To ensure data transmission security, you must transmit data over TCP using Transport Layer Security (TLS) 1.2.
Configuration
Most on-premises devices, such as VPNs and routers, do not support the TLS protocol or the RFC 5424 format. To collect data from these devices, we recommend that you use the Syslog plug-in for Logtail. For more information, see Collect Syslog from Linux systems.
To upload logs using the Syslog protocol, you must configure a log upload address in the ProjectName.Endpoint:SyslogPort format. Example: test-project-1.cn-hangzhou-intranet.log.aliyuncs.com:10009. Select an endpoint based on the region where your project is located. For more information, see Endpoints. The Syslog port is 10009. You must also configure parameters in the STRUCTURED-DATA field, such as the Simple Log Service project and LogStore, and your Alibaba Cloud account's AccessKey pair.
|
Parameter |
Description |
Example |
|
STRUCTURED-DATA |
The SD-ID is fixed to |
|
|
project |
The name of the Simple Log Service project. You must create a project in advance. For more information, see Manage Projects. |
test-project-1 |
|
logstore |
The name of the LogStore. You must create a LogStore in advance. For more information, see Create a LogStore. |
test-LogStore-1 |
|
access-key-id |
The AccessKey ID. We recommend that you use the AccessKey pair of a RAM user. For more information, see Authorization. |
LTAI**************** |
|
access-key-secret |
The AccessKey Secret. We recommend that you use the AccessKey pair of a RAM user. For more information, see Authorization. |
yourAccessKeySecret |
Example: Collect logs by using syslog-ng
syslog-ng is an open-source implementation of the Syslog protocol for UNIX and UNIX-like systems. You can run the sudo yum install syslog-ng or sudo apt-get install syslog-ng command to install syslog-ng.
Rsyslog is installed on Linux servers by default. Rsyslog and syslog-ng cannot run at the same time. If you want to use syslog-ng, you must uninstall Rsyslog first.
-
Open the syslog-ng configuration file.
The configuration file is typically located at /etc/syslog-ng/syslog-ng.conf.
-
Add the following configuration block to the end of the syslog-ng configuration file, and then configure the parameters within it based on your business requirements.
### Syslog-ng Logging Config for LogService ### template LogServiceFormat { template("<${PRI}>1 ${ISODATE} ${HOST:--} ${PROGRAM:--} ${PID:--} ${MSGID:--} [logservice project=\"test-project-1\" logstore=\"test-logstore-1\" access-key-id=\"<yourAccessKeyId>\" access-key-secret=\"<yourAccessKeySecret>\"] $MSG\n"); template_escape(no); }; destination d_logservice{ tcp("test-project-1.cn-hangzhou.log.aliyuncs.com" port(10009) tls(peer-verify(required-untrusted)) template(LogServiceFormat)); }; log { source(s_sys); # default use s_sys destination(d_logservice); }; ### END Syslog-ng Logging Config for LogService ### -
Restart syslog-ng.
Run the sudo /etc/init.d/syslog-ng restart, sudo service syslog-ng restart, or sudo systemctl restart syslog-ng command to restart syslog-ng.
-
Run the logger command to generate a test log.
Example: Run the logger hello world! command to generate a log.
Sample log
After you upload logs, you must configure indexes before you can view the logs in the Simple Log Service console. For more information, see Create an index.
For more information about the log fields, see RFC 5424.
To prevent AccessKey pair leaks, Simple Log Service deletes the logservice field by default.
03-28 11:01:01 __source__: xxx
__topic__: syslog-forwarder
_facility_: 3
_hostname_: xxx
_priority_: 30
_program_: systemd
_severity_: 6
_unixtimestamp_: 1553742061117098000
content: Started Session 59532 of user root.
03-28 11:00:15 __source__: mymachine.example.com
__topic__: syslog-forwarder
_facility_: 4
_hostname_: mymachine.example.com
_message_id_: ID47
_priority_: 34
_program_: su
_severity_: 2
_unixtimestamp_: 1553742015003000000
content: this is a test message
|
Field |
Description |
|
__source__ |
The value of the hostname field in the raw log. |
|
__topic__ |
The value is fixed to syslog-forwarder. |
|
__facility__ |
The facility information, which indicates the device or module that generates the log. |
|
__program__ |
The process name. |
|
__severity__ |
The severity of the log. |
|
__priority__ |
The priority of the log. |
|
__unixtimestamp__ |
The timestamp from the raw log, in nanoseconds. |
|
content |
The value of the msg field in the raw log. |
FAQ
-
Test log uploads
You can use Netcat to test log uploads to verify network connectivity and ensure that the AccessKey has upload permissions.
-
Log on to the server on which you want to test log uploads.
-
Run the following command to install Netcat:
sudo yum install nmap-ncat -
Run the following command to connect to Simple Log Service:
ncat --ssl <yourProject>.<yourEndpoint> 10009Sample command:
ncat --ssl test-project-1.cn-hangzhou.log.aliyuncs.com 10009 -
Netcat does not automatically detect network disconnections. Within 30 seconds of running the ncat command, enter the log message and press Enter.
<34>1 2019-03-28T03:00:15.003Z mymachine.example.com su - ID47 [logservice project="<yourProject>" logstore="<yourLogstore>" access-key-id="<yourAccessKeyID>" access-key-secret="<yourAccessKeySecret>"] this is a test messageSample command:
<34>1 2019-03-28T03:00:15.003Z mymachine.example.com su - ID47 [logservice project="trace-doc-test" logstore="doc-test-001-logs" access-key-id="<yourAccessKeyID>" access-key-secret="<yourAccessKeySecret>"] this is a test message -
Preview logs in the Simple Log Service console to check whether the logs are uploaded.
For more information, see Preview logs.
A log entry with a timestamp of
2019-03-28 11:00:15and a source ofmymachine.example.comappears in the preview results. The Syslog fields in the content column, including_hostname_,_severity_,_facility_,_message_id_,_unixtimestamp_,_program_, and_priority_, are parsed. This indicates that the log was uploaded and parsed successfully.
-
-
Check network connectivity
If the
ncatcommand in the previous step produces no output at all (thencatprocess exits immediately with no error message), first usetelnetto check whether port 10009 is reachable before assuming the network is the problem.-
Run the following command to check port connectivity:
telnet <yourProject>.<yourEndpoint> 10009Sample command:
telnet test-project-1.cn-hangzhou.log.aliyuncs.com 10009 -
If the output includes
Connected to..., the network is reachable. In this case, the issue is likely an incorrect AccessKey or Project configuration. Continue with thencattest in Test log uploads, or see Troubleshoot syslog upload failures in this section. -
If the connection times out or is refused, the network is not reachable. Check your security group, firewall, or network route configuration.
NoteSimple Log Service uses a shared access layer. Even if the Project name is incorrect,
telnetmight still returnConnected.telnetonly verifies network-layer connectivity. If the network is reachable but log upload still fails, check your AccessKey and Project name. -
-
Diagnose collection errors
If you collect Syslog data through the Logtail Syslog plug-in and a manual log upload fails, you can view specific error messages by diagnosing collection errors. For more information, see How to view Logtail collection error information. This diagnostic feature applies only to Logtail collection scenarios. When you upload logs directly by using the Syslog protocol as described in this topic, the data does not go through Logtail, so this diagnostic feature does not apply. See Troubleshoot syslog upload failures in this section instead.
-
Troubleshoot syslog upload failures
If logs sent by using the Syslog protocol are not received by the
LogStore, check the following items in order:-
Confirm that the SD-ID in STRUCTURED-DATA is fixed to
logservice. Any other identifier, such asslsorsls@17055, causes the connection to succeed but the log to be silently dropped. -
Confirm that the data is transmitted over TCP using TLS 1.2.
-
Confirm that the
AccessKeypair has write permissions on the targetLogStore. -
Run
ncat --ssl <ProjectName>.<Endpoint> 10009to verify that the port is reachable. -
Go to the
LogStorequery page in the Simple Log Service console and search for the log to confirm whether it arrived.
-