新增kafka sasl认证机制
This commit is contained in:
64
pom.xml
64
pom.xml
@@ -116,44 +116,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.flink</groupId>
|
<groupId>org.apache.flink</groupId>
|
||||||
<artifactId>flink-sql-connector-kafka_2.11</artifactId>
|
<artifactId>flink-connector-kafka_2.12</artifactId>
|
||||||
<version>${flink.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.flink</groupId>
|
|
||||||
<artifactId>flink-connector-kafka_2.11</artifactId>
|
|
||||||
<version>${flink.version}</version>
|
|
||||||
<!--<scope>provided</scope>-->
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.kafka</groupId>
|
|
||||||
<artifactId>kafka-clients</artifactId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--Flink modules-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.flink</groupId>
|
|
||||||
<artifactId>flink-table-api-java</artifactId>
|
|
||||||
<version>${flink.version}</version>
|
|
||||||
<!--<scope>provided</scope>-->
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.flink</groupId>
|
|
||||||
<artifactId>flink-table-planner-blink_2.11</artifactId>
|
|
||||||
<version>${flink.version}</version>
|
|
||||||
<!--<scope>provided</scope>-->
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.flink</groupId>
|
|
||||||
<artifactId>flink-table-planner_2.11</artifactId>
|
|
||||||
<version>${flink.version}</version>
|
<version>${flink.version}</version>
|
||||||
<!--<scope>provided</scope>-->
|
<!--<scope>provided</scope>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -161,7 +124,7 @@
|
|||||||
<!-- CLI dependencies -->
|
<!-- CLI dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.flink</groupId>
|
<groupId>org.apache.flink</groupId>
|
||||||
<artifactId>flink-clients_2.11</artifactId>
|
<artifactId>flink-clients_2.12</artifactId>
|
||||||
<version>${flink.version}</version>
|
<version>${flink.version}</version>
|
||||||
<!--<scope>provided</scope>-->
|
<!--<scope>provided</scope>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -181,6 +144,23 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase-client -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.hbase</groupId>
|
||||||
|
<artifactId>hbase-client</artifactId>
|
||||||
|
<version>2.2.3</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.zookeeper</groupId>
|
<groupId>org.apache.zookeeper</groupId>
|
||||||
<artifactId>zookeeper</artifactId>
|
<artifactId>zookeeper</artifactId>
|
||||||
@@ -203,12 +183,6 @@
|
|||||||
<version>4.5.6</version>
|
<version>4.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.flink</groupId>
|
|
||||||
<artifactId>flink-connector-hbase-2.2_2.11</artifactId>
|
|
||||||
<version>${flink.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
|
|||||||
@@ -61,4 +61,7 @@ public class CommonConfig {
|
|||||||
public static final int STATIC_THRESHOLD_SCHEDULE_MINUTES = CommonConfigurations.getIntProperty("static.threshold.schedule.minutes");
|
public static final int STATIC_THRESHOLD_SCHEDULE_MINUTES = CommonConfigurations.getIntProperty("static.threshold.schedule.minutes");
|
||||||
public static final int BASELINE_THRESHOLD_SCHEDULE_DAYS = CommonConfigurations.getIntProperty("baseline.threshold.schedule.days");
|
public static final int BASELINE_THRESHOLD_SCHEDULE_DAYS = CommonConfigurations.getIntProperty("baseline.threshold.schedule.days");
|
||||||
|
|
||||||
|
public static final String SASL_JAAS_CONFIG_USER = CommonConfigurations.getStringProperty("sasl.jaas.config.user");
|
||||||
|
public static final String SASL_JAAS_CONFIG_PASSWORD = CommonConfigurations.getStringProperty("sasl.jaas.config.password");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ public class DosSketchSource {
|
|||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty("bootstrap.servers", CommonConfig.KAFKA_INPUT_BOOTSTRAP_SERVERS);
|
properties.setProperty("bootstrap.servers", CommonConfig.KAFKA_INPUT_BOOTSTRAP_SERVERS);
|
||||||
properties.setProperty("group.id", CommonConfig.KAFKA_GROUP_ID);
|
properties.setProperty("group.id", CommonConfig.KAFKA_GROUP_ID);
|
||||||
|
properties.setProperty("security.protocol", "SASL_PLAINTEXT");
|
||||||
|
properties.setProperty("sasl.mechanism", "PLAIN");
|
||||||
|
properties.setProperty("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\""+CommonConfig.SASL_JAAS_CONFIG_USER+"\" password=\""+CommonConfig.SASL_JAAS_CONFIG_PASSWORD+"\";");
|
||||||
|
|
||||||
return streamExeEnv.addSource(new FlinkKafkaConsumer<String>(
|
return streamExeEnv.addSource(new FlinkKafkaConsumer<String>(
|
||||||
CommonConfig.KAFKA_INPUT_TOPIC_NAME,
|
CommonConfig.KAFKA_INPUT_TOPIC_NAME,
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package com.zdjizhi.utils;
|
|||||||
|
|
||||||
import com.zdjizhi.common.CommonConfig;
|
import com.zdjizhi.common.CommonConfig;
|
||||||
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
|
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
|
||||||
import org.apache.flink.table.api.EnvironmentSettings;
|
|
||||||
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,17 +10,8 @@ import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
|
|||||||
public class FlinkEnvironmentUtils {
|
public class FlinkEnvironmentUtils {
|
||||||
public static StreamExecutionEnvironment streamExeEnv = StreamExecutionEnvironment.getExecutionEnvironment();
|
public static StreamExecutionEnvironment streamExeEnv = StreamExecutionEnvironment.getExecutionEnvironment();
|
||||||
|
|
||||||
|
static {
|
||||||
public static StreamTableEnvironment getStreamTableEnv() {
|
|
||||||
streamExeEnv.setParallelism(CommonConfig.STREAM_EXECUTION_ENVIRONMENT_PARALLELISM);
|
streamExeEnv.setParallelism(CommonConfig.STREAM_EXECUTION_ENVIRONMENT_PARALLELISM);
|
||||||
|
|
||||||
EnvironmentSettings settings = EnvironmentSettings.newInstance()
|
|
||||||
.useBlinkPlanner()
|
|
||||||
.inStreamingMode()
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return StreamTableEnvironment.create(streamExeEnv, settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,14 @@ import java.util.Properties;
|
|||||||
public class KafkaUtils {
|
public class KafkaUtils {
|
||||||
|
|
||||||
private static Properties getKafkaSinkProperty(){
|
private static Properties getKafkaSinkProperty(){
|
||||||
Properties propertiesproducer = new Properties();
|
Properties properties = new Properties();
|
||||||
propertiesproducer.setProperty("bootstrap.servers", CommonConfig.KAFKA_OUTPUT_BOOTSTRAP_SERVERS);
|
properties.setProperty("bootstrap.servers", CommonConfig.KAFKA_OUTPUT_BOOTSTRAP_SERVERS);
|
||||||
|
properties.setProperty("security.protocol", "SASL_PLAINTEXT");
|
||||||
|
properties.setProperty("sasl.mechanism", "PLAIN");
|
||||||
|
properties.setProperty("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\""+CommonConfig.SASL_JAAS_CONFIG_USER+"\" password=\""+CommonConfig.SASL_JAAS_CONFIG_PASSWORD+"\";");
|
||||||
|
|
||||||
return propertiesproducer;
|
|
||||||
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FlinkKafkaProducer<String> getKafkaSink(String topic){
|
public static FlinkKafkaProducer<String> getKafkaSink(String topic){
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ stream.execution.job.name=DOS-DETECTION-APPLICATION
|
|||||||
kafka.input.parallelism=1
|
kafka.input.parallelism=1
|
||||||
|
|
||||||
#输入kafka topic名
|
#输入kafka topic名
|
||||||
kafka.input.topic.name=DOS-SKETCH-LOG
|
kafka.input.topic.name=DOS-SKETCH-RECORD
|
||||||
|
|
||||||
#输入kafka地址
|
#输入kafka地址
|
||||||
#kafka.input.bootstrap.servers=192.168.44.12:9092
|
kafka.input.bootstrap.servers=192.168.44.12:9092
|
||||||
kafka.input.bootstrap.servers=192.168.44.11:9092,192.168.44.14:9092,192.168.44.15:9092
|
#kafka.input.bootstrap.servers=192.168.44.11:9092,192.168.44.14:9092,192.168.44.15:9092
|
||||||
|
|
||||||
#读取kafka group id
|
#读取kafka group id
|
||||||
kafka.input.group.id=2108231709
|
kafka.input.group.id=2108231709
|
||||||
@@ -22,15 +22,15 @@ kafka.input.group.id=2108231709
|
|||||||
kafka.output.metric.parallelism=1
|
kafka.output.metric.parallelism=1
|
||||||
|
|
||||||
#发送kafka metrics topic名
|
#发送kafka metrics topic名
|
||||||
#kafka.output.metric.topic.name=TRAFFIC-TOP-DESTINATION-IP-METRICS-LOG
|
kafka.output.metric.topic.name=TRAFFIC-TOP-DESTINATION-IP-METRICS
|
||||||
kafka.output.metric.topic.name=test
|
#kafka.output.metric.topic.name=test
|
||||||
|
|
||||||
#发送kafka event并行度大小
|
#发送kafka event并行度大小
|
||||||
kafka.output.event.parallelism=1
|
kafka.output.event.parallelism=1
|
||||||
|
|
||||||
#发送kafka event topic名
|
#发送kafka event topic名
|
||||||
#kafka.output.event.topic.name=DOS-EVENT-LOG
|
kafka.output.event.topic.name=DOS-EVENT
|
||||||
kafka.output.event.topic.name=test
|
#kafka.output.event.topic.name=test
|
||||||
|
|
||||||
#kafka输出地址
|
#kafka输出地址
|
||||||
kafka.output.bootstrap.servers=192.168.44.12:9092
|
kafka.output.bootstrap.servers=192.168.44.12:9092
|
||||||
@@ -118,4 +118,8 @@ http.pool.response.timeout=60000
|
|||||||
static.threshold.schedule.minutes=10
|
static.threshold.schedule.minutes=10
|
||||||
|
|
||||||
#获取baseline周期,默认7天
|
#获取baseline周期,默认7天
|
||||||
baseline.threshold.schedule.days=7
|
baseline.threshold.schedule.days=7
|
||||||
|
|
||||||
|
#kafka用户认证配置参数
|
||||||
|
sasl.jaas.config.user=admin
|
||||||
|
sasl.jaas.config.password=galaxy2019
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.zdjizhi.common;
|
|
||||||
|
|
||||||
import org.apache.flink.table.functions.TableFunction;
|
|
||||||
import org.apache.flink.types.Row;
|
|
||||||
|
|
||||||
public class UdtfTest extends TableFunction<Row> {
|
|
||||||
|
|
||||||
public void eval(Row[] rows) {
|
|
||||||
for (Row row : rows) {
|
|
||||||
collect(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user