1. Download and unzip
$ sudo tar -zxvf apache-flume-1.8.0-bin.tar.gz -C /usr/local/
$ sudo mv apache-flume-1.8.0-bin flume
2. Add environment variables
$ sudo vim ~/.bashrc
export FLUME_HOME=/usr/local/flume
export FLUME_CONF_DIR=$FLUME_HOME/conf
export PATH=$PATH:$FLUME_HOME/bin
$ source ~/.bashrc
3. Modify the configuration file
cd /usr/local/flume/conf
cp flume-env.sh.template flume-env.sh
sudo vim flume-env.sh
Add Java environment variables
export JAVA_HOME=/usr/local/java-8-openjdk-amd64
4. Flume version
./flume/bin/flume-ng version
Error: Could not find or load main class org.apache.flume.tools.GetJavaProperty
If hbase is installed in the system, an error occurs: Could not find or load main class org.apache.flume.tools.GetJavaProperty. If hbase is not installed, this step can be skipped.
- #1. Comment out this line of hbase.env.sh configuration of hbase, that is, add a # before export
- #export HBASE_CLASSPATH=/home/hadoop/hbase/conf
- #2, or change HBASE_CLASSPATH to JAVA_CLASSPATH, the configuration is as follows
- export JAVA_CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
5. Test Flume
(1) Euro
1. Create the agent configuration file
sudo vim ./flume/conf/avro.conf
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 4141
#注意这个端口名,在后面的教程中会用得到
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2. Start flume agent a1 and start the log window
/usr/local/flume/bin/flume-ng agent -c . -f /usr/local/flume/conf/avro.conf -n a1 -Dflume.root.logger=INFO,console
3. Create the specified file
cd /usr/local/flume/conf/
sudo sh -c 'echo "hello world" > /usr/local/flume/log.00'
4. Open another window to print the log
./flume/bin/flume-ng avro-client --conf conf -H localhost -p 4141 -F /usr/local/flume/log.00
View log window
(2)telnet
1. Create the agent configuration file
sudo vim ./flume/conf/example.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
#同上,记住该端口名
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2. Start the agent log window
/usr/local/flume/bin/flume-ng agent -c . -f /usr/local/flume/conf/example.conf -n a1 -Dflume.root.logger=INFO,console
3. Open another window
telnet localhost 44444
Enter some characters (cannot enter Chinese)
4. Log window display