TLS allows you to specify an IP address for a host or adjust the LogCollector IP address obtaining policy. This makes it easier to identify or manage hosts within a host group. This topic describes how to set IP addresses for hosts or containers.
Background information
To identify and manage hosts or containers within a host group, TLS LogCollector needs to read the IP addresses of the hosts or containers. By default, LogCollector takes the first network interface IP address as the IP address of the host or container and then reports it to the server. You can also specify an IP address for the host or adjust the LogCollector IP address obtaining policy as needed.
If both the IP address obtaining policy and a specific IP address are set, the specified IP address takes precedence.
Set IP address obtaining policy
Hosts or containers within a host group are distinguished by their IP addresses. In host groups of host identification type, if IP address obtained by LogCollector changes frequently, it will cause inconvenience for administrators to distinguish and identify different hosts or containers. In this case, you can set an IP address obtaining policy for LogCollector. For example, you can set the policy to read the IP address from a specified network interface or to obtain the IP address in a specific order.
Policy description
Host groups distinguish hosts and containers by their IP addresses. The IP address is automatically obtained and reported to the server by LogCollector installed in the host or container. By default, LogCollector takes the first network interface IP address as the host or container IP address. You can also adjust the obtaining policy as needed.
TLS LogCollector supports the following IP address obtaining policies:
- (Default) Use the IP address of the first network interface as the host or container IP address.
- Uses the IP address of the specified network interface as the host or container IP address. If the IP address is obtained successfully, this address is used as the host or container IP address; if fails, use the IP address of the first network interface as the host or container IP address.
- Obtains IP address in the sequence: hostname > eth0 > bond0. If the IP address is obtained successfully, this address is used as the host or container IP address; if fails, LogCollector moves to the next sequence. If all fails, the IP address of the first network card is used as the host or container IP address.
Configuration methods
Add the ip_policy parameter to the output.tls section of the configuration file to specify the policy that LogCollector obtains IP addresses. The configuration file path is as follows:
- Logcollector versions prior to v2.2.0: /usr/local/filebeat-7.12.0/etc/filebeat.yml
- Logcollector v2.2.0 and later: /usr/local/logcollector/etc/logcollector.yml
Tip
After modifying the settings, restart LogCollector to apply the configuration. For restart instructions, see 3. Process management. The ip_policy parameter supports the following configuration methods:
For example, to use the IP address of eth1 as the host IP address, configure as follows:
Specify IP address
When collecting host machine logs, if you use an IP address-based host group, you must configure the host's IP address for the host group. The IP address must be the one obtained by LogCollector; otherwise, a mismatch may cause LogCollector heartbeat failures for the corresponding host. If the automatically obtained IP address by LogCollector is not suitable, or multiple rules of the IP address obtaining policy do not meet your business needs, you can manually specify an IP address for the host based on the following instructions.
- Specify IP address when installing LogCollector:
- You can set the ip parameter during initialization to directly specify an IP address for the host. For details, see 2 Install and start LogCollector. When creating a host group, enter this IP address in the settings. The IP address will be used as the host's installation identifier displayed in the host group.
- Modify IP address after installing LogCollector:
- During LogCollector operation, to update authentication parameters such as secret_id and secret_key, or identification parameters like label, execute the following command to edit the LogCollector configuration file.