This topic explains how to use Flume to stream data from an E-MapReduce (EMR) Kafka cluster to the Alibaba Cloud OSS-HDFS service.
Prerequisites
-
The OSS-HDFS service is enabled, and you have the required access permissions. For more information, see Enable the OSS-HDFS service.
-
You have created a DataLake cluster and selected the Flume service. For more information, see Create a cluster.
-
You have created a DataFlow cluster and selected the Kafka service. For more information, see Create a cluster.
Procedure
-
Configure Flume.
-
Go to the Flume configuration page.
-
Log on to the E-MapReduce console.
-
In the top navigation bar, select a region and resource group.
-
On the EMR on ECS page, find the target cluster and click Services in the Actions column.
-
On the Services tab, click Configure in the FLUME service area.
-
-
Set the maximum Java Virtual Machine (JVM) heap size (Xmx).
Writing data from Flume to the OSS-HDFS service is memory-intensive. We recommend that you increase the Xmx value for the Flume agent.
-
Click the flume-env.sh tab.
This topic uses global configuration. To configure a specific node, select Independent Node Configuration from the drop-down list on the Configure page for the FLUME service.
-
Modify the value of the JAVA_OPTS parameter.
For example, to set the maximum JVM heap size to 1 GB, change the parameter value to
-Xmx1g. -
Click Save.
-
-
Modify the flume-conf.properties configuration.
-
Click the flume-conf.properties tab.
This topic uses global configuration. To configure a specific node, select Independent Node Configuration from the drop-down list on the Configure page for the FLUME service.
-
In the editor for flume-conf.properties, enter the following configuration.
NoteThe value of default-agent in the following example must match the value of the agent_name parameter on the Configure page for the FLUME service.
default-agent.sources = source1 default-agent.sinks = k1 default-agent.channels = c1 default-agent.sources.source1.type = org.apache.flume.source.kafka.KafkaSource default-agent.sources.source1.channels = c1 default-agent.sources.source1.kafka.bootstrap.servers = <kafka-host1:port1,kafka-host2:port2...> default-agent.sources.source1.kafka.topics = flume-test default-agent.sources.source1.kafka.consumer.group.id = flume-test-group default-agent.sinks.k1.type = hdfs default-agent.sinks.k1.hdfs.path = oss://{yourBucketName}.{yourBucketRegion}.oss-dls.aliyuncs.com/{path} default-agent.sinks.k1.hdfs.fileType=DataStream # Use a memory channel to buffer events default-agent.channels.c1.type = memory default-agent.channels.c1.capacity = 100 default-agent.channels.c1.transactionCapacity = 100 # Bind the source and sink to the channel default-agent.sources.source1.channels = c1 default-agent.sinks.k1.channel = c1Parameter
Description
default-agent.sources.source1.kafka.bootstrap.servers
The hostnames and port numbers of the brokers in your Kafka cluster.
default-agent.sinks.k1.hdfs.path
The path for OSS-HDFS must be in the format oss://{yourBucketName}.{yourBucketRegion}.oss-dls.aliyuncs.com/{path}. For example: oss://flume-test.cn-hangzhou.oss-dls.aliyuncs.com/result.
Path components:
-
{yourBucketName}: Enter the name of the Bucket for which the OSS-HDFS service is enabled.
-
{yourBucketRegion}: Enter the region ID of the Bucket.
-
{path}: Enter the directory name of the OSS-HDFS service.
default-agent.channels.c1.capacity
The maximum number of events that can be stored in the channel. Adjust this value based on your environment.
default-agent.channels.c1.transactionCapacity
The maximum number of events that a source can write to or a sink can retrieve from the channel per transaction. Adjust this value based on your environment.
-
-
Click Save.
-
-
-
Test the data synchronization.
- Connect to the EMR Dataflow cluster using SSH. For more information, see Log on to a cluster.
- Create a topic named flume-test.
kafka-topics.sh --partitions 10 --replication-factor 2 --zookeeper master-1-1:2181/emr-kafka --topic flume-test --create -
Produce test data.
kafka-console-producer.sh --topic flume-test --broker-list master-1-1:9092For example, enter
abcand press Enter.A file is generated in the oss://flume-test.cn-hangzhou.oss-dls.aliyuncs.com/result path. The file is named in the FlumeData.xxxx format, with the current timestamp in milliseconds as the suffix.