spring cloud admin 2.0
18180 ワード
目次
spring-cloud-eurekaserver
pom.xml
EurekaServerApplication
application.yml
义齿
pom.xml
SpringClientApplication
application.yml
spring-cloud-admin
pom.xml
SpringBootAdminApplication
spring-useAdmin-demo
pom.xml
DemoApplication.java
spring-cloud-eurekaserver,spring-boot-admin,spring-boot-clientを実行するだけで、spring-boot-clientはspring.boot.admin.client.urlを構成するだけで、spring-boot-adminでプロジェクトを監視できます.
spring-cloud-eurekaserver
pom.xml
EurekaServerApplication
application.yml
义齿
pom.xml
SpringClientApplication
application.yml
spring-cloud-admin
pom.xml
SpringBootAdminApplication
application.yml
注意:spring.profiles.active=secure異なる起動方法では、SpringBootAdministratinApplication.javaは構成に応じて異なる権限ブロックコードを実行します.
spring-useAdmin-demo
pom.xml
DemoApplication.java
application.yml
主な違いはspring.boot.admin.client.url
spring-cloud-eurekaserver
pom.xml
EurekaServerApplication
application.yml
义齿
pom.xml
SpringClientApplication
application.yml
spring-cloud-admin
pom.xml
SpringBootAdminApplication
spring-useAdmin-demo
pom.xml
DemoApplication.java
spring-cloud-eurekaserver,spring-boot-admin,spring-boot-clientを実行するだけで、spring-boot-clientはspring.boot.admin.client.urlを構成するだけで、spring-boot-adminでプロジェクトを監視できます.
spring-cloud-eurekaserver
pom.xml
4.0.0
com.eureka
eurekaServer
0.0.1
jar
EurekaServer
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.5.13.RELEASE
UTF-8
UTF-8
1.8
org.springframework.cloud
spring-cloud-dependencies
Edgware.SR5
pom
import
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.cloud
spring-cloud-starter-eureka-server
org.springframework.boot
spring-boot-starter-security
org.springframework.cloud
spring-cloud-starter-config
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false
EurekaServerApplication
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
application.yml
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/
endpoints:
shutdown:
enabled: true
sensitive: true
security:
user:
name: "xxxx"
password: "xxxx"
义齿
pom.xml
4.0.0
com.test
client
0.0.1-SNAPSHOT
jar
spring-boot-client-2
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.6.RELEASE
UTF-8
UTF-8
1.8
2.0.4
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
2.0.2.RELEASE
org.springframework.boot
spring-boot-starter-test
test
de.codecentric
spring-boot-admin-dependencies
${spring-boot-admin.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
SpringClientApplication
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class SpringBootClient2Application {
public static void main(String[] args) {
SpringApplication.run(SpringBootClient2Application.class, args);
}
}
application.yml
server:
port: 8083
spring:
profiles:
active:
- secure
application:
name: admin-client
boot:
admin:
client:
url: "http://${spring.security.user.name}:${spring.security.user.password}@localhost:8091"
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
---
spring:
profiles: insecure
---
# admin
spring:
profiles: secure
security:
user:
name: "xxx"
password: "xxx"
# eureka eureka
eureka:
instance:
metadata-map:
"user.name": ${spring.security.user.name} #These two are needed so that the server
"user.password": ${spring.security.user.password} #can access the protected client endpoints
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health #2.0 actuator
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://${spring.security.user.name}:${spring.security.user.password}@localhost:8761}/eureka/
spring-cloud-admin
pom.xml
4.0.0
com.monitor
serverAdmin
0.0.1
jar
spring-boot-admin
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.6.RELEASE
UTF-8
UTF-8
1.8
2.0.4
de.codecentric
spring-boot-admin-starter-server
de.codecentric
spring-boot-admin-server-ui
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-security
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
2.0.2.RELEASE
org.springframework.boot
spring-boot-starter-test
test
de.codecentric
spring-boot-admin-dependencies
${spring-boot-admin.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
build-info
SpringBootAdminApplication
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
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 de.codecentric.boot.admin.server.config.AdminServerProperties;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
@EnableDiscoveryClient
@SpringBootApplication
@EnableAdminServer
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
@Profile("insecure")
@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll()//
.and().csrf().disable();
}
}
@Profile("secure")
@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");
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().disable();
// @formatter:on
}
}
}
application.yml
注意:spring.profiles.active=secure異なる起動方法では、SpringBootAdministratinApplication.javaは構成に応じて異なる権限ブロックコードを実行します.
server:
port: 8091
spring:
application:
name: admin-server
profiles:
active:
- secure
# 2.0 ,actuator ,
management:
endpoints:
web:
exposure:
include: "*" #<2>
endpoint:
health:
show-details: ALWAYS
# end::configuration-eureka[]
---
spring:
profiles: insecure
---
# admin
spring:
profiles: secure
security:
user:
name: "xxx"
password: "xxx"
# eureka eureka
eureka:
instance:
metadata-map:
"user.name": ${spring.security.user.name} #These two are needed so that the server
"user.password": ${spring.security.user.password} #can access the protected client endpoints
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health #2.0 actuator
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://${spring.security.user.name}:${spring.security.user.password}@localhost:8761}/eureka/
spring-useAdmin-demo
pom.xml
4.0.0
com.xxx
xx
1.0.0
jar
xxx
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.6.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
2.0.1.RELEASE
org.springframework.boot
spring-boot-maven-plugin
true
DemoApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
@EnableDiscoveryClient
public class PupApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(PupApplication.class, args);
}
}
application.yml
主な違いはspring.boot.admin.client.url
spring:
application:
name: demo
# spring cloud admin
security:
user:
name: "xxx"
password: "xxx"
boot:
admin:
client:
url: "http://${spring.security.user.name}:${spring.security.user.password}@localhost:8091"
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
## eureka eureka
eureka:
instance:
metadata-map:
"user.name": ${spring.security.user.name} #These two are needed so that the server
"user.password": ${spring.security.user.password} #can access the protected client endpoints
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health #2.0 actuator
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://${spring.security.user.name}:${spring.security.user.password}@localhost:8761}/eureka/