After installing LoongCollector, you can manage its lifecycle and runtime configuration.
Common LoongCollector commands
Start LoongCollector
If you have specific performance requirements for data collection, modify the startup parameter configuration file (ilogtail_config.json) before you start LoongCollector.
sudo /etc/init.d/loongcollectord startStop LoongCollector
sudo /etc/init.d/loongcollectord stopCheck the LoongCollector status
sudo /etc/init.d/loongcollectord status # A return value of "loongcollector is running" indicates a successful start.Check the LoongCollector version
cat /usr/local/ilogtail/app_info.json # The version information is stored in the loongcollector_version field.Restart LoongCollector
sudo /etc/init.d/loongcollectord restartUninstall LoongCollector
In the sample code, replace
${region_id}withcn-hangzhou. To accelerate the download, replace${region_id}with the region of your ECS instance. For more information, see Regions.wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh -O loongcollector.sh;Run the uninstall command.
chmod +x loongcollector.sh; sudo ./loongcollector.sh uninstall;
Upgrade LoongCollector
Upgrade LoongCollector to a later version or upgrade from Logtail to LoongCollector. The upgrade commands are the same for both scenarios.
Upgrade LoongCollector or upgrade from Logtail to LoongCollector
LoongCollector stops during the upgrade and automatically restarts after the upgrade is complete. The upgrade overwrites only essential files. Your configuration and checkpoint files are retained to prevent log loss.
Run the download command on your server to obtain the latest installation package. In the sample code, replace
${region_id}withcn-hangzhou. To accelerate the download, replace${region_id}with the region of your ECS instance. For more information, see Regions.wget https://aliyun-observability-release-${region_id}.oss-${region_id}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh -O loongcollector.sh;Run the upgrade command. Use the
upgradecommand. If you use theinstallcommand, the installation is overwritten and your original configuration is lost.chmod +x loongcollector.sh; sudo ./loongcollector.sh upgrade;If the following information is displayed, the upgrade is successful.
Upgrade loongcollector files successfully. Starting loongcollector ... Upgrade loongcollector successfully.
Roll back from LoongCollector to Logtail
You must download the logtail.sh script again. Do not use the old logtail.sh script.
Run the download command on your server to obtain the installation package. In the sample code, replace
${region_id}withcn-hangzhou. To accelerate the download, replace${region_id}with the region of your ECS instance. For more information, see Regions.wget https://logtail-release-${region_id}.oss-${region_id}.aliyuncs.com/linux64/logtail.sh -O logtail.sh;Run the rollback command. To specify a version, such as 1.8.7, refer to the comment and replace the version number as needed.
chmod +x logtail.sh; sudo ./logtail.sh upgrade; #chmod +x logtail.sh; sudo ./logtail.sh upgrade -v -v 1.8.7;
Startup parameter configuration file (ilogtail_config.json)
Description: This file configures the startup parameters for LoongCollector. Incorrect parameter settings can affect collection performance or cause collection errors.
Path: /usr/local/ilogtail/ilogtail_config.json.
Scenario: Simple Log Service (SLS) limits the collection performance of LoongCollector to avoid consuming excessive server resources. If the collection performance does not meet your needs, adjust the startup parameters.
File example:
{ "primary_region" : "cn-beijing", // Default region. You can ignore this parameter. "config_servers" : // The address used to obtain collection configurations. [ "http://logtail.cn-beijing.log.aliyuncs.com" ], "data_servers" : // The address for data transmission with SLS. [ { "region" : "cn-beijing", "endpoint_list": [ "cn-beijing.log.aliyuncs.com" ] } ], "cpu_usage_limit" : 0.4, "mem_usage_limit" : 384, "max_bytes_per_sec" : 20971520, "bytes_per_sec" : 1048576, "buffer_file_num" : 25, "buffer_file_size" : 20971520, "buffer_map_num" : 5 }Parameters: The following table lists only the common startup parameters that you might need to configure. Add or modify them as needed. Keep the default values for parameters not listed in the table.
Scenarios: The following examples show common scenarios and operations.
Collection performance configuration planning
To prevent the collector from consuming excessive server resources and affecting other services, SLS limits its collection performance. To improve collection performance, modify the startup parameters.
Recommended parameter examples
The following parameter configurations are recommended for collecting common JSON files. The performance of full regular expression mode and separator mode is similar to that of JSON mode. The performance of minimalist mode is five times higher than that of JSON mode. Factors such as data and rule complexity, and the number of collection directories and files, affect CPU and memory consumption. Adjust the parameters in the following table as needed.
Add or modify the parameter values in /usr/local/ilogtail/ilogtail_config.json and restart LoongCollector for the changes to take effect. The following table provides recommended values for different collection rates.
When you configure startup parameters based on the Collection rate greater than 40 MB/s column in the table, the collection performance is approaching its limit.
Parameter | Description | Collection rate greater than 10 MB/s | Collection rate greater than 20 MB/s | Collection rate greater than 40 MB/s |
cpu_usage_limit | The CPU usage threshold, calculated per core.
A value of 0.4 means SLS attempts to limit the collector's CPU usage to 40% of a single core. If the usage exceeds this limit, LoongCollector automatically restarts. This is a soft limit. The actual CPU usage may exceed this value. If the limit is exceeded for five minutes, a circuit breaker is triggered and LoongCollector automatically restarts. | 1 | 2 | 4 |
mem_usage_limit | The memory usage threshold.
The collection rate, the number of monitored directories and files, and sending blockages are related to this parameter. For more information, see Limits. This is a soft limit. The actual memory usage may exceed this value. If the limit is exceeded for five minutes, a circuit breaker is triggered and LoongCollector automatically restarts. | 1024 | 2048 | 4096 |
process_thread_count | The number of threads for data processing.
A single thread can handle 24 MB/s of data writes in minimalist mode or 12 MB/s in full regular expression mode. You do not need to adjust this parameter under normal circumstances. | 2 | 4 | 8 |
send_request_concurrency | The number of asynchronous concurrent requests.
If you have a high write TPS, set a higher concurrency value. Estimate that one concurrent request supports 0.5 MB/s to 1 MB/s of network throughput, depending on network latency. | 20 | 40 | 80 |
High network latency or unstable log transmission
You may experience log loss, duplicate log transmission, frequent retries by LoongCollector, or frequent network interruptions or fluctuations. Possible reasons include the following:
Insufficient network bandwidth: If the volume of collected logs is large, insufficient network bandwidth can cause log accumulation and increased latency.
Unstable network environment: Cross-region or cross-network connections can lead to network latency or packet loss.
Solution
Use Alibaba Cloud CDN edge nodes to accelerate log collection. This method offers significant advantages in network latency and stability compared to collection over the public network. This feature incurs additional charges based on the amount of data transferred.
Enable the cross-domain log transfer acceleration feature for your project.
Stop LoongCollector. Log on to the server where LoongCollector is installed and run the
sudo /etc/init.d/loongcollectord stopcommand.Modify the endpoint. In the
/usr/local/ilogtail/ilogtail_config.jsonfile, replace the value of theendpoint_listparameter under thedata_serversparameter withlog-global.aliyuncs.com. This changes the domain name used for data transmission to the acceleration endpoint.Start LoongCollector. Run the
sudo /etc/init.d/loongcollectord startcommand.
Large single log entries are truncated
If a single log entry is too large, it may be truncated after collection. This happens because the maximum size for a single log entry is 512 KB (524,288 bytes) by default. If a log entry exceeds this size, SLS truncates it. For multi-line logs that are split based on a regular expression for the first line, the size limit for each resulting log entry is also 512 KB. If this limit is exceeded, the entry is forcibly split into multiple entries.
Solution
In the
/usr/local/ilogtail/ilogtail_config.jsonfile, modify the value of themax_read_buffer_sizeparameter. If the parameter does not exist, add it. The maximum value for this parameter is 8 MB (8,388,608 bytes).Note that memory usage increases linearly. You must reserve
max_read_buffer_size × file concurrencyof memory.Restart LoongCollector. Run the
sudo /etc/init.d/loongcollectord restartcommand.
Logs older than 15 minutes are lost during transmission
Log collection may appear to be working, but some logs are lost. This occurs when the timestamp of a log differs from the current SLS server time by more than 15 minutes. For data security, SLS validates the timestamp of each request, including requests from LoongCollector, and rejects requests with a timestamp that differs from the server time by more than 15 minutes. If the server's local time is changed, for example, to a future time for testing, requests are rejected and data writes fail.
Solution
In the
/usr/local/ilogtail/ilogtail_config.jsonfile, change the value of theenable_log_time_auto_adjustparameter totrue. If the parameter does not exist, add it. This setting allows the log time to automatically adjust to the server's local time.When this feature is enabled, the offset between the SLS time and the server's local time is added to the log time. Because the offset is updated only when a request is rejected, the log time that you query in SLS might not match the actual write time.
Restart LoongCollector. Run the
sudo /etc/init.d/loongcollectord restartcommand.
Switch to a project in another region
For various reasons, you may need to store logs collected from a server in a new project.
Solution
To reuse the collection configuration, save the content of the collection configuration file before you proceed. The uninstallation process deletes this file.
Uninstall LoongCollector from the server.
Choose the appropriate LoongCollector installation method based on the relationship between the new project and the server.
If you also need to transfer historical data to the new project, two methods are available:
Download the logs to your local machine, and then use the Import Historical Log Files feature to transfer the logs to the new project.
Use data transformation to copy data from the old project to the new project.
Optimize long log transmission delays
This issue occurs when the log timestamp in SLS is more than three seconds later than the time the log was generated on the server. Possible reasons include the following:
More than 100 files are being collected simultaneously, or more than 5,000 files are in the monitored directory, consuming a large amount of memory.
High log data traffic (for example, over 2 MB/s in minimalist mode or over 1 MB/s in regular expression mode) causes high CPU usage.
Activate CloudLens for SLS and check the CPU usage of the current host under Collection Monitoring.
The rate at which LoongCollector sends data to SLS exceeds 10 MB/s.
Activate CloudLens for SLS and check the collection rate of the current host under Collection Monitoring.
Solution
Adjust the number of files or the data traffic based on the possible reasons listed above. If you cannot reduce memory usage or lower the transmission traffic, see Collection performance configuration planning to adjust the collection performance.
Other common configuration files
The following are other configuration and information files used by LoongCollector during runtime:
LoongCollector collection configuration file (user_log_config.json)
Description: This file records the collection configuration information that LoongCollector obtains from SLS. The file is updated whenever the collection configuration is updated. Do not modify this file, except to manually configure sensitive information such as AccessKey details or database passwords.
Path: /usr/local/ilogtail/user_log_config.json.
Scenario: Check this file to confirm whether a collection configuration has been delivered to the server. If this file exists and its content matches the collection configuration in SLS, the configuration has been successfully delivered.
AppInfo record file (app_info.json)
Description: The app_info.json file records information such as the LoongCollector startup time, the retrieved IP address, and the hostname. This file is for recording purposes only. Any modifications to it do not take effect.
Path: /usr/local/ilogtail/app_info.json.
Scenario: View the server IP information identified by SLS during collection to verify that it matches the IP information in the IP-based machine group in the SLS console. This is typically used to resolve heartbeat failures in IP-based machine groups.
If you have set a hostname-to-IP binding in the server's /etc/hosts file, the bound IP address is automatically retrieved. If no hostname binding is set, the IP address of the first network interface card is automatically retrieved. If the working_ip parameter in ilogtail_config.json is set, its value is used as the server's IP address.
LoongCollector runtime log (loongcollector.LOG)
Description: The loongcollector.LOG file records the runtime logs of LoongCollector. The log levels, from lowest to highest, are INFO, WARN, and ERROR.
Path: /usr/local/ilogtail/loongcollector.LOG.
Scenario: If a collection error occurs, first refer to Diagnose and monitor LoongCollector to check for errors. Then, troubleshoot the issue by referring to the log collection error types and the LoongCollector runtime log.
User ID file
Description: This file contains the Alibaba Cloud account ID of the project to which the collected logs belong. The filename is the account ID, with no suffix. It indicates that this account has permission to access and collect logs from this server.
Path: /etc/ilogtail/users/{Alibaba Cloud account ID}.
Scenario: You only need to configure a user ID when collecting logs from non-Alibaba Cloud ECS instances, self-managed servers, or servers from other cloud providers. If multiple accounts need to collect logs from the same server, create multiple user ID files on that server.
Custom identifier file
Description: This file is used to configure a custom identifier. This identifier is used as the content for a custom-identifier machine group, which helps SLS discover LoongCollector on the server and establish a heartbeat.
Path: /etc/ilogtail/user_defined_id.
Scenario: This configuration is required when using a custom-identifier machine group. For more information, see Associate a machine group with a LoongCollector collection configuration.
CheckPoint file
Description: The checkpoint mechanism records the current collection position to ensure log integrity.
Path: The default path is
/tmp/logtail_checkpoint.Scenario: Manage the checkpoint file by modifying the startup parameter file. For more information, see Limits.
FAQ
How to upgrade when the server cannot connect to the internet
On the server where you need to upgrade
LoongCollector, rununame -mto determine the system architecture. Then, on a server that can access the public network, run the corresponding command. Replace${region_id}with the region of your project.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 package to the server where you need to upgrade
LoongCollector, and then run the following command:chmod +x loongcollector.sh;./loongcollector.sh upgrade-local;