Todos os produtos
Search
Central de documentação

Object Storage Service:Use o JindoSDK com o Apache Flume para gravar dados no OSS-HDFS

Última atualização: Jul 03, 2026

O Apache Flume é um sistema distribuído, confiável e de alta disponibilidade. Ele permite coletar, agregar e mover grandes volumes de dados de log, armazenando-os de forma centralizada. Os dados são liberados para uma transação do Flume mediante a chamada flush() no Apache Flume e gravados no OSS-HDFS por meio do JindoSDK.

Pré-requisitos

Procedimento

  1. Conecte-se à instância ECS. Para mais informações, consulte Conectar-se a uma instância ECS.

  2. Configure o JindoSDK.

    1. Baixe a versão mais recente do pacote JAR do JindoSDK. Para baixar o JindoSDK, visite o GitHub.

    2. Descompacte o pacote de instalação baixado.

      O código de exemplo a seguir mostra como descompactar um pacote chamado jindosdk-x.x.x-linux.tar.gz. Caso utilize outra versão do JindoSDK, substitua o nome pelo arquivo JAR correspondente.

      tar -zxvf jindosdk-x.x.x-linux.tar.gz -C/usr/lib
    3. Defina JINDOSDK_HOME.

      export JINDOSDK_HOME=/usr/lib/jindosdk-x.x.x-linux
      export PATH=$JINDOSDK_HOME/bin:$PATH
    4. Defina HADOOP_CLASSPATH.

      export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${FLUME_HOME}/lib/*
      Importante

      Implante o diretório de instalação e as variáveis de ambiente no diretório lib da raiz do Flume em cada nó.

    5. Defina FLUME_CLASSPATH.

      cp ${FLUME_HOME}/conf/flume-env.sh.template ${FLUME_HOME}/conf/flume-env.sh
      echo "FLUME_CLASSPATH=/usr/lib/jindosdk-x.x.x-linux/lib/*" >>  ${FLUME_HOME}/conf/flume-env.sh
  3. Configure um sink.

    O exemplo abaixo ilustra a configuração de um sink:

    # Configure an OSS sink. Set your_bucket to the bucket for which OSS-HDFS is enabled. 
    xxx.sinks.oss_sink.hdfs.path = oss://${your_bucket}/flume_dir/%Y-%m-%d/%H
    
    # Specify the maximum number of events that can be written in a Flume transaction. We recommend that you flush more than 32 MB of data each time. This prevents impacts on the overall performance and prevents a large number of staging files from being generated. 
    # The batchSize parameter specifies the number of events, which is the number of log entries. Before you configure this parameter, you must evaluate the average size of events. For example, the average size is 200 bytes. If the size of data that is flushed each time is 32 MB, the value of the batchSize parameter is approximately 160,000 (32 MB/200 bytes). 
    xxx.sinks.oss_sink.hdfs.batchSize = 100000
    
    ...
    # Specify whether to partition Hadoop Distributed File System (HDFS) files by time. The timestamp is rounded down to an integer. Default value: true. 
    xxx.sinks.oss_sink.hdfs.round = true
    # When you set the xxx.sinks.oss_sink.hdfs.round parameter to true, you must configure the xxx.sinks.oss_sink.hdfs.roundUnit parameter. For example, if you set the xxx.sinks.oss_sink.hdfs.roundUnit parameter to minute and the xxx.sinks.oss_sink.hdfs.roundValue parameter to 60, data is written to a file within 60 minutes, which is equivalent to generating a file every 60 minutes. 
    xxx.sinks.oss_sink.hdfs.roundValue = 15
    # Specify the time unit that is used by the time partition. Default value: minute. Valid values: second, minute, and hour. 
    xxx.sinks.oss_sink.hdfs.roundUnit = minute
    # Specify the fixed prefix of new files generated by Apache Flume in the HDFS directory. 
    xxx.sinks.oss_sink.hdfs.filePrefix = your_topic
    # Specify the file size that triggers the system to create new files. Each time the file size is reached, the system creates a new file. Unit: bytes. A value of 0 specifies that the file is not split based on the file size. 
    xxx.sinks.oss_sink.rollSize = 3600
    # Specify the number of threads, such as open and write, that are enabled for each sink instance to perform HDFS IO operations. 
    xxx.sinks.oss_sink.threadsPoolSize = 30
    ...

    Para obter mais detalhes sobre os parâmetros necessários na configuração do sink, consulte Apache Flume.

Perguntas frequentes

O que fazer se a mensagem de erro "org.apache.flume.conf.ConfigurationException: Component has no type. Cannot configure.user_sink" for retornada?

Adicione as configurações abaixo ao arquivo core-site.xml do Hadoop para resolver o problema:

<!-- Configure the implementation classes of JindoOSS -->
fs.AbstractFileSystem.oss.impl com.aliyun.jindodata.oss.OSS 
fs.oss.impl com.aliyun.jindodata.oss.OssFileSystem
<!-- Configure the AccessKey pair and endpoint --> 
fs.oss.credentials.provider com.aliyun.jindodata.auth.SimpleAliyunCredentialsProvider 
fs.oss.accessKeyId LTAI******** 
fs.oss.accessKeySecret KZo1******** 
fs.oss.endpoint {regionId}.oss-dls.aliyuncs.com