If you are using the legacy Logging agent and have a highly customized configuration, then we recommend migrating to open-source Fluentd. You can configure Fluentd to preserve the behavior of your Logging agent environment without disrupting the collection of your logs by Cloud Logging. This document describes the migration process.
Feature comparison
The following table provides a parity comparison of key functionalities between the legacy Logging agent and upstream Fluentd.
| Features | Legacy Logging agent | Upstream Fluentd |
|---|---|---|
| Log ingestion to Cloud Logging | Yes | Yes |
| Standard system logs (syslog) | Yes | Yes |
| Preconfigured third party application input | Yes | Yes † |
| Structured (JSON) and unstructured (text) log handling | Yes | Yes |
| Multiline exception merge | Yes | Yes |
| Google Cloud metadata enrichment | Yes | Yes |
| Kubernetes metadata enrichment | Yes | Yes |
| Unique log entry IDs | Yes | Yes |
| Log field transformation | Yes | Yes |
| Severity mapping | Yes | Yes |
| Authentication (ADC and Service Account Keys) | Yes | Yes |
| REST and gRPC transport protocols | Yes | Yes |
| Monitoring integration | Yes | Yes |
† Although the google-fluentd-catch-all- config package isn't included in the standard installation of upstream Fluentd and plugins, you can maintain the preconfigured input functionality by following the migration steps detailed in this guide.
Before you begin
Before starting the migration, make sure that you have the following:
- A supported VM instance in a Google Cloud project.
- Credentials on the VM instance that authorize communication with Cloud Logging. Compute Engine VM instances generally have the correct credentials by default. To check if you have the proper credentials, run the Authorize the Logging agent procedures.
Migrate to Fluentd
This section outlines the steps to migrate to the upstream Fluentd version, maintaining the key functionalities provided by the legacy Logging agent.
To migrate your setup, complete the following steps:
- Shut down the legacy Logging agent
- Install a stable version of fluentd-package
- Install Google Cloud Platform plugins
- Migrate your input plugins configuration files
- Update syslog configuration
- Update your Fluentd configuration file
- Validate that the Fluentd agent is running correctly
- Uninstall the legacy Logging agent
Shut down the legacy Logging agent
Before you install the upstream Fluentd agent, you must stop the legacy Logging agent to avoid conflicts. To avoid losing any pending logs during the migration, make sure you flush all buffered logs at shutdown.
To gracefully shut down the legacy Logging agent, do the following:
- Open a terminal connection to your VM instance using SSH or a similar tool and, make sure you have sudo access.
To flush any buffered logs before shutting down the legacy Logging agent, enable the
flush_at_shutdownoption:Update the
/etc/google-fluentd/google-fluentd.conffile to set theflush_at_shutdownflag totrue:# Configure the agent to flush all buffer chunks on shutdown <match **> @type google_cloud flush_at_shutdown true </match>Restart the agent to apply the configuration changes:
sudo service google-fluentd restart
Stop the legacy Logging agent:
sudo service google-fluentd stop
Install a stable version of fluentd-package
Install a stable distribution of Fluentd (fluentd-package) in your VM
instances. For instructions, see Fluentd Install
fluent-package
documentation.
Install Google Cloud Platform plugins
To enable Fluentd to interact with Cloud Logging and handle specific log formats, install the following plugins:
If not already installed, install the build tools for extension compilation:
Debian or Ubuntu
Run the following command on Debian or Ubuntu:
sudo apt-get update sudo apt-get install -y build-essentialCentOS or RHEL
Run the following command on CentOS or RHEL:
sudo yum update sudo yum groupinstall -y "Development Tools"Install the
fluent-plugin-google-cloudplugin:sudo fluent-gem install fluent-plugin-google-cloudInstall the
fluent-plugin-detect-exceptionsplugin:sudo fluent-gem install fluent-plugin-detect-exceptionsOptional: if your legacy Logging agent deployment collects logs from applications running within a Kubernetes cluster, then install the
fluent-plugin-kubernetes_metadata_filterplugin:sudo fluent-gem install fluent-plugin-kubernetes_metadata_filterOptional: If your legacy Logging agent collects and exposes metrics in Prometheus format, then install the following gems:
sudo fluent-gem install prometheus-client -v 0.9.0 sudo fluent-gem install fluent-plugin-prometheus -v 1.4.0
Migrate your input-plugin configuration files
To migrate your existing configuration and position files for your Fluentd installation, complete the following steps:
Create directories for the Fluentd configuration and position files:
# Create the destination directory for Fluentd configuration files sudo mkdir -p /etc/fluent/config.d # Create the destination directory for position files sudo mkdir -p /var/lib/fluent/posCopy your
google-fluentdconfiguration files to the configuration directory for Fluentd:sudo cp /etc/google-fluentd/config.d/* /etc/fluent/config.d/Copy all the position (
.pos) files used bygoogle-fluentdto the position-file directory for Fluentd:sudo cp /var/lib/google-fluentd/pos/*.pos /var/lib/fluent/pos/The position files are used to track reading positions in log files. Migrating them lets Fluentd start at the same point google-fluentd was using.
Update the
pos_filepath in your new Fluentd configuration files to point to the new position-file directory:sudo sed -i 's#/var/lib/google-fluentd#/var/lib/fluent#g' /etc/fluent/config.d/*.confGrant the Fluentd service user ,
_fluentd, read and write access to the/var/lib/fluent/directory:sudo chown -R _fluentd:_fluentd /var/lib/fluent/Grant the
_fluentduser read access to syslog files:sudo usermod -a -G adm _fluentd
Update syslog configuration
Upstream Fluentd runs as the unprivileged user, which can't bind to privileged
ports numbered less than 1024. If your legacy Logging agent setup includes network-based
syslog collection by using @type syslog on port 514, you must adjust the
configuration.
To update the port configuration, do the following:
Replace the entire content of the
/etc/fluent/config.d/syslog_endpoint.conffile with the following configuration:sudo tee /etc/fluent/config.d/syslog_endpoint.conf > /dev/null <<EOF <source> @type syslog port 5140 <transport tcp> </transport> bind 127.0.0.1 tag syslog </source> EOFCreate or modify the
/etc/rsyslog.d/40-fluentd-forward.conffile to forward syslog messages to the new Fluentd port:sudo tee /etc/rsyslog.d/40-fluentd-forward.conf > /dev/null <<EOF # Forward all syslog messages to Fluentd on localhost:5140 via TCP *.* @@127.0.0.1:5140 EOFRestart the
rsyslogservice to apply the changes:sudo systemctl restart rsyslog.service
Update the main Fluentd configuration file
Configure the upstream Fluentd agent by replicating your settings from the
agent's configuration file, google-fluentd.conf, to the main Fluentd
configuration file, located at /etc/fluent/fluentd.conf.
To configure upstream Fluentd agent, complete the following steps:
Copy the entire contents of the
google-fluentd.conffile to overwrite the default upstream Fluentd configuration file:sudo cp /etc/google-fluentd/google-fluentd.conf /etc/fluent/fluentd.confUpdate the
buffer_pathin your Fluentd configuration files to point to the new Fluentd directory:sudo sed -i 's#/var/log/google-fluentd#/var/log/fluent#g' /etc/fluent/fluentd.confInspect the
fluentd.conffile to confirm that the configuration includes the following:@include config.d/*.confis present to import all your input plugin configuration.- The
<match **> @type google_cloudblock is configured to stream logs to Cloud Logging. - The
buffer_pathwithin the output plugin now points to/var/lib/fluent/. - Any
pos_filedirective within input plugins point to/var/lib/fluent/.
Execute a dry run to verify your Fluentd configuration:
sudo fluentd -c /etc/fluent/fluentd.conf --dry-runCheck the resulting output for any
errororwarnalerts. You must resolve any identified issues prior to moving forward. For details on syntax changes, see Configuration compatibility for upstream Fluentd.Restart the Fluentd agent:
sudo service fluentd restart
Validate that the Fluentd agent is running correctly
After starting Fluentd, verify that logs are being successfully sent to Cloud Logging:
Verify that Fluentd is running without errors:
$ sudo service fluentd statusThe service status should be active (running).
Check Fluentd logs and ensure there are no errors or warnings:
sudo tail -n 100 /var/log/fluent/fluentd.log | grep -iE "error|warn|failed|exception" || trueNo errors or warnings should be listed.
Check Cloud Logging to confirm logs are being received from your VM instance. For information on viewing your logs, see Using the Logs Explorer.
Uninstall the legacy Logging agent
Only after you validate that the new Fluentd is successfully sending logs to Cloud Logging, remove the legacy Logging agent and its configuration files:
Debian or Ubuntu
sudo apt-get remove --purge google-fluentd
CentOS or RHEL
sudo yum remove google-fluentd