From f252378cce3151adcada8dd2033e550dc400844c Mon Sep 17 00:00:00 2001 From: wangkang Date: Wed, 11 Apr 2018 17:05:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0spring=20boot=20admin?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../udf-admin-server-dev.properties | 18 +++ udf-server/pom.xml | 3 +- udf-server/udf-admin-server/pom.xml | 114 ++++++++++++++++++ .../admin/server/NotifierConfiguration.java | 63 ++++++++++ .../server/UdfAdminServerApplication.java | 63 ++++++++++ .../main/resources/bootstrap-dev.properties | 32 +++++ .../src/main/resources/bootstrap.properties | 39 ++++++ .../src/main/resources/logback.xml | 5 + .../main/resources/bootstrap-dev.properties | 2 +- .../src/main/resources/build_qa.sh | 2 +- 10 files changed, 338 insertions(+), 3 deletions(-) create mode 100644 udf-config-repository/udf-admin-server/udf-admin-server-dev.properties create mode 100644 udf-server/udf-admin-server/pom.xml create mode 100644 udf-server/udf-admin-server/src/main/java/org/itkk/udf/admin/server/NotifierConfiguration.java create mode 100644 udf-server/udf-admin-server/src/main/java/org/itkk/udf/admin/server/UdfAdminServerApplication.java create mode 100644 udf-server/udf-admin-server/src/main/resources/bootstrap-dev.properties create mode 100644 udf-server/udf-admin-server/src/main/resources/bootstrap.properties create mode 100644 udf-server/udf-admin-server/src/main/resources/logback.xml diff --git a/udf-config-repository/udf-admin-server/udf-admin-server-dev.properties b/udf-config-repository/udf-admin-server/udf-admin-server-dev.properties new file mode 100644 index 0000000..b44496a --- /dev/null +++ b/udf-config-repository/udf-admin-server/udf-admin-server-dev.properties @@ -0,0 +1,18 @@ +######################################################## +###org.itkk.application.config (ApplicationConfig) +######################################################## +org.itkk.application.config.outputExceptionStackTrace=true +org.itkk.application.config.threadPool.poolSize=100 +######################################################## +###LOGGING (must reboot) +######################################################## +logging.file=d:/develop/application-log/${spring.application.name}_${server.port}_${spring.profiles.active}/base.log +######################################################## +###turbine ( TurbineProperties ) +######################################################## +turbine.appConfig=udf-admin-server +######################################################## +###notify +######################################################## +spring.boot.admin.notify.mail.from=udf_admin@163.com +spring.boot.admin.notify.mail.to=udf_admin@163.com \ No newline at end of file diff --git a/udf-server/pom.xml b/udf-server/pom.xml index b7c2abc..7a8b509 100644 --- a/udf-server/pom.xml +++ b/udf-server/pom.xml @@ -24,11 +24,12 @@ 192.168.1.10:5000/org.itkk/java:8 192.168.1.10:5000 wangkangit@163.com - 1.5.6 + 1.5.7 udf-eureka-config-server + udf-admin-server diff --git a/udf-server/udf-admin-server/pom.xml b/udf-server/udf-admin-server/pom.xml new file mode 100644 index 0000000..8e6daa3 --- /dev/null +++ b/udf-server/udf-admin-server/pom.xml @@ -0,0 +1,114 @@ + + + 4.0.0 + + udf-admin-server + udf-admin-server + jar + http://itkk.org:81 + + + org.itkk.udf + udf-server + 1.0 + + + + 9002 + 8002 + + + + + + org.springframework.boot + spring-boot-starter-mail + + + + de.codecentric + spring-boot-admin-server + ${spring-boot-admin.version} + + + de.codecentric + spring-boot-admin-server-ui + ${spring-boot-admin.version} + + + de.codecentric + spring-boot-admin-server-ui-turbine + ${spring-boot-admin.version} + + + de.codecentric + spring-boot-admin-server-ui-login + ${spring-boot-admin.version} + + + + org.springframework.cloud + spring-cloud-starter-turbine + + + + org.springframework.boot + spring-boot-starter-security + + + + org.itkk.udf + udf-starter-core + + + + org.itkk.udf + udf-starter-amqp-rabbitmq + + + + + + + ${project.basedir}/src/main/resources/ + true + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${springboot.version} + + + + repackage + + + + + + + com.spotify + docker-maven-plugin + ${docker-maven-plugin.version} + + ${docker.registry.host}/${project.groupId}/${project.artifactId}:latest + ${docker.java.base.image} + ${docker.maintainer} + ${server.port} + + ["java","-jar","/${project.build.finalName}.jar"] + + + ${project.build.directory} + ${project.build.finalName}.jar + + + + + + + diff --git a/udf-server/udf-admin-server/src/main/java/org/itkk/udf/admin/server/NotifierConfiguration.java b/udf-server/udf-admin-server/src/main/java/org/itkk/udf/admin/server/NotifierConfiguration.java new file mode 100644 index 0000000..348a29d --- /dev/null +++ b/udf-server/udf-admin-server/src/main/java/org/itkk/udf/admin/server/NotifierConfiguration.java @@ -0,0 +1,63 @@ +package org.itkk.udf.admin.server.demo; + +import de.codecentric.boot.admin.notify.MailNotifier; +import de.codecentric.boot.admin.notify.Notifier; +import de.codecentric.boot.admin.notify.RemindingNotifier; +import de.codecentric.boot.admin.notify.filter.FilteringNotifier; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.scheduling.annotation.Scheduled; + +import java.util.concurrent.TimeUnit; + +/** + * 通知 + */ +@Configuration +@ConditionalOnBean(MailNotifier.class) +@AutoConfigureAfter(de.codecentric.boot.admin.config.NotifierConfiguration.MailNotifierConfiguration.class) +public class NotifierConfiguration { + + /** + * delegate + */ + @Autowired + private Notifier delegate; + + /** + * filteringNotifier + * + * @return FilteringNotifier + */ + @Bean + public FilteringNotifier filteringNotifier() { + return new FilteringNotifier(delegate); + } + + /** + * remindingNotifier + * + * @return RemindingNotifier + */ + @Bean + @Primary + public RemindingNotifier remindingNotifier() { + final int duration = 10; + RemindingNotifier notifier = new RemindingNotifier(filteringNotifier()); + notifier.setReminderPeriod(TimeUnit.SECONDS.toMillis(duration)); + return notifier; + } + + /** + * remind + */ + @Scheduled(fixedRate = 60_000L) + public void remind() { + remindingNotifier().sendReminders(); + } + +} diff --git a/udf-server/udf-admin-server/src/main/java/org/itkk/udf/admin/server/UdfAdminServerApplication.java b/udf-server/udf-admin-server/src/main/java/org/itkk/udf/admin/server/UdfAdminServerApplication.java new file mode 100644 index 0000000..b1e857f --- /dev/null +++ b/udf-server/udf-admin-server/src/main/java/org/itkk/udf/admin/server/UdfAdminServerApplication.java @@ -0,0 +1,63 @@ +/** + * UdfEurekaServerDemoApplication.java + * Created at 2016-10-02 + * Created by wangkang + * Copyright (C) 2016 itkk.org, All rights reserved. + */ +package org.itkk.udf.admin.server.demo; + +import org.itkk.udf.core.BaseApplication; +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.cloud.netflix.turbine.EnableTurbine; +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 de.codecentric.boot.admin.config.EnableAdminServer; + +/** + * 描述 : 系统入口 + * + * @author wangkang + */ +@SpringCloudApplication +@EnableAdminServer +@EnableTurbine +public class UdfAdminServerApplication extends BaseApplication { + + /** + * 描述 : spring boot的入口,在整个项目中,包括其子项目在内, 只能有一个main方法,否则spring boot启动不起来 + * + * @param args 参数 + */ + public static void main(String[] args) { + SpringApplication.run(UdfAdminServerApplication.class, args); + } + + /** + * 描述 : SecurityConfig + * + * @author Administrator + */ + @Configuration + public static class SecurityConfig extends WebSecurityConfigurerAdapter { + @Override + protected void configure(HttpSecurity http) throws Exception { + // Page with login form is served as /login.html and does a POST on /login + http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll(); + // The UI does a POST on /logout on logout + http.logout().logoutUrl("/logout"); + // The ui currently doesn't support csrf + http.csrf().disable(); + // Requests for the login page and the static assets are allowed + http.authorizeRequests().antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**") + .permitAll(); + // ... and any other request needs to be authorized + http.authorizeRequests().antMatchers("/**").authenticated(); + // Enable so that the clients can authenticate via HTTP basic for registering + http.httpBasic(); + } + } + +} diff --git a/udf-server/udf-admin-server/src/main/resources/bootstrap-dev.properties b/udf-server/udf-admin-server/src/main/resources/bootstrap-dev.properties new file mode 100644 index 0000000..b8a4dbc --- /dev/null +++ b/udf-server/udf-admin-server/src/main/resources/bootstrap-dev.properties @@ -0,0 +1,32 @@ +######################################################## +###security (must reboot) +######################################################## +security.user.name=admin +security.user.password=123456 +######################################################## +###eureka.client ( EurekaInstanceConfigBean , EurekaClientConfigBean , EurekaServerConfigBean ) (must reboot) +######################################################## +eureka.instance.preferIpAddress=true +eureka.client.serviceUrl.defaultZone=http://admin:123456@127.0.0.1:9001/eureka/ +######################################################## +###spring.cloud.config ( ConfigClientProperties ) +######################################################## +spring.cloud.config.username=admin +spring.cloud.config.password=123456 +spring.cloud.config.enabled=true +spring.cloud.config.profile=${spring.profiles.active} +spring.cloud.config.name=${spring.application.name},base,gzip,mail,rabbitmq +spring.cloud.config.label=master +spring.cloud.config.failFast=true +spring.cloud.config.discovery.enabled=true +spring.cloud.config.discovery.serviceId=UDF-EUREKA-CONFIG-SERVER +######################################################## +###spring.boot.admin (http://blog.csdn.net/yiyaopeng/article/details/72887134) +######################################################## +spring.boot.admin.routes.endpoints=env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream,turbine.stream +spring.boot.admin.turbine.location=UDF-ADMIN-SERVER +spring.boot.admin.turbine.clusters=default +######################################################## +###turbine ( TurbineProperties ) +######################################################## +turbine.clusterNameExpression=new String("default") \ No newline at end of file diff --git a/udf-server/udf-admin-server/src/main/resources/bootstrap.properties b/udf-server/udf-admin-server/src/main/resources/bootstrap.properties new file mode 100644 index 0000000..684124f --- /dev/null +++ b/udf-server/udf-admin-server/src/main/resources/bootstrap.properties @@ -0,0 +1,39 @@ +######################################################## +###INFO ( note : info.build.time is the UTC time ) +######################################################## +info.build.group=${project.groupId} +info.build.artifact=${project.artifactId} +info.build.version=${project.version} +info.build.name=${project.name} +info.build.time=${project.build.date} +info.build.encoding=${project.build.sourceEncoding} +info.build.java.source=${java.version} +info.build.java.target=${java.version} +######################################################## +###IDENTITY +######################################################## +spring.application.name=${project.name} +######################################################## +###WEB PROPERTIES (ServerProperties) +######################################################## +server.port=${server.port} +######################################################## +###MANAGEMENT (ManagementServerProperties) +######################################################## +management.security.enabled=false +######################################################## +###PROFILES +######################################################## +spring.profiles.active=${profiles.activation} +######################################################## +###org.itkk.application.config (ApplicationConfig) (must reboot) +######################################################## +org.itkk.application.config.encoding=UTF-8 +org.itkk.application.config.timeZone=Asia/Shanghai +org.itkk.application.config.dateFormat=yyyy-MM-dd'T'HH:mm:ss:SSSZ +######################################################## +### shutdown +######################################################## +endpoints.shutdown.enabled=true +endpoints.shutdown.sensitive=true +management.port=${management.port} \ No newline at end of file diff --git a/udf-server/udf-admin-server/src/main/resources/logback.xml b/udf-server/udf-admin-server/src/main/resources/logback.xml new file mode 100644 index 0000000..049dc97 --- /dev/null +++ b/udf-server/udf-admin-server/src/main/resources/logback.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/udf-server/udf-eureka-config-server/src/main/resources/bootstrap-dev.properties b/udf-server/udf-eureka-config-server/src/main/resources/bootstrap-dev.properties index 6116733..e58d6e6 100644 --- a/udf-server/udf-eureka-config-server/src/main/resources/bootstrap-dev.properties +++ b/udf-server/udf-eureka-config-server/src/main/resources/bootstrap-dev.properties @@ -48,7 +48,7 @@ org.itkk.application.config.threadPool.poolSize=100 ######################################################## ###LOGGING (must reboot) ######################################################## -logging.file=d:/develop/${project.groupId}-log/${spring.application.name}_${server.port}_${spring.profiles.active}/base.log +logging.file=d:/develop/application-log/${spring.application.name}_${server.port}_${spring.profiles.active}/base.log ######################################################## ###GZIP (ServerProperties) ((must reboot) ######################################################## diff --git a/udf-server/udf-eureka-config-server/src/main/resources/build_qa.sh b/udf-server/udf-eureka-config-server/src/main/resources/build_qa.sh index 836c3ca..f20dd0b 100644 --- a/udf-server/udf-eureka-config-server/src/main/resources/build_qa.sh +++ b/udf-server/udf-eureka-config-server/src/main/resources/build_qa.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -base_path="udf-sample-api" +base_path="udf-server" echo 'shutdown application begin' returnCode=`curl -I -s -X POST "http://127.0.0.1:${management.port}/shutdown"|head -1|cut -d" " -f2`