Browse Source

init

master
zhizhi wu 5 years ago
commit
55bfa8422d
  1. 32
      .gitignore
  2. 63
      admin/pom.xml
  3. 64
      admin/src/main/java/com/ccsens/admin/AdminApplication.java
  4. 36
      admin/src/main/java/com/ccsens/admin/config/CustomNotifier.java
  5. 64
      admin/src/main/resources/application-dev.yml
  6. 64
      admin/src/main/resources/application-prod.yml
  7. 70
      admin/src/main/resources/application-test.yml
  8. 3
      admin/src/main/resources/application.yml
  9. 40
      eureka/pom.xml
  10. 20
      eureka/src/main/java/com/ccsens/eureka/EurekaApplication.java
  11. 26
      eureka/src/main/java/com/ccsens/eureka/config/WebSecurityConfig.java
  12. 55
      eureka/src/main/resources/application-dev1.yml
  13. 38
      eureka/src/main/resources/application-dev2.yml
  14. 3
      eureka/src/main/resources/application.yml
  15. 100
      pom.xml

32
.gitignore

@ -0,0 +1,32 @@
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
*.class
target
target/
target/*
.idea
.idea/
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
*.iml
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

63
admin/pom.xml

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>common</artifactId>
<groupId>com.ccsens</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>admin</artifactId>
<properties>
<admin.version>2.1.6</admin.version>
</properties>
<dependencies>
<!--admin-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${admin.version}</version>
</dependency>
<!--admin ui-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>${admin.version}</version>
</dependency>
<!--eureka客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--登录权限-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!--邮件通知-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!--JMX Bean-->
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
<!--turbine-->
<!--<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui-turbine</artifactId>
<version>1.5.7</version>
</dependency>-->
</dependencies>
</project>

64
admin/src/main/java/com/ccsens/admin/AdminApplication.java

@ -0,0 +1,64 @@
package com.ccsens.admin;
import de.codecentric.boot.admin.server.config.AdminServerProperties;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
/**
* @description:
* @author: wuHuiJuan
* @create: 2019/11/22 15:57
*/
@Configuration
@EnableAutoConfiguration(exclude= {DataSourceAutoConfiguration.class})
@EnableDiscoveryClient
@EnableAdminServer
public class AdminApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}
@Configuration
public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath;
public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");
http.authorizeRequests()
.antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
.httpBasic().and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers(
adminContextPath + "/instances",
adminContextPath + "/actuator/**"
);
// @formatter:on
}
}
}

36
admin/src/main/java/com/ccsens/admin/config/CustomNotifier.java

@ -0,0 +1,36 @@
package com.ccsens.admin.config;
import de.codecentric.boot.admin.server.domain.entities.Instance;
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
import de.codecentric.boot.admin.server.domain.events.InstanceEvent;
import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent;
import de.codecentric.boot.admin.server.notify.AbstractEventNotifier;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
/**
* @description: add your own Notifiers
* @author: wuHuiJuan
* @create: 2019/11/25 12:35
*/
@Slf4j
public class CustomNotifier extends AbstractEventNotifier {
public CustomNotifier(InstanceRepository repository) {
super(repository);
}
@Override
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
return Mono.fromRunnable(() -> {
if (event instanceof InstanceStatusChangedEvent) {
log.info("Instance {} ({}) is {}", instance.getRegistration().getName(), event.getInstance(),
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus());
} else {
log.info("Instance {} ({}) {}", instance.getRegistration().getName(), event.getInstance(),
event.getType());
}
});
}
}

64
admin/src/main/resources/application-dev.yml

@ -0,0 +1,64 @@
server:
port: 7000
# 使用在服务代理器之后
# use-forward-headers: true
spring:
application:
name: admin
boot:
admin:
ui:
title: SpringBootAdmin-Server
# notify:
# mail:
# from: ${spring.mail.username}
# to: 2377881365@qq.com
security:
user:
name: admin #配置登录的账号
password: password #配置登录的密码
# mail:
# host: smtp.qq.com
# username: 654600784@qq.com
# password: ryuwsxunlaxvbcbg
# properties:
# mail:
# smtp:
# auth: true
#Actuator配置:暴露敏感路径,默认情况下,敏感路径并不暴露
management:
endpoints:
web:
exposure:
# 暴露xxx端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
include: "*"
# 不暴露哪些端点
# exclude: env,beans,configprops
endpoint:
health:
# 是否展示健康检查详情
show-details: ALWAYS
health:
redis:
enabled: false
eureka:
instance:
lease-renewal-interval-in-seconds: 10
health-check-url-path: /actuator/health
metadata-map:
# startup: ${random.int} #needed to trigger info and endpoint update after restart
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
# # 是否注册IP到eureka server,如不指定或设为false,那就回注册主机名到eureka server
prefer-ip-address: true
client:
service-url:
# 指定eureka server通信地址,注意/eureka/小尾巴不能少
# defaultZone: http://admin:admin@peer1:8761/eureka/,http://admin:admin@peer2:8762/eureka/
defaultZone: http://admin:admin@127.0.0.1:7010/eureka/
registry-fetch-interval-seconds: 5
logging:
file: /home/admin/log/admin.log
pattern:
file: '%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx'

