一、准备工作
(一)关闭防火墙
查看当前防火墙状态
systemctl status firewalld
关闭当前防火墙
systemctl stop firewalld
开机防火墙不启动。
systemctl disable firewalld
(二)拷贝所有文件
相关资源下载:
链接:https://pan.baidu.com/s/1VXGqQ2quBVHwlFoSsYErsg
提取码:m30v
创建目录、通过ftp工具将所有的文件上传至此目录
midir /usr/install
- apache-flume-1.6.0-bin.tar.gz:flume安装包
- flume-ng-sql-source-1.4.3.jar:flume用于连接数据库的重要支撑jar包。
- jdk-8u192-linux-x64.tar.gz:jdk
- kafka_2.11-0.8.2.1.tgz:kafka+zookeeper
- ojdbc5.jar:把oracle驱动包,取自oracle安装目录下(参考路径:D:\app\product\11.2.0\dbhome_1\jdbc\lib)
二、JDK
1. 跳转到目录
cd /usr/install
2. 解压
tar -zxvf jdk-8u192-linux-x64.tar.gz
3. 修改配置文件
vi /etc/profile
配置文件 配置内容如下:
vi /etc/profile 在文件底部加上四条配置信息:
export JAVA_HOME=/usr/install/jdk1.8.0_192
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:%{JAVA_HOME}/lib:%{JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
4. 更新环境变量
source /etc/profile
5. 测试是否成功
java -version
成功的话会显示
特别说明:执行命令 一定要注意空格,否则会提示 “-bash: tar-zxvf: command not found”
三、kafka_2.11-0.8.2.1单机版安装
1. 跳转到目录
cd /usr/install
2. 解压
tar -zxvf kafka_2.11-0.8.2.1.tgz
3. 修改配置文件
cd kafka_2.11-0.8.2.1
cd config
vi server.properties
修改内容:
- 配置host.name
host.name=192.168.74.63
- 修改zookeeper配置,建议把localhost修改为具体的IP
zookeeper.connect=192.168.74.63:2181
- 建议调整超时时间
zookeeper.connection.timeout.ms=60000
对比图如下:
4. 启动zookeeper
/usr/install/kafka_2.11-0.8.2.1/bin/zookeeper-server-start.sh /usr/install/kafka_2.11-0.8.2.1/config/zookeeper.properties
5. 启动kafka
/usr/install/kafka_2.11-0.8.2.1/bin/kafka-server-start.sh /usr/install/kafka_2.11-0.8.2.1/config/server.properties
【问题】
如果出现问题kafka.common.KafkaException: Failed to acquire lock on file .lock in /tmp/kafka-logs. A Kafka instan
https://blog.csdn.net/raoping2017/article/details/71629226
解决方法
- 删除 /tmp/kafka-logs;
- netstat -lnp|grep 9092;并且 kill pid;
- 又将移除的 /tmp/kafka-logs 移回,
启动正常。
6. 测试
【producer端】
/usr/install/kafka_2.11-0.8.2.1/bin/kafka-console-producer.sh --broker-list 192.168.74.63:9092 --topic test
【consumer端】
/usr/install/kafka_2.11-0.8.2.1/bin/kafka-console-consumer.sh --zookeeper 192.168.74.63:2181 --topic test --from-beginning
在【producer端】输入: message
在【consumer端】显示: message
表示已安装启动成功
【producer端】
【consumer端】
#创建topic test2
/usr/install/kafka_2.11-0.8.2.1/bin/kafka-topics.sh --create --zookeeper 192.168.74.63:2181 --replication-factor 1 --partitions 1 --topic test2
#列出当前的所有topic
/usr/install/kafka_2.11-0.8.2.1/bin/kafka-topics.sh --list --zookeeper 192.168.74.63:2181
四、Flume1.6.0安装配置
参考资料:CentOS安装配置Flume1.6.0
1. 跳转到目录
cd /usr/install
2. 解压
tar -zxvf apache-flume-1.6.0-bin.tar.gz
3. 重命名
mv apache-flume-1.6.0-bin flume-1.6.0
4. 配置环境变量
vi ~/.bash_profile
修改内容:
#在这文件中添加两句环境变量
FLUME_HOME=/usr/local/src/flume-1.6.0
export PATH=$FLUME_HOME/bin:$PATH
#保存退出:wq!
5. 更新环境变量
source ~/.bash_profile
6. 配置文件conf/flume.env.sh
路径在 flume-1.6.0/conf 中,你会发现只有flume-env.sh.template这个文件,因此我们需要拷贝一份重命名:
cd flume-1.6.0/
cd conf/
cp flume-env.sh.template flume.env.sh
vi flume.env.sh
修改内容:
export JAVA_HOME=/usr/install/jdk1.8.0_192
7. 测试
cd /usr/install/flume-1.6.0/
./bin/flume-ng version
显示出这个消息就证明flume安装好了
8. 启动flume-ng agent:
./flume-ng agent -c /appcom/apache-flume-1.6.0-bin/conf/ -f /appcom/apache-flume-1.6.0-bin/conf/agent1.properties -Dflume.root.logger=DEBUG,console -n agent1
9. 启动一个flume-ng avro-client生产数据:
./flume-ng avro-client -c /appcom/apache-flume-1.6.0-bin/conf/ -H 192.168.74.63 -p 41414 -F /data/Shell.java -Dflume.root.logger=DEBUG,console
五、Flume连接oracle实时推送数据到kafka
参考资料:Flume连接oracle实时推送数据到kafka
1. 把相关jar饱放在lib目录下
cd /usr/install/
mv flume-ng-sql-source-1.4.3.jar /usr/install/flume-1.6.0/lib/
mv ojdbc5.jar /usr/install/flume-1.6.0/lib/
2. 新建flume-sql.conf
cd /usr/install/flume-1.6.0/conf/flume-sql.conf
touch flume-sql.conf
vi flume-sql.conf
flume-sql.conf输入以下内容:
分别配置数据库、kafka的服务器信息
agentOne.channels=channelOne
agentOne.sources=sourceOne
agentOne.sinks=sinkOne
###########sql source#################
# For each one of the sources, the type is defined
agentOne.sources.sourceOne.type=org.keedio.flume.source.SQLSource
agentOne.sources.sourceOne.hibernate.connection.url=jdbc:oracle:thin:@192.168.74.85:1521/orcl
# Hibernate Database connection properties
agentOne.sources.sourceOne.hibernate.connection.user=INDBADMIN
agentOne.sources.sourceOne.hibernate.connection.password=INDBADMIN
agentOne.sources.sourceOne.hibernate.connection.autocommit=true
agentOne.sources.sourceOne.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
agentOne.sources.sourceOne.hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
agentOne.sources.sourceOne.run.query.delay=10000
agentOne.sources.sourceOne.status.file.path=/tmp
agentOne.sources.sourceOne.status.file.name=sqlSource.status
# Custom query
agentOne.sources.sourceOne.start.from=0
agentOne.sources.sourceOne.custom.query=select sysdate from dual
agentOne.sources.sourceOne.batch.size=1000
agentOne.sources.sourceOne.max.rows=1000
agentOne.sources.sourceOne.hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
agentOne.sources.sourceOne.hibernate.c3p0.min_size=1
agentOne.sources.sourceOne.hibernate.c3p0.max_size=10
##############################
agentOne.channels.channelOne.type=memory
agentOne.channels.channelOne.capacity=10000
agentOne.channels.channelOne.transactionCapacity=10000
agentOne.channels.channelOne.byteCapacityBufferPercentage=20
agentOne.channels.channelOne.byteCapacity=800000
agentOne.sinks.sinkOne.type=org.apache.flume.sink.kafka.KafkaSink
agentOne.sinks.sinkOne.topic=test
agentOne.sinks.sinkOne.brokerList=192.168.74.63:9092
agentOne.sinks.sinkOne.requiredAcks=1
agentOne.sinks.sinkOne.batchSize=20
agentOne.sinks.sinkOne.channel=channelOne
agentOne.sinks.sinkOne.channel=channelOne
agentOne.sources.sourceOne.channels=channelOne
3. flume-ng启动flume-sql.conf和测试
cd /usr/install/flume-1.6.0/bin
./flume-ng agent --conf ../conf --conf-file ../conf/flume-sql.conf --name agentOne -Dflume.root.logger=INFO,console
运行成功日志如下:
输出日志