MinIO、Elasticsearch升级,Logstash添加内部TCP日志开关

pull/552/head
macro 2022-06-25 20:20:46 +08:00
parent d59951511a
commit dcb1b79f6a
11 changed files with 50 additions and 47 deletions

View File

@ -12,10 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -43,7 +40,7 @@ public class MinioController {
@ApiOperation("文件上传") @ApiOperation("文件上传")
@RequestMapping(value = "/upload", method = RequestMethod.POST) @RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public CommonResult upload(@RequestParam("file") MultipartFile file) { public CommonResult upload(@RequestPart("file") MultipartFile file) {
try { try {
//创建一个MinIO的Java客户端 //创建一个MinIO的Java客户端
MinioClient minioClient =MinioClient.builder() MinioClient minioClient =MinioClient.builder()

View File

@ -1,6 +1,6 @@
spring: spring:
datasource: datasource:
url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root username: root
password: root password: root
druid: druid:
@ -19,10 +19,17 @@ spring:
password: # Redis服务器连接密码默认为空 password: # Redis服务器连接密码默认为空
timeout: 300ms # 连接超时时间(毫秒) timeout: 300ms # 连接超时时间(毫秒)
minio:
endpoint: http://localhost:9000 #MinIO服务所在地址
bucketName: mall #存储桶名称
accessKey: minioadmin #访问的key
secretKey: minioadmin #访问的秘钥
logging: logging:
level: level:
root: info root: info
com.macro.mall: debug com.macro.mall: debug
logstash: logstash:
host: localhost host: localhost
enableInnerLog: false

View File

@ -1,6 +1,6 @@
spring: spring:
datasource: datasource:
url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
username: reader username: reader
password: 123456 password: 123456
druid: druid:
@ -19,6 +19,12 @@ spring:
password: # Redis服务器连接密码默认为空 password: # Redis服务器连接密码默认为空
timeout: 300ms # 连接超时时间(毫秒) timeout: 300ms # 连接超时时间(毫秒)
minio:
endpoint: http://192.168.3.101:9090 #MinIO服务所在地址
bucketName: mall #存储桶名称
accessKey: minioadmin #访问的key
secretKey: minioadmin #访问的秘钥
logging: logging:
file: file:
path: /var/logs path: /var/logs

View File

@ -11,6 +11,8 @@
<property name="LOG_FILE_PATH" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/logs}"/> <property name="LOG_FILE_PATH" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/logs}"/>
<!--LogStash访问host--> <!--LogStash访问host-->
<springProperty name="LOG_STASH_HOST" scope="context" source="logstash.host" defaultValue="localhost"/> <springProperty name="LOG_STASH_HOST" scope="context" source="logstash.host" defaultValue="localhost"/>
<!--是否开启LogStash插件内部日志-->
<springProperty name="ENABLE_INNER_LOG" scope="context" source="logstash.enableInnerLog" defaultValue="false"/>
<!--DEBUG日志输出到文件--> <!--DEBUG日志输出到文件-->
<appender name="FILE_DEBUG" <appender name="FILE_DEBUG"
@ -64,6 +66,7 @@
<level>DEBUG</level> <level>DEBUG</level>
</filter> </filter>
<destination>${LOG_STASH_HOST}:4560</destination> <destination>${LOG_STASH_HOST}:4560</destination>
<addDefaultStatusListener>${ENABLE_INNER_LOG}</addDefaultStatusListener>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers> <providers>
<timestamp> <timestamp>
@ -96,6 +99,7 @@
<onMismatch>DENY</onMismatch> <onMismatch>DENY</onMismatch>
</filter> </filter>
<destination>${LOG_STASH_HOST}:4561</destination> <destination>${LOG_STASH_HOST}:4561</destination>
<addDefaultStatusListener>${ENABLE_INNER_LOG}</addDefaultStatusListener>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers> <providers>
<timestamp> <timestamp>
@ -123,6 +127,7 @@
<!--业务日志输出到LogStash--> <!--业务日志输出到LogStash-->
<appender name="LOG_STASH_BUSINESS" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <appender name="LOG_STASH_BUSINESS" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${LOG_STASH_HOST}:4562</destination> <destination>${LOG_STASH_HOST}:4562</destination>
<addDefaultStatusListener>${ENABLE_INNER_LOG}</addDefaultStatusListener>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers> <providers>
<timestamp> <timestamp>
@ -150,6 +155,7 @@
<!--接口访问记录日志输出到LogStash--> <!--接口访问记录日志输出到LogStash-->
<appender name="LOG_STASH_RECORD" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <appender name="LOG_STASH_RECORD" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${LOG_STASH_HOST}:4563</destination> <destination>${LOG_STASH_HOST}:4563</destination>
<addDefaultStatusListener>${ENABLE_INNER_LOG}</addDefaultStatusListener>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers> <providers>
<timestamp> <timestamp>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>localhost:4560</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
<root level="INFO">
<appender-ref ref="LOGSTASH" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>

View File

@ -3,7 +3,7 @@ server:
spring: spring:
datasource: datasource:
url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root username: root
password: root password: root
druid: druid:
@ -40,4 +40,5 @@ logging:
logstash: logstash:
host: localhost host: localhost
enableInnerLog: false

View File

@ -3,7 +3,7 @@ server:
spring: spring:
datasource: datasource:
url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
username: reader username: reader
password: 123456 password: 123456
druid: druid:

View File

@ -6,6 +6,7 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType; import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -17,7 +18,8 @@ import java.util.List;
*/ */
@Data @Data
@EqualsAndHashCode @EqualsAndHashCode
@Document(indexName = "pms",shards = 1,replicas = 0) @Document(indexName = "pms")
@Setting(shards = 1,replicas = 0)
public class EsProduct implements Serializable { public class EsProduct implements Serializable {
private static final long serialVersionUID = -1L; private static final long serialVersionUID = -1L;
@Id @Id

View File

@ -1,5 +1,6 @@
package com.macro.mall.search.service.impl; package com.macro.mall.search.service.impl;
import cn.hutool.core.util.StrUtil;
import com.macro.mall.search.dao.EsProductDao; import com.macro.mall.search.dao.EsProductDao;
import com.macro.mall.search.domain.EsProduct; import com.macro.mall.search.domain.EsProduct;
import com.macro.mall.search.domain.EsProductRelatedInfo; import com.macro.mall.search.domain.EsProductRelatedInfo;
@ -13,6 +14,7 @@ import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter; import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter;
import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested; import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedLongTerms; import org.elasticsearch.search.aggregations.bucket.terms.ParsedLongTerms;
@ -36,10 +38,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.*;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -142,21 +141,21 @@ public class EsProductServiceImpl implements EsProductService {
//排序 //排序
if(sort==1){ if(sort==1){
//按新品从新到旧 //按新品从新到旧
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("id").order(SortOrder.DESC)); nativeSearchQueryBuilder.withSorts(SortBuilders.fieldSort("id").order(SortOrder.DESC));
}else if(sort==2){ }else if(sort==2){
//按销量从高到低 //按销量从高到低
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("sale").order(SortOrder.DESC)); nativeSearchQueryBuilder.withSorts(SortBuilders.fieldSort("sale").order(SortOrder.DESC));
}else if(sort==3){ }else if(sort==3){
//按价格从低到高 //按价格从低到高
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("price").order(SortOrder.ASC)); nativeSearchQueryBuilder.withSorts(SortBuilders.fieldSort("price").order(SortOrder.ASC));
}else if(sort==4){ }else if(sort==4){
//按价格从高到低 //按价格从高到低
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("price").order(SortOrder.DESC)); nativeSearchQueryBuilder.withSorts(SortBuilders.fieldSort("price").order(SortOrder.DESC));
}else{ }else{
//按相关度 //按相关度
nativeSearchQueryBuilder.withSort(SortBuilders.scoreSort().order(SortOrder.DESC)); nativeSearchQueryBuilder.withSorts(SortBuilders.scoreSort().order(SortOrder.DESC));
} }
nativeSearchQueryBuilder.withSort(SortBuilders.scoreSort().order(SortOrder.DESC)); nativeSearchQueryBuilder.withSorts(SortBuilders.scoreSort().order(SortOrder.DESC));
NativeSearchQuery searchQuery = nativeSearchQueryBuilder.build(); NativeSearchQuery searchQuery = nativeSearchQueryBuilder.build();
LOGGER.info("DSL:{}", searchQuery.getQuery().toString()); LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class); SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
@ -217,15 +216,15 @@ public class EsProductServiceImpl implements EsProductService {
public EsProductRelatedInfo searchRelatedInfo(String keyword) { public EsProductRelatedInfo searchRelatedInfo(String keyword) {
NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder(); NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder();
//搜索条件 //搜索条件
if(StringUtils.isEmpty(keyword)){ if(StrUtil.isEmpty(keyword)){
builder.withQuery(QueryBuilders.matchAllQuery()); builder.withQuery(QueryBuilders.matchAllQuery());
}else{ }else{
builder.withQuery(QueryBuilders.multiMatchQuery(keyword,"name","subTitle","keywords")); builder.withQuery(QueryBuilders.multiMatchQuery(keyword,"name","subTitle","keywords"));
} }
//聚合搜索品牌名称 //聚合搜索品牌名称
builder.addAggregation(AggregationBuilders.terms("brandNames").field("brandName")); builder.withAggregations(AggregationBuilders.terms("brandNames").field("brandName"));
//集合搜索分类名称 //集合搜索分类名称
builder.addAggregation(AggregationBuilders.terms("productCategoryNames").field("productCategoryName")); builder.withAggregations(AggregationBuilders.terms("productCategoryNames").field("productCategoryName"));
//聚合搜索商品属性去除type=1的属性 //聚合搜索商品属性去除type=1的属性
AbstractAggregationBuilder aggregationBuilder = AggregationBuilders.nested("allAttrValues","attrValueList") AbstractAggregationBuilder aggregationBuilder = AggregationBuilders.nested("allAttrValues","attrValueList")
.subAggregation(AggregationBuilders.filter("productAttrs",QueryBuilders.termQuery("attrValueList.type",1)) .subAggregation(AggregationBuilders.filter("productAttrs",QueryBuilders.termQuery("attrValueList.type",1))
@ -235,7 +234,7 @@ public class EsProductServiceImpl implements EsProductService {
.field("attrValueList.value")) .field("attrValueList.value"))
.subAggregation(AggregationBuilders.terms("attrNames") .subAggregation(AggregationBuilders.terms("attrNames")
.field("attrValueList.name")))); .field("attrValueList.name"))));
builder.addAggregation(aggregationBuilder); builder.withAggregations(aggregationBuilder);
NativeSearchQuery searchQuery = builder.build(); NativeSearchQuery searchQuery = builder.build();
SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class); SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(searchQuery, EsProduct.class);
return convertProductRelatedInfo(searchHits); return convertProductRelatedInfo(searchHits);
@ -246,7 +245,7 @@ public class EsProductServiceImpl implements EsProductService {
*/ */
private EsProductRelatedInfo convertProductRelatedInfo(SearchHits<EsProduct> response) { private EsProductRelatedInfo convertProductRelatedInfo(SearchHits<EsProduct> response) {
EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo(); EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo();
Map<String, Aggregation> aggregationMap = response.getAggregations().getAsMap(); Map<String, Aggregation> aggregationMap = ((Aggregations)response.getAggregations().aggregations()).asMap();
//设置品牌 //设置品牌
Aggregation brandNames = aggregationMap.get("brandNames"); Aggregation brandNames = aggregationMap.get("brandNames");
List<String> brandNameList = new ArrayList<>(); List<String> brandNameList = new ArrayList<>();

View File

@ -1,6 +1,6 @@
spring: spring:
datasource: datasource:
url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root username: root
password: root password: root
druid: druid:
@ -17,8 +17,7 @@ spring:
repositories: repositories:
enabled: true enabled: true
elasticsearch: elasticsearch:
rest: uris: localhost:9200
uris: localhost:9200
logging: logging:
level: level:
@ -26,4 +25,5 @@ logging:
com.macro.mall: debug com.macro.mall: debug
logstash: logstash:
host: localhost host: localhost
enableInnerLog: false

View File

@ -1,6 +1,6 @@
spring: spring:
datasource: datasource:
url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
username: reader username: reader
password: 123456 password: 123456
druid: druid:
@ -17,8 +17,7 @@ spring:
repositories: repositories:
enabled: true enabled: true
elasticsearch: elasticsearch:
rest: uris: es:9200
uris: es:9200
logging: logging:
file: file: