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

前面写了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 = 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(","));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值