Colete logs de instâncias ECS em uma conta do Alibaba Cloud (a conta de origem) e envie-os para um projeto do Simple Log Service (SLS) em outra conta (a conta de destino) autorizando o Logtail para acesso entre contas.
Quick start
Use cases
Common reasons for centralizing logs across accounts:
-
Unified monitoring: Centralize application and system logs from multiple accounts to simplify alerting and troubleshooting.
-
Security and compliance: Aggregate operation and security logs into a dedicated audit account for compliance.
-
Business migration: Move log collection to a new account during business migration.
The following example migrates log collection from a source account to a destination account.
How it works
This solution uses file-based authorization. You create authorization and identifier files on the source ECS instances, which grant the destination account permission to collect logs through Logtail.
Workflow:
-
On each source ECS instance (Account B), create an authorization file named after the destination account UID (Account A).
-
On the same instances, create a custom identifier file to group these servers in the destination account.
-
After Logtail recognizes the authorization file, it sends heartbeats to SLS in the destination account (Account A) and reports the custom identifier.
-
In the SLS console of the destination account (Account A), create a machine group using this custom identifier. Instances with normal heartbeats are automatically added to the group.
-
Apply a Logtail collection configuration to the machine group. Logtail collects logs based on the configuration and sends them to the logstore in the destination account (Account A).
For cross-account data transformation, use a custom role for authorization:
-
The first Role ARN grants the data transformation job permission to read data from the source logstore. To configure role permissions, see Grant read-only access to the source logstore.
-
The second Role ARN grants the data transformation job permission to write transformed data to the destination logstore. To configure role permissions, see Grant write permission to the destination logstore (cross-account).
Procedure
Step 1: Configure authorization and an identifier on the source ECS instance
Create an authorization file and an identifier file on each source ECS instance. This allows the destination account to collect logs and provides a unique identifier for the machine group.
-
Log on to the ECS instances in the source account.
-
Run the following script to complete the authorization and identifier configuration. Replace
{TARGET_ACCOUNT_ID}and{YOUR_MACHINE_GROUP_ID}in the script with your actual values.
#!/bin/bash
# Replace with the 16-digit Alibaba Cloud account ID of the destination account (Account A).
TARGET_ACCOUNT_ID="{TARGET_ACCOUNT_ID}"
# Define a unique identifier for this group of machines.
# Use a combination of the business and environment names, such as "my-app-prod-servers".
MACHINE_GROUP_ID="{YOUR_MACHINE_GROUP_ID}"
# 1. Create the authorization file directory.
sudo mkdir -p /etc/ilogtail/users
# 2. Create the authorization file. The file name is the destination account ID. This grants collection permissions to that account.
sudo touch "/etc/ilogtail/users/${TARGET_ACCOUNT_ID}"
# 3. Create the custom identifier file. This file is used to identify and group the machines in the destination account.
echo "${MACHINE_GROUP_ID}" | sudo tee /etc/ilogtail/user_defined_id > /dev/null
# 4. Restart the Logtail service to apply the configuration.
# If your system does not use systemd, run 'sudo /etc/init.d/ilogtaild restart'.
sudo systemctl restart ilogtail
echo "Configuration complete. Check the heartbeat status of the machine group in the SLS console of the destination account."
-
(Optional) Verify the configuration
-
Check whether the files are created:
sudo ls -l /etc/ilogtail/users/andsudo cat /etc/ilogtail/user_defined_id. -
Check the Logtail service status:
sudo systemctl status ilogtail. -
View the Logtail logs to confirm that heartbeats are sent:
sudo tail -n 100 /var/log/ilogtail/ilogtail.LOG | grep Heartbeat.
-
Step 2: Create a machine group in the destination account
In the SLS console of the destination account, create a machine group using the custom identifier from the previous step to manage the source ECS instances.
-
Log on to the SLS console by using the destination account (Account A).
-
On the Projects page, click the destination project.
-
In the navigation pane, choose Resources > Machine Groups.
-
Click Create Machine Group.
-
In the Create Machine Group dialog box, configure the following parameters:
-
Machine Group Name: Enter a custom name, such as
cross-account-app-servers. -
Machine Group Type: Select Custom Identifier.
-
Custom Identifier: Enter the value of
MACHINE_GROUP_IDthat you set in the script in Step 1. Make sure that the content is identical and does not contain extra spaces or line feeds.
-
-
Click OK.
-
In the Machine Group list, click the new machine group. Wait 1–3 minutes and refresh the page. The Heartbeat status should show OK.
Step 3: Create and apply a Logtail collection configuration
Create a Logtail collection configuration and apply it to the machine group to start collecting logs.
-
In the SLS console of the destination account, go to the destination project and logstore.
-
Choose Quick Integration > Import Data, and then select Regular Expression - Text Log or another log type as needed.
-
In the Select Machine Group step, move the machine group from the Source Machine Groups list to the Applied Machine Groups list, and then click Next.
-
Configure the Logtail collection rule, including the log path and collection pattern.
nullAfter confirming stable data collection in the destination account, immediately log on to the SLS console of the source account (Account B) and delete or disable the original Logtail collection configuration to avoid extra costs.
-
Complete the Preview Data and Set Index step and click Next. SLS enables full-text indexing by default. You can also configure field indexes as needed.
Background information
Logtail must be configured with the Alibaba Cloud account ID that owns the target SLS project. Without this identity, Logtail cannot connect to SLS, causing heartbeat failures and halting all log collection.
For example, an e-commerce company runs two applications on ECS clusters in the Alibaba Cloud China (Hangzhou) region, each under a different account. The company uses SLS in the same region to manage logs.
-
Application A is deployed on a Linux ECS cluster under Alibaba Cloud account A (UID: 12****456) and uses SLS from that account for log management.
-
Application B is deployed on a Linux ECS cluster under Alibaba Cloud account B (UID: 17****397) and uses SLS from that account for log management.
Due to business adjustments, the company plans to centralize logs from both applications into SLS under Alibaba Cloud account A (UID: 12****456). Each application's logs are collected into a separate logstore within the same project. You must create a new Logtail collection configuration, machine group, and logstore for Application B. Log collection for Application A remains unchanged.

