Apache Flume est un système distribué, fiable et hautement disponible. Il permet de collecter, d'agréger et de déplacer de grandes quantités de journaux, puis de les stocker de manière centralisée. Les données sont vidées vers une transaction Flume via un appel à la méthode flush() dans Apache Flume, puis écrites dans OSS-HDFS à l'aide de JindoSDK.
Prérequis
Si vous utilisez Elastic Compute Service (ECS) comme environnement de déploiement, créez une instance.
Un environnement Hadoop doit être configuré. Pour plus d'informations sur l'installation de Hadoop, consultez la section Étape 2 : Créer un environnement d'exécution Hadoop.
Apache Flume doit être déployé. Pour plus d'informations, visitez le site Apache Flume.
Le service OSS-HDFS doit être activé pour un bucket et les autorisations d'accès appropriées doivent être accordées. Pour plus d'informations, consultez la rubrique Activer le service OSS-HDFS.
Procédure
Connectez-vous à l'instance ECS. Pour plus d'informations, consultez la section Se connecter à une instance ECS.
-
Configurez JindoSDK.
Téléchargez la dernière version du package JAR JindoSDK. Pour télécharger JindoSDK, rendez-vous sur GitHub.
-
Décompressez le package d'installation téléchargé.
L'exemple de code suivant illustre la décompression d'un package nommé
jindosdk-x.x.x-linux.tar.gz. Si vous utilisez une autre version de JindoSDK, remplacez le nom du package par celui du fichier JAR correspondant.tar -zxvf jindosdk-x.x.x-linux.tar.gz -C/usr/lib -
Configurez la variable
JINDOSDK_HOME.export JINDOSDK_HOME=/usr/lib/jindosdk-x.x.x-linux export PATH=$JINDOSDK_HOME/bin:$PATH -
Configurez la variable
HADOOP_CLASSPATH.export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${FLUME_HOME}/lib/*ImportantDéployez le répertoire d'installation et les variables d'environnement dans le répertoire lib du dossier racine de Flume sur chaque nœud.
-
Configurez la variable
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
-
Configurez un sink.
L'exemple de code suivant montre comment configurer un 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 ...Pour plus d'informations sur les paramètres requis pour configurer un sink, consultez la documentation Apache Flume.
FAQ
Que faire si le message d'erreur « org.apache.flume.conf.ConfigurationException: Component has no type. Cannot configure.user_sink » s'affiche ?
Ajoutez les configurations suivantes au fichier de configuration core-site.xml de Hadoop pour résoudre le problème :
<!-- 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