Use the Flume service to synchronize streaming data from an E-MapReduce (EMR) Dataflow cluster (Kafka) to the Hive service of an EMR data lake cluster.
Prerequisites
Before you begin, ensure that you have:
An EMR data lake cluster with Flume selected as an optional service. For more information, see Create a cluster
An EMR Dataflow cluster with Kafka selected as an optional service. For more information, see Create a cluster
Step 1: Create a Hive table
Log on to the data lake cluster in SSH mode. For more information, see Log on to a cluster.
transactional property set to true and use ORC format with bucketing.Run the following statement to create a table named flume_test:
create table flume_test (id int, content string)
clustered by (id) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true');Step 2: Configure Flume
Go to the Configure tab of the Flume service.
Log on to the EMR console. In the left-side navigation pane, click EMR on ECS.
In the top navigation bar, select the region where your cluster resides and select a resource group.
On the EMR on ECS page, find the data lake cluster and click Services in the Actions column.
On the Services tab, click Configure in the Flume service section.
On the Configure tab, click the flume-conf.properties subtab. By default, the global configuration applies to all nodes. To configure individual nodes, select Independent Node Configuration from the drop-down list.
Add the following configuration to the
flume-conf.propertiesvalue:Parameter Default Description default-agent.sources.source1.kafka.bootstrap.servers — Hostnames and port numbers of brokers in the Kafka cluster. Format: host1:port1,host2:port2,...default-agent.sinks.k1.hive.metastore — URI of the Hive metastore. Format: thrift://emr-header-1.cluster-xxx:9083. Runhostnameon the emr-header-1 node to get the hostname.default-agent.channels.c1.capacity100 Maximum number of events stored in the channel. Adjust based on your throughput requirements. default-agent.channels.c1.transactionCapacity100 Maximum number of events each transaction receives from the source or delivers to the sink. Adjust based on your throughput requirements. 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 # Describe the sink default-agent.sinks.k1.type = hive default-agent.sinks.k1.hive.metastore = thrift://xxxx:9083 default-agent.sinks.k1.hive.database = default default-agent.sinks.k1.hive.table = flume_test default-agent.sinks.k1.serializer = DELIMITED default-agent.sinks.k1.serializer.delimiter = "," default-agent.sinks.k1.serializer.serdeSeparator = ',' default-agent.sinks.k1.serializer.fieldnames =id,content default-agent.channels.c1.type = memory default-agent.channels.c1.capacity = 100 default-agent.channels.c1.transactionCapacity = 100 default-agent.sources.source1.channels = c1 default-agent.sinks.k1.channel = c1The following table describes the key parameters. Required parameters are in bold.
Save the configuration.
Click Save in the lower-left corner.
In the dialog box that appears, enter an execution reason and click Save.
Step 3: Start the Flume agent
On the Status tab of the Flume service, find the FlumeAgent component.
In the Actions column, choose More > Restart.
In the dialog box that appears, enter an execution reason and click OK.
In the Confirm message, click OK.
Step 4: Test data synchronization
Use Secure Shell (SSH) to log on to the Dataflow cluster. For more information, see Log on to a cluster.
Create a Kafka topic named
flume-test:kafka-topics.sh --partitions 10 --replication-factor 2 --zookeeper master-1-1:2181/emr-kafka --topic flume-test --createStart a Kafka producer and send test data:
kafka-console-producer.sh --topic flume-test --broker-list master-1-1:9092For example, type
abcand press Enter.Log on to the data lake cluster in SSH mode, and run the following Hive parameters to enable transaction support:
set hive.support.concurrency=true; set hive.exec.dynamic.partition.mode=nonstrict; set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;Query the
flume_testtable to verify that the data was written:select * from flume_test;The expected output is:
OK 1 a