64
admin/src/main/resources/application-prod.yml

@ -0,0 +1,64 @@
server:
port: 7000
# 使用在服务代理器之后
# use-forward-headers: true
spring:
application:
name: admin
boot:
admin:
ui:
title: SpringBootAdmin-Server
# notify:
# mail:
# from: ${spring.mail.username}
# to: wuhuijuan@ccsens.com, zhangye@ccsens.com,weizezhao@ccsens.com
security:
user:
name: admin #配置登录的账号
password: password #配置登录的密码
# mail:
# host: smtp.qq.com
# username: 654600784@qq.com
# password: ryuwsxunlaxvbcbg
# properties:
# mail:
# smtp:
# auth: true
#Actuator配置:暴露敏感路径,默认情况下,敏感路径并不暴露
management:
endpoints:
web:
exposure:
# 暴露xxx端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
# include: "*"
# 不暴露哪些端点
exclude: env,beans,configprops
endpoint:
health:
# 是否展示健康检查详情
show-details: ALWAYS
health:
redis:
enabled: false
eureka:
instance:
lease-renewal-interval-in-seconds: 10
health-check-url-path: /actuator/health
metadata-map:
# startup: ${random.int} #needed to trigger info and endpoint update after restart
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
# # 是否注册IP到eureka server,如不指定或设为false,那就回注册主机名到eureka server
prefer-ip-address: true
client:
service-url:
# 指定eureka server通信地址,注意/eureka/小尾巴不能少
# defaultZone: http://admin:admin@peer1:8761/eureka/,http://admin:admin@peer2:8762/eureka/
defaultZone: http://admin:admin@127.0.0.1:7010/eureka/
registry-fetch-interval-seconds: 5
logging:
file: /home/admin/log/admin.log
pattern:
file: '%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx'

70
admin/src/main/resources/application-test.yml

@ -0,0 +1,70 @@
server:
port: 7000
# 使用在服务代理器之后
# use-forward-headers: true
spring:
application:
name: admin
boot:
admin:
ui:
title: SpringBootAdmin-Server
notify:
mail:
from: ${spring.mail.username}
to: 2377881365@qq.com
routes:
# endpoints: env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,activiti,hystrix.stream,turbine.stream
endpoints: env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,activiti,hystrix.stream
# turbine:
# clusters: default
# location: microservice-hystrix-turbine
security:
user:
name: admin #配置登录的账号
password: password #配置登录的密码
mail:
host: smtp.qq.com
username: 654600784@qq.com
password: ryuwsxunlaxvbcbg
properties:
mail:
smtp:
auth: true
#Actuator配置:暴露敏感路径,默认情况下,敏感路径并不暴露
management:
endpoints:
web:
exposure:
# 暴露xxx端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
include: "*"
# 不暴露哪些端点
exclude: env,beans,configprops
endpoint:
health:
# 是否展示健康检查详情
show-details: ALWAYS
health:
redis:
enabled: false
eureka:
instance:
lease-renewal-interval-in-seconds: 10
health-check-url-path: /actuator/health
metadata-map:
# startup: ${random.int} #needed to trigger info and endpoint update after restart
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
# # 是否注册IP到eureka server,如不指定或设为false,那就回注册主机名到eureka server
prefer-ip-address: true
client:
service-url:
# 指定eureka server通信地址,注意/eureka/小尾巴不能少
# defaultZone: http://admin:admin@peer1:8761/eureka/,http://admin:admin@peer2:8762/eureka/
defaultZone: http://admin:admin@peer1:8761/eureka/
registry-fetch-interval-seconds: 5
logging:
file: /home/admin/log/admin.log
pattern:
file: '%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx'

