flume 数据存入mysql(二)对敏感信息加密

来源:互联网 发布:电脑视频剪辑合成软件 编辑:程序博客网 时间:2024/05/22 03:09

前面写了flume 将数据存入mysql,但是有个问题,就是配置文件中暴露了我的mysql 的地址和帐号密码。这个是很危险的事情。所以这里就对mysql 的配置信息进行简单加密处理。

加密我才用 base64 进行了加密处理,因为我怕麻烦所以就随便搞搞就好了。

正常内容加密的话,用aes+base64,解密用md5验证内容完整性,就可以。需要的小伙伴可以试一下。

阅读本文请参照

flume 读取数据存入mysql(一)


本文目录:

  • 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 = source1agent1.sinks = mysqlSinkagent1.channels = channel1# Describe/configure source1agent1.sources.source1.type = execagent1.sources.source1.command = tail -F /opt/apps/logs/tail.logagent1.sources.source1.channels = channel1# Describe mysqlSinkagent1.sinks.mysqlSink.type =com.us.flume.MysqlSinkagent1.sinks.mysqlSink.hostname=localhostagent1.sinks.mysqlSink.port=3306agent1.sinks.mysqlSink.databaseName=sinktestagent1.sinks.mysqlSink.tableName=mysqltestagent1.sinks.mysqlSink.user=rootagent1.sinks.mysqlSink.password=YWRtaW4sVW5pc3RhY2tzagent1.sinks.mysqlSink.channel = channel1# Use a channel which buffers events in memoryagent1.channels.channel1.type = memoryagent1.channels.channel1.capacity = 1000agent1.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(","));
0 0
原创粉丝点击