Step 1: Create a user identity file
-
Log on to the ECS server that belongs to Alibaba Cloud account B.
nullYou must create the user identity file on each ECS server in ECS cluster B.
-
Run the following command to create the user identity file.
Set the user identity to Alibaba Cloud account A. This creates a file named after the account ID. Configure a user identity.
touch /etc/ilogtail/users/12****456
Step 2: Create a custom identifier-based machine group
-
Create a custom identifier file for the machine group on the ECS server.
nullYou must create the custom identifier file for the machine group on each ECS server in ECS cluster B.
-
Log on to the ECS server that belongs to Alibaba Cloud account B.
-
In the specified directory, create the /etc/ilogtail/user_defined_id file and add a custom identifier.
For example, to set the custom identifier to
application_b, enterapplication_bin the file and save it. For the file path, see Create a custom identifier-based machine group.
-
-
Create a machine group in the SLS console.
-
Log on to the SLS console with Alibaba Cloud account A.
-
In the Project List area, click the destination project.
-
In the left-side navigation pane, choose .
-
To the right of Machine Groups, click .
-
In the Create Machine Group dialog box, configure the parameters and click OK.
Set Custom Identifier to the custom identifier that you configured in step 1. For other parameters, see Create a machine group that uses a custom identifier.

-
-
Verify that the heartbeat status of the servers in the machine group is OK.
-
In the machine group list, click the destination machine group.
-
On the Machine Group Configurations page, view the ECS instances that use the same custom identifier and their heartbeat status.
Heartbeat status of OK indicates that the ECS instance is connected to SLS. If the status is FAIL, see A Logtail machine group has no heartbeat.

-
Step 3: Collect logs
-
Log on to the SLS console with Alibaba Cloud account A.
-
Click Quick Start.

-
In the Quick Data Import dialog box, select Regex - Text Log.
-
In the Import Data wizard, select the destination project and logstore, and then click Next.
-
Configure Machine Group Configurations.
-
Set Scenario to Servers.
-
Set Installation Environment to ECS.
-
Select the machine group that you created in Step 2. Move the machine group from Source Machine Group to Applied Machine Group, and then click Next.
-
-
Create a Logtail collection configuration and click Next.
For parameter details, see Collect logs in full regex mode.
null-
By default, only one Logtail collection configuration can match a file. Because the collection configuration for account B is still active, the new configuration for account A cannot take effect. You can use one of the following methods to activate the configuration for account A:
-
Stop the log collection for account B. To do this, log on to the SLS console with account B and remove the Logtail collection configuration from the destination machine group. Apply a Logtail configuration to a specified machine group.
-
Add a forced collection configuration for account A. How to collect logs from a file multiple times.
-
-
After you create the Logtail collection configuration, delete the original configuration for Alibaba Cloud account B to prevent duplicate log collection. Delete a Logtail configuration.

-
-
Preview the data, configure indexes, and then click Next.
SLS enables full-text indexing by default. You can also configure field indexes based on collected logs. Create indexes.
Related operations
To migrate historical data from the logstore in Alibaba Cloud account B to the current logstore, create a data transformation job in the source logstore. Replicate data from a logstore.
For cross-account data transformation, use a custom role for authorization.
-
The first Role ARN grants the data transformation job permission to read data from the source logstore. To configure role permissions, see Grant read-only access to the source logstore.
-
The second Role ARN grants the data transformation job permission to write transformed data to the destination logstore. To configure role permissions, see Grant write permission to the destination logstore (cross-account).
> Create Machine Group