Simple Log Service lets you use Logstash for data consumption. To do this, configure the Logstash input Simple Log Service to pull data from Simple Log Service and send it to other systems, such as Kafka and HDFS.
Features
-
Distributed consumption: Configure multiple servers to consume data from a single Logstore simultaneously.
-
High performance: Based on the Java consumer group implementation, the plugin can process up to 20 MB/s of data on a single core (before compression).
-
High reliability: Consumption progress is saved on the server. If a consumer is interrupted, it automatically resumes from the last checkpoint.
-
Automatic load balancing: The system automatically allocates shards based on the number of consumers and rebalances the load when consumers are added or removed.
Procedure
Download the Logstash installation package for your operating system from Logstash.
The following example uses a Linux environment:
-
Install Logstash. For more information, see the official Logstash documentation.
-
Download and install the public signature key.
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch -
In the
/etc/yum.repos.d/directory, create a repository file with a.repoextension, such aslogstash.repo, and add the following content:[logstash-9.x] name=Elastic repository for 9.x packages baseurl=https://artifacts.elastic.co/packages/9.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md -
Download and install Logstash.
sudo yum install logstash
-
-
Install the input plugin.
-
Download the input plugin from logstash-input-sls.
-
Install the input plugin.
/usr/share/logstash/bin/logstash-plugin install logstash-input-sls.zipNoteFor information about potential installation failures and their solutions, see plugin installation and configuration.
-
-
Create the
logstashuser. Logstash must run as a non-root user.-
Create the
logstashuser.sudo adduser --system --no-create-home --group logstash -
Set permissions for the logstash user. Ensure that the
logstashuser owns the Logstash-related directories, such as/usr/share/logstash,/etc/logstash, and/var/log/logstash.sudo chown -R logstash:logstash /usr/share/logstash /etc/logstash /var/log/logstash -
Verify that the
logstashuser was created.id logstashThe output should display the User ID (UID) and Group ID (GID) for the
logstashuser, confirming that the user was successfully created.
-
-
Start Logstash as the
logstashuser.-
In the
/etc/logstashdirectory, create a configuration file with a .conf extension. This topic useslogstash-sample.confas an example. -
Add the sample code to the
logstash-sample.conffile and start Logstash as thelogstashuser.sudo -u logstash /usr/share/logstash/bin/logstash -f /etc/logstash/logstash-sample.confThe following example configures Logstash to consume data from a Logstore and print it to standard output. The parameters used in the example are described below.
Parameters
Sample code
input { logservice{ endpoint => "your project endpoint" access_id => "your_accesskey_id" access_key => "your_accesskey_secret" project => "your project name" logstore => "your logstore name" consumer_group => "consumer group name" consumer_name => "consumer name" position => "end" checkpoint_second => 30 include_meta => true consumer_name_with_ip => true } } output { stdout {} }endpoint
string(Required)The service endpoint of the SLS Project. For more information, see Service endpoints.
access_id
string(Required)The AccessKey ID of your Alibaba Cloud account. The AccessKey ID must have the required permissions to manage consumer groups. For more information, see Grant permissions to consume data from a Logstore.
access_key
string(Required)The AccessKey Secret of your Alibaba Cloud account. The AccessKey Secret must have the required permissions to manage consumer groups. For more information, see Grant permissions to consume data from a Logstore.
project
string(Required)The name of the SLS Project.
logstore
string(Required)The name of the SLS Logstore.
consumer_group
string(Required)The name of the consumer group.
consumer_name
string(Required)The name of the consumer. This name must be unique within the consumer group.
position
string(Required)The position where data consumption starts.
-
begin: Starts consumption from the first log entry in the Logstore.
-
end: Starts consumption from the current time.
-
yyyy-MM-dd HH:mm:ss: Starts consumption from the specified point in time.
checkpoint_second
number(Optional)The interval, in seconds, for saving a checkpoint. The value must be an integer from 10 to 60. Default: 30.
include_meta
boolean(Optional)Specifies whether to include metadata in the output. Metadata includes fields such as source, time, tag, and topic. Default: true.
consumer_name_with_ip
boolean(Optional)Specifies whether to append the consumer's IP address to the consumer name. This parameter must be set to
trueto enable distributed consumption. Default: true. -
-