3
admin/src/main/resources/application.yml

@ -0,0 +1,3 @@
spring:
profiles:
active: prod

40
eureka/pom.xml

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>common</artifactId>
<groupId>com.ccsens</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eureka</artifactId>
<dependencies>
<!--eureka服务端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!--权限控制-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>2.1.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>2.1.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

20
eureka/src/main/java/com/ccsens/eureka/EurekaApplication.java

@ -0,0 +1,20 @@
package com.ccsens.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* @description:
* @author: wuHuiJuan
* @create: 2019/11/26 09:45
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}

26
eureka/src/main/java/com/ccsens/eureka/config/WebSecurityConfig.java

@ -0,0 +1,26 @@
package com.ccsens.eureka.config;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* @description: 权限控制
* @author: wuHuiJuan
* @create: 2019/11/26 09:50
*/
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/eureka/**");
http.authorizeRequests()
.antMatchers( "/actuator/**").permitAll();
super.configure(http);
}
}

55
eureka/src/main/resources/application-dev1.yml

@ -0,0 +1,55 @@
server:
port: 7010
spring:
application:
name: eureka
#配置登录账号密码
security:
user:
name: admin
password: admin
# 单台
eureka:
instance:
#Eureka Server对端口是不敏感的,这意味着,如果直接用IP的形式(例如地址写成http://127.0.0.1:8761/eureka/)相互注册,Eureka Server误认为两个Eureka Server实例是一个实例——这会造成Eureka Server首页显示不正常等一系列问题!!
hostname: 127.0.0.1
# eureka既是服务端,也是客户端
client:
#是否要注册到其他Eureka Server实例(eureka集群需要,单台不需要)
register-with-eureka: false
#是否要从其他Eureka Server实例获取数据
fetch-registry: false
service-url:
defaultZone: http://admin:admin@localhost:7010/eureka/
server:
enable-self-preservation: false
# 集群
#eureka:
# instance:
# #Eureka Server对端口是不敏感的,这意味着,如果直接用IP的形式(例如地址写成http://127.0.0.1:8761/eureka/)相互注册,Eureka Server误认为两个Eureka Server实例是一个实例——这会造成Eureka Server首页显示不正常等一系列问题!!
# hostname: peer1
# # eureka既是服务端,也是客户端
# client:
# #是否要注册到其他Eureka Server实例(eureka集群需要,单台不需要)
# register-with-eureka: true
# #是否要从其他Eureka Server实例获取数据
# fetch-registry: true
# #注册Eureka Server
# service-url:
# defaultZone: http://admin:admin@peer2:8762/eureka/
management:
health:
redis:
enabled: false
endpoint:
health:
# 为health端点配置显示详情
show-details: always
endpoints:
web:
exposure:
# 暴露metrics端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
include: "*"
# 不暴露哪些端点
exclude: env,beans,configprops

38
eureka/src/main/resources/application-dev2.yml

@ -0,0 +1,38 @@
server:
port: 8762
spring:
application:
name: eureka
#配置登录账号密码
security:
user:
name: admin
password: admin
eureka:
instance:
#Eureka Server对端口是不敏感的,这意味着,如果直接用IP的形式(例如地址写成http://127.0.0.1:8761/eureka/)相互注册,Eureka Server误认为两个Eureka Server实例是一个实例——这会造成Eureka Server首页显示不正常等一系列问题!!
hostname: peer2
# eureka既是服务端,也是客户端
client:
#是否要注册到其他Eureka Server实例(eureka集群需要,单台不需要)
register-with-eureka: true
#是否要从其他Eureka Server实例获取数据
fetch-registry: true
#注册Eureka Server
service-url:
defaultZone: http://admin:admin@peer2:8761/eureka/
management:
health:
redis:
enabled: false
endpoint:
health:
# 为health端点配置显示详情
show-details: always
endpoints:
web:
exposure:
# 暴露metrics端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
include: "*"
# 不暴露哪些端点
exclude: env,beans,configprops

3
eureka/src/main/resources/application.yml

@ -0,0 +1,3 @@
spring:
profiles:
active: dev1

100
pom.xml

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>admin</module>
<module>eureka</module>
<module>ccmq</module>
<module>histrixmonitor</module>
</modules>
<groupId>com.ccsens</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<!-- 引入spring cloud的依赖,不能少,主要用来管理Spring Cloud生态各组件的版本 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Loading…
Cancel
Save