From 55bfa8422d051977925fb829bd9680e270fb363f Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Tue, 28 Jul 2020 14:48:27 +0800 Subject: [PATCH] init --- .gitignore | 32 ++++++ admin/pom.xml | 63 +++++++++++ .../com/ccsens/admin/AdminApplication.java | 64 +++++++++++ .../ccsens/admin/config/CustomNotifier.java | 36 +++++++ admin/src/main/resources/application-dev.yml | 64 +++++++++++ admin/src/main/resources/application-prod.yml | 64 +++++++++++ admin/src/main/resources/application-test.yml | 70 ++++++++++++ admin/src/main/resources/application.yml | 3 + eureka/pom.xml | 40 +++++++ .../com/ccsens/eureka/EurekaApplication.java | 20 ++++ .../eureka/config/WebSecurityConfig.java | 26 +++++ .../src/main/resources/application-dev1.yml | 55 ++++++++++ .../src/main/resources/application-dev2.yml | 38 +++++++ eureka/src/main/resources/application.yml | 3 + pom.xml | 100 ++++++++++++++++++ 15 files changed, 678 insertions(+) create mode 100644 .gitignore create mode 100644 admin/pom.xml create mode 100644 admin/src/main/java/com/ccsens/admin/AdminApplication.java create mode 100644 admin/src/main/java/com/ccsens/admin/config/CustomNotifier.java create mode 100644 admin/src/main/resources/application-dev.yml create mode 100644 admin/src/main/resources/application-prod.yml create mode 100644 admin/src/main/resources/application-test.yml create mode 100644 admin/src/main/resources/application.yml create mode 100644 eureka/pom.xml create mode 100644 eureka/src/main/java/com/ccsens/eureka/EurekaApplication.java create mode 100644 eureka/src/main/java/com/ccsens/eureka/config/WebSecurityConfig.java create mode 100644 eureka/src/main/resources/application-dev1.yml create mode 100644 eureka/src/main/resources/application-dev2.yml create mode 100644 eureka/src/main/resources/application.yml create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25abe6e --- /dev/null +++ b/.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* + diff --git a/admin/pom.xml b/admin/pom.xml new file mode 100644 index 0000000..60ca8bd --- /dev/null +++ b/admin/pom.xml @@ -0,0 +1,63 @@ + + + + common + com.ccsens + 1.0-SNAPSHOT + + 4.0.0 + + admin + + 2.1.6 + + + + + + + de.codecentric + spring-boot-admin-starter-server + ${admin.version} + + + + de.codecentric + spring-boot-admin-server-ui + ${admin.version} + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.boot + spring-boot-starter-security + + + + org.springframework.boot + spring-boot-starter-mail + + + + org.jolokia + jolokia-core + + + + + + + + + \ No newline at end of file diff --git a/admin/src/main/java/com/ccsens/admin/AdminApplication.java b/admin/src/main/java/com/ccsens/admin/AdminApplication.java new file mode 100644 index 0000000..3dc3036 --- /dev/null +++ b/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 + } + } + +} diff --git a/admin/src/main/java/com/ccsens/admin/config/CustomNotifier.java b/admin/src/main/java/com/ccsens/admin/config/CustomNotifier.java new file mode 100644 index 0000000..84272ef --- /dev/null +++ b/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 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()); + } + }); + } +} diff --git a/admin/src/main/resources/application-dev.yml b/admin/src/main/resources/application-dev.yml new file mode 100644 index 0000000..e2c6793 --- /dev/null +++ b/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' \ No newline at end of file diff --git a/admin/src/main/resources/application-prod.yml b/admin/src/main/resources/application-prod.yml new file mode 100644 index 0000000..86345b3 --- /dev/null +++ b/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' \ No newline at end of file diff --git a/admin/src/main/resources/application-test.yml b/admin/src/main/resources/application-test.yml new file mode 100644 index 0000000..fdcd89c --- /dev/null +++ b/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' \ No newline at end of file diff --git a/admin/src/main/resources/application.yml b/admin/src/main/resources/application.yml new file mode 100644 index 0000000..90385b2 --- /dev/null +++ b/admin/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + profiles: + active: prod \ No newline at end of file diff --git a/eureka/pom.xml b/eureka/pom.xml new file mode 100644 index 0000000..bdc359a --- /dev/null +++ b/eureka/pom.xml @@ -0,0 +1,40 @@ + + + + common + com.ccsens + 1.0-SNAPSHOT + + 4.0.0 + + eureka + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + org.springframework.boot + spring-boot-starter-security + + + de.codecentric + spring-boot-admin-server + 2.1.6 + compile + + + de.codecentric + spring-boot-admin-server + 2.1.6 + compile + + + + + \ No newline at end of file diff --git a/eureka/src/main/java/com/ccsens/eureka/EurekaApplication.java b/eureka/src/main/java/com/ccsens/eureka/EurekaApplication.java new file mode 100644 index 0000000..d653c24 --- /dev/null +++ b/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); + } +} diff --git a/eureka/src/main/java/com/ccsens/eureka/config/WebSecurityConfig.java b/eureka/src/main/java/com/ccsens/eureka/config/WebSecurityConfig.java new file mode 100644 index 0000000..1854500 --- /dev/null +++ b/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); + + + } + +} diff --git a/eureka/src/main/resources/application-dev1.yml b/eureka/src/main/resources/application-dev1.yml new file mode 100644 index 0000000..fc5cb78 --- /dev/null +++ b/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 diff --git a/eureka/src/main/resources/application-dev2.yml b/eureka/src/main/resources/application-dev2.yml new file mode 100644 index 0000000..2c76d0e --- /dev/null +++ b/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 diff --git a/eureka/src/main/resources/application.yml b/eureka/src/main/resources/application.yml new file mode 100644 index 0000000..01c59b4 --- /dev/null +++ b/eureka/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + profiles: + active: dev1 \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7c7229b --- /dev/null +++ b/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + pom + + admin + eureka + ccmq + histrixmonitor + + com.ccsens + common + 1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-parent + 2.1.8.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-jetty + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Finchley.SR2 + pom + import + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + +