Install LoongCollector on a Linux server to collect and ship logs to Simple Log Service (SLS). Choose an installation method based on the relationship between your server and the SLS project.
Limitations
Prerequisites
Choose an installation method
Installation method | When to use |
The ECS instance and project belong to the same Alibaba Cloud account and are in the same region. | |
The ECS instance and project belong to the same Alibaba Cloud account but are in different regions. | |
The ECS instance and project are in the same region but belong to different Alibaba Cloud accounts. | |
|
Same account and region
When the ECS instance and project belong to the same Alibaba Cloud account and are in the same region, SLS can install LoongCollector automatically through OOS (Operation Orchestration Service). No manual login to the ECS instance is required.
This one-click installation is integrated into the SLS data collection templates. SLS provides templates for single-line, multi-line, and regex-based text logs. These templates differ only in their processing plugins. Select a template based on your log format, or choose any text log template and configure the processing plugins later.
Procedure
Log on to the Simple Log Service console. In the project list, click the target project.
Click
Log Storage. In the Logstores list, find the target Logstore and click the
icon next to it.Click the
icon next to Data Collection. In the dialog box that appears, select the Single Line - Text Logs template and click Integrate Now.Click Create Machine Group, select one or more ECS instances in the same region as the project, and then click Install and Create Machine Group.
Wait for the installation to complete, enter a name, and then click OK. If the installation fails, click Recreate Installation Task and reselect the ECS instances. Verify that the selected instances are in the same region as the project.
Click Next. If the Automatic Retry status is FAIL, click Automatic Retry and wait approximately two minutes until the status changes to OK.
The one-click installation is complete. Click Next to proceed to the collection configuration.
Same account, different region
When the ECS instance belongs to the same Alibaba Cloud account as the project but is in a different region, download the installation package manually and use either the internet or transfer acceleration method for data transmission.
Procedure
Download the installation package. Run the following command on your server. Replace
${region_id}withcn-hangzhou, or for faster downloads, replace it with the Region ID of the region where your ECS instance is located.wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh -O loongcollector.sh;Select a transmission method and run the installation command. Replace
${region_id}with the Region ID of the region where your project is located.Internet: Suitable for most scenarios such as cross-region deployments. Performance is subject to bandwidth limitations and network instability.
chmod +x loongcollector.sh; ./loongcollector.sh install ${region_id}-internetTransfer acceleration: Uses CDN to accelerate cross-region data transmission (for example, from the Chinese mainland to regions outside the Chinese mainland). This method reduces latency but incurs additional data transfer fees.
Enable the cross-region transfer acceleration feature for your project before running this command. Enable the cross-region transfer acceleration.
chmod +x loongcollector.sh; ./loongcollector.sh install ${region_id}-acceleration
Verify the agent status. Run the following command. A response of
loongcollector is runningindicates a successful start.sudo /etc/init.d/loongcollectord statusCreate a machine group. SLS uses machine groups to discover servers through custom identifiers and establish heartbeat connections with the LoongCollector agent.
On the server, write a custom identifier string to the identifier file. This string is referenced in a later step.
# Create the directory if it does not exist. The file path is fixed by SLS and cannot be changed. echo "user-defined-test-1" > /etc/ilogtail/user_defined_idLog on to the Simple Log Service console. In the project list, click the destination project.
In the left-side navigation pane, click
Resources, and then click Machine Groups.To the right of Machine Groups, click the
icon, and then click Create Machine Group.
Configure the following parameters and click OK.
Machine Group Name: A name that is unique within the project, 3 to 128 characters, starts and ends with a lowercase letter or digit, and contains only lowercase letters, digits, hyphens (-), and underscores (_).
Machine Group Identifier: Select Custom Identifier.
Custom Identifier: Enter the identifier that matches the string in the identifier file on the server. In this example, enter
user-defined-test-1.
Verify the heartbeat status. After the machine group is created, find it in the list and check the Heartbeat status. If the status is FAIL, wait approximately two minutes and refresh the page. An OK status indicates a successful connection.
Configure log collection. After installation, create a collection configuration to start collecting logs.
Different account, same region
When the ECS instance is in the same region as the project but belongs to a different Alibaba Cloud account, download the installation package manually, use the internal network for data transmission, and configure a user ID.
Procedure
Download the installation package. Run the following command on your server. Replace
${region_id}withcn-hangzhou, or for faster downloads, replace it with the Region ID of the region where your ECS instance is located.wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh -O loongcollector.sh;Run the installation command. Replace
${region_id}with the Region ID of the region where your project is located.A connection timeout usually indicates an incorrect
${region_id}. The internal network cannot connect across different regions. Correct the Region ID and rerun the command.chmod +x loongcollector.sh; ./loongcollector.sh install ${region_id}Verify the agent status. Run the following command. A response of
loongcollector is runningindicates a successful start.sudo /etc/init.d/loongcollectord statusConfigure a user ID. The user ID file contains the Alibaba Cloud account ID (root account) that owns the project. This ID authorizes the project to collect logs from this server.
Configure a user ID only when collecting logs from an ECS instance owned by a different account, an on-premises server, or a server from another cloud provider. To allow multiple accounts to collect logs from the same server, create separate user ID files for each account.
Log on to the Simple Log Service console. In the upper-right corner, hover over your profile picture to view and copy the root account ID.
On the server where LoongCollector is installed, create a user ID file using the root account ID as the filename:
touch /etc/ilogtail/users/{root_account_ID} # If the /etc/ilogtail/users directory does not exist, create it manually. The user ID file requires only a filename and has no file extension.
Configure a machine group. Simple Log Service uses machine groups to discover servers by using custom identifiers and establish heartbeat connections with the LoongCollector agent on each server.
On the server, write the custom string
user-defined-test-1to the custom identifier file. You will use this string in a later step.# Write a custom string to the specified file. If the directory does not exist, create it manually. The file path and name are fixed by Simple Log Service and cannot be changed. echo "user-defined-test-1" > /etc/ilogtail/user_defined_idLog on to the Simple Log Service console. In the project list, click the destination project.
In the left-side navigation pane, click
Resources, and then click Machine Groups.To the right of Machine Groups, click the
icon, and then click Create Machine Group.
Configure the following parameters and click OK.
Machine Group Name: Enter a name for the machine group. The name must be unique within the project, be 3 to 128 characters in length, start and end with a lowercase letter or a digit, and can contain only lowercase letters, digits, hyphens (-), and underscores (_).
Machine Group Identifier: Select Custom Identifier.
Custom Identifier: Enter the custom identifier that you configured. It must match the custom string in the custom identifier file on the server. In this example, the value is
user-defined-test-1.
After the machine group is created, find it in the list and check its Heartbeat status. If the status is FAIL, wait approximately two minutes and refresh the page. An OK status indicates a successful connection.
After the installation, you must also create a collection configuration to start collecting logs.
Other cloud or on-premises server
This method applies to on-premises servers or servers from other cloud providers. If your server is an ECS instance, but it belongs to a different Alibaba Cloud account and is in a different region than your project, treat it as an on-premises server. For these scenarios, you must manually download the installation package, use the internet or transfer acceleration method, and configure a user ID.
For server requirements, see Supported Linux operating system versions.
Procedure
Download the installation package. On your server, run the download command. In the sample code, you can replace
${region_id}withcn-hangzhou. To speed up the download, see Region ID and replace${region_id}with the ID of a region near your server.wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh -O loongcollector.sh;Select a transmission method and run the installation command. Replace
${region_id}with the Region ID of the region where your project is located.Internet: This method is suitable for most scenarios, such as cross-region deployments or collecting logs from other cloud or on-premises servers. However, performance is subject to bandwidth limitations and network instability.
chmod +x loongcollector.sh; ./loongcollector.sh install ${region_id}-internetTransfer acceleration: This method is used for cross-region data transmission, such as from a region in the Chinese mainland to a region outside the Chinese mainland. It uses a Content Delivery Network (CDN) to improve performance and avoid high latency and instability over the internet. This method incurs additional data transfer fees.
Before you run the installation command, you must enable the cross-region transfer acceleration feature for your project.
chmod +x loongcollector.sh; ./loongcollector.sh install ${region_id}-acceleration
Check the agent status. Run the following command. A response of
loongcollector is runningindicates that LoongCollector started successfully.sudo /etc/init.d/loongcollectord statusConfigure a user ID. The user ID file contains the root account ID of the Alibaba Cloud account that owns the project. This ID authorizes the project to access and collect logs from this server.
You need to configure a user ID only when you collect logs from an ECS instance that does not belong to your account, an on-premises server, or a server from another cloud provider. If multiple accounts need to collect logs from the same server, you can create multiple user ID files on that server.
Log on to the Simple Log Service console. In the upper-right corner, hover over your profile picture to view and copy the root account ID.
On the server where LoongCollector is installed, create a user ID file. Use the root account ID as the filename.
touch /etc/ilogtail/users/{root_account_ID} # If the /etc/ilogtail/users directory does not exist, create it manually. The user ID file requires only a filename and has no file extension.
Configure a machine group. Simple Log Service uses machine groups to discover servers by using custom identifiers and establish heartbeat connections with the LoongCollector agent on each server.
On the server, write the custom string
user-defined-test-1to the custom identifier file. You will use this string in a later step.# Write a custom string to the specified file. If the directory does not exist, create it manually. The file path and name are fixed by Simple Log Service and cannot be changed. echo "user-defined-test-1" > /etc/ilogtail/user_defined_idLog on to the Simple Log Service console. In the project list, click the destination project.
In the left-side navigation pane, click
Resources, and then click Machine Groups.To the right of Machine Groups, click the
icon, and then click Create Machine Group.
Configure the following parameters and click OK.
Machine Group Name: Enter a name for the machine group. The name must be unique within the project, be 3 to 128 characters in length, start and end with a lowercase letter or a digit, and can contain only lowercase letters, digits, hyphens (-), and underscores (_).
Machine Group Identifier: Select Custom Identifier.
Custom Identifier: Enter the custom identifier that you configured. It must match the custom string in the custom identifier file on the server. In this example, the value is
user-defined-test-1.
After the machine group is created, find it in the list and check its Heartbeat status. If the status is FAIL, wait approximately two minutes and refresh the page. An OK status indicates a successful connection.
After the installation, you must also create a collection configuration to start collecting logs.
Install LoongCollector in batches
In the same-account and same-region scenario, the automated installation feature allows you to select multiple ECS instances at once.
For all other scenarios, you can use ECS Cloud Assistant to run batch installation commands for LoongCollector on your ECS instances.
For the download and installation commands, refer to the installation scenarios described in this topic. To learn how to use ECS Cloud Assistant, see Create and run commands.
Upgrade and roll back versions
LoongCollector stops running during an upgrade and automatically restarts after the upgrade is complete. The upgrade process overwrites only the necessary program files. The upgrade process preserves your configuration and checkpoint files to prevent log data loss.
Upgrade to LoongCollector
On the server, run the download command to download the latest installation package. In the sample code, you can replace
${region_id}withcn-hangzhou. To speed up the download, see Region ID and replace${region_id}with the ID of the region where your ECS instance is located.wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh -O loongcollector.sh;Run the upgrade command. You must use the
upgradecommand. If you use theinstallcommand, it performs an overwrite installation and deletes your existing configuration.chmod +x loongcollector.sh; sudo ./loongcollector.sh upgrade;The following output indicates a successful upgrade:
Upgrade loongcollector files successfully. Starting loongcollector ... Upgrade loongcollector successfully.
Roll back from LoongCollector to Logtail
You must download a new logtail.sh script. Do not use an old version of the script.
On the server, run the download command to get the installation package. In the sample code, you can replace
${region_id}withcn-hangzhou. To speed up the download, see Region ID and replace${region_id}with the ID of the region where your ECS instance is located.wget https://logtail-release-${region_id}.oss-${region_id}.aliyuncs.com/linux64/logtail.sh -O logtail.sh;Run the rollback command. To roll back to a specific version, such as 1.8.7, use the commented-out command and replace the version number as needed.
chmod +x logtail.sh; sudo ./logtail.sh upgrade; #chmod +x logtail.sh; sudo ./logtail.sh upgrade -v 1.8.7;
Install a specific version
To install a specific version, use the -v parameter. Replace the version number in the following commands as needed.
LoongCollector
chmod +x loongcollector.sh; sudo ./loongcollector.sh install ${region_id} -v 3.2.6;Logtail
chmod +x logtail.sh; sudo ./logtail.sh install ${region_id} -v 1.8.7;
Uninstall LoongCollector
In the sample code, you can replace
${region_id}withcn-hangzhou. To speed up the process, see Region ID and replace${region_id}with the ID of the region where your ECS instance is located.wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh -O loongcollector.sh;Run the uninstallation command.
chmod +x loongcollector.sh; sudo ./loongcollector.sh uninstall;
FAQ
Offline installation
On the server where you want to install
LoongCollector, run theuname -mcommand to check the system architecture. Then, on a server with internet access, run the download command for your system architecture. Replace${region_id}with the Project's region ID.ARM architecture:
wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh;wget http://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/aarch64/main/loongcollector-linux64.tar.gz;x86-64 architecture:
wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh;wget http://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/x86_64/main/loongcollector-linux64.tar.gz;
Copy the downloaded installation script and installation package to the server where you want to install
LoongCollector, and then run the following command. Replace${region_id}with the Project's region ID.chmod +x loongcollector.sh; ./loongcollector.sh install-local ${region_id}-internetRun the following command to check the status. A response of
loongcollector is runningindicates that LoongCollector started successfully.sudo /etc/init.d/loongcollectord statusSince the server cannot access the internet, you also need to configure a proxy.
Offline upgrade
On the server where you want to upgrade
LoongCollector, run theuname -mcommand to check the system architecture. Then, on a server with internet access, run the download command for your system architecture. Replace${region_id}with the ID of the Project's region.ARM architecture:
wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh;wget http://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/aarch64/main/loongcollector-linux64.tar.gz;x86-64 architecture:
wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh;wget http://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/x86_64/main/loongcollector-linux64.tar.gz;
Copy the installation script and installation package to the server where you want to upgrade
LoongCollector, and then run the following command:chmod +x loongcollector.sh;./loongcollector.sh upgrade-local;
One-click installation failure
One-click installation requires that the ECS instance and Project are in the same Alibaba Cloud account and region. Otherwise, choose a different installation method. If this requirement is met, verify that you also meet the permission and network requirements in the Prerequisites section.
Resolving 'No heartbeat' or 'heartbeat FAIL' issues
If the heartbeat status is FAIL, it may take some time to establish the initial heartbeat. Wait for about two minutes and then refresh the heartbeat status. If the status is still FAIL, check the following:
Check the relationship between the server and the SLS Project. Different relationships require different installation procedures.
If you used the wrong procedure, run the
chmod +x loongcollector.sh; sudo ./loongcollector.sh uninstall;command to uninstall LoongCollector. Then, select the correct procedure and reinstall.
If you followed the correct procedure but the heartbeat status is still FAIL, check whether the
regionvalue in the/usr/local/ilogtail/ilogtail_config.jsonfile on the server matches the SLS Project's region ID.If they do not match, rerun the installation command with the correct region ID. This updates the file's content.
This method performs an overwrite installation and erases the original configuration. Use it with caution on servers with existing collection configurations.
If the information matches or the heartbeat status is still FAIL after reinstallation, proceed to the next step.
If the procedure requires a user ID file (for cross-account scenarios), check the following:
The user ID must be the Alibaba Cloud account ID. If not, correct it.
This must be the Alibaba Cloud account ID of the SLS Project owner, not the ECS instance owner.
Check whether the custom identifier for the machine group in the SLS console matches the one in the custom identifier file on the server. If they do not match, modify one of the values so that they match.
If the heartbeat status is still FAIL, check whether the network requirements in the Prerequisites section are met.
References
Region
Log on to the Simple Log Service console and click the target project in the Project list.
Click the
icon next to the project name to open the Project Overview page.In the Basic Information section, you can view the region name of the current project. The following table maps each region name to its corresponding Region ID.
A region represents the geographical location of the physical data center where cloud service resources are located. A Region ID is the unique identifier for a cloud service region.
Endpoints
An endpoint is the service access point for Simple Log Service (SLS). It is a URL used to access a project and its log data, and is determined by the region where the project is located. Simple Log Service provides private, public, and acceleration endpoints. To view the endpoints, follow these steps:
Log on to the Simple Log Service console and click the target project in the Project list.
Click the
icon next to the project name to open the Project Overview page.In the Endpoints section, you can view the endpoint information for the current project. Different network transmission methods use different endpoints. Choosing a suitable network transmission method helps ensure faster and more stable data transfer.
Network type | Endpoint type | Description | Scenarios |
Alibaba Cloud internal network | Private endpoint | The Alibaba Cloud internal network is a gigabit shared network. Transmitting log data over the Alibaba Cloud internal network is faster and more stable than over the internet. The internal network includes VPC and the classic network. | The ECS instance and SLS project are in the same region, or an on-premises server is connected to the internal network. Note Create an SLS project in the same region as your ECS instance. This allows log collection over the Alibaba Cloud internal network without consuming internet bandwidth. |
internet | Public endpoint | Transmitting log data over the internet is limited by network bandwidth and affected by factors such as jitter, latency, and packet loss. | You can transmit data over the internet in the following scenarios:
|
Transfer acceleration | Acceleration endpoint | This method uses Alibaba Cloud CDN edge nodes to accelerate log collection. It reduces latency and improves stability compared with log collection over the internet, but it incurs additional traffic fees. | If you transmit data between the Chinese mainland and other regions, using the internet may cause high network latency and instability. In this case, you can use transfer acceleration. For more information, see Transfer acceleration. |
