前面写了flume 将数据存入mysql,但是有个问题,就是配置文件中暴露了我的mysql 的地址和帐号密码。这个是很危险的事情。所以这里就对mysql 的配置信息进行简单加密处理。
加密我才用 base64 进行了加密处理,因为我怕麻烦所以就随便搞搞就好了。
正常内容加密的话,用aes+base64,解密用md5验证内容完整性,就可以。需要的小伙伴可以试一下。
阅读本文请参照
本文目录:
- 1.加密测试类,生成密钥;
- 2.将密钥配置在flume的conf 中
- 3.修改mysql Sink的代码进行解密
加密测试类
public static void main (String [] args){
String pass="admin";
pass=Base64.getEncoder().encodeToString((pass+",Unistacks").getBytes());
String Dpass=new String(Base64.getDecoder().decode(pass));
Dpass=Dpass.substring(0,Dpass.indexOf(","));
System.out.println(pass+"---------"+Dpass);
}
2.将密钥配置在flume的conf 中
agent1.sources = source1
agent1.sinks = mysqlSink
agent1.channels = channel1
# Describe/configure source1
agent1.sources.source1.type = exec
agent1.sources.source1.command = tail -F /opt/apps/logs/tail.log
agent1.sources.source1.channels = channel1
# Describe mysqlSink
agent1.sinks.mysqlSink.type =com.us.flume.MysqlSink
agent1.sinks.mysqlSink.hostname=localhost
agent1.sinks.mysqlSink.port=3306
agent1.sinks.mysqlSink.databaseName=sinktest
agent1.sinks.mysqlSink.tableName=mysqltest
agent1.sinks.mysqlSink.user=root
agent1.sinks.mysqlSink.password=YWRtaW4sVW5pc3RhY2tz
agent1.sinks.mysqlSink.channel = channel1
# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.capacity = 1000
agent1.channels.channel1.transactionCapactiy = 100
3.修改mysql Sink的代码进行解密
修改MysqlSink.java 类的52行为下面内容
password=new String(Base64.getDecoder().decode(context.getString("password")));
password=password.substring(0,password.indexOf(","));