SpringBoot実際の電力供給のアイテムモール(20K +スター)住所:github.com/macrozheng / ...
概要
スプリングブート管理者が指標SpringBootモニタリングに適用することができ、それは紙の意志の詳細は、その使用、監視センタのマイクロサービスアーキテクチャとして使用することができます。
春のブート管理者プロフィール
SpringBootアプリケーションは、次いで、グラフィカルインタフェースを介して提示されているこれらの指標によってSpringBootを監視するため、スプリングブート管理アプリケーションを実行して各種インジケータアクチュエータ処理アプリケーションを介して露光することができます。春のブート管理アプリケーションは、各セルを監視し、また、春の雲はマイクロサービスアプリケーションを監視するために組み合わせるレジストリことはできません。
春ブーツ管理者は、アプリケーションを監視するために、以下の情報を提供することができます。
- 実行中の概要情報プロセス監視アプリケーション。
- このようなJVM、Tomcatおよびプロセス情報としてメトリクス情報、。
- このようなシステムの特性、システム環境変数とアプリケーション構成情報として環境変数情報、;
- 作成されたすべてのビーン情報を見ます。
- すべての構成情報のアプリケーションを参照してください。
- Viewアプリケーションとログ。
- ビューJVM情報。
- ビューのWebエンドポイントは、アクセスすることができます。
- 追跡情報を表示HTTP。
管理サーバモジュールを作成します。
ここでは、監視センターとしての機能を発揮するために、管理サーバモジュールを作成します。
- pom.xmlにその依存関係を追加します。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
复制代码
- でapplication.ymlで構成されました:
spring:
application:
name: admin-server
server:
port: 9301
复制代码
- 管理サーバ機能を有効にするには、スタートアップクラスに@EnableAdminServer追加します。
@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
复制代码
管理クライアントモジュールを作成します。
ここでは、クライアント管理サーバとして登録するための管理クライアントモジュールを作成します。
- pom.xmlにその依存関係を追加します。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
复制代码
- でapplication.ymlで構成されました:
spring:
application:
name: admin-client
boot:
admin:
client:
url: http://localhost:9301 #配置admin-server地址
server:
port: 9305
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
logging:
file: admin-client.log #添加开启admin的日志监控
复制代码
- 管理サーバと管理クライアントサービスを開始します。
監視情報のデモ
- 春ブーツ管理者のホームページを開くには、以下のアドレスにアクセスしてください:HTTP:// localhostを:9301
-
壁板のボタンをクリックして、情報を監視、管理、クライアントのビューを選択します。
-
監視情報の概要。
- このようなJVM、Tomcatおよびプロセス情報としてメトリクス情報、。
- このようなシステムの特性、システム環境変数とアプリケーション構成情報として環境変数情報、;
- 作成されたすべてのビーン情報を見ます。
- すべての構成情報のアプリケーションを参照してください。
- ログ情報を表示するには、次の設定を開くことができます追加する必要があります。
logging:
file: admin-client.log #添加开启admin的日志监控
复制代码
- ビューJVM情報。
- ビューのWebエンドポイントは、アクセスすることができます。
- 追跡情報を表示HTTP;
登録センターと連携して
春ブーツ管理者は、春の雲登録センターを組み合わせて、単に管理サーバと登録センターの統合は、管理サーバーは自動的に監視情報を取得するために、レジストリからサービスのリストを取得し、その後、一つずつますすることができます。この機能を導入する例として、ここではユーレカセンターにサインアップしてください。
管理サーバーを変更します。
- pom.xmlにその依存関係を追加します。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
复制代码
- アプリケーションeureka.ymlを設定し、単純にレジストリの設定を追加します。
spring:
application:
name: admin-server
server:
port: 9301
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8001/eureka/
复制代码
- サービス登録を有効にするには、起動クラスに@EnableDiscoveryClientを追加します。
@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
复制代码
管理クライアントを変更します
- pom.xmlにその依存関係を追加します。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
复制代码
- アプリケーションeureka.ymlを設定し、オリジナルの管理サーバアドレスの設定を削除し、レジストリの設定を追加することができます。
spring:
application:
name: admin-client
server:
port: 9305
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
logging:
file: admin-client.log #添加开启admin的日志监控
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8001/eureka/
复制代码
- サービス登録を有効にするには、起動クラスに@EnableDiscoveryClientを追加します。
@EnableDiscoveryClient
@SpringBootApplication
public class AdminClientApplication {
public static void main(String[] args) {
SpringApplication.run(AdminClientApplication.class, args);
}
}
复制代码
デモ
-
ブートアプリケーションeureka.yml構成管理サーバ、管理クライアントを使用して、ユーレカ・サーバを起動します。
-
ビューレジストリサービスが登録されていることがわかった:HTTPを:// localhostを:8001 /
- ビュー春のブート管理ホームの発見は、サービス情報を見ることができます:HTTP:// localhostを:9301
ログイン認証を追加します
我々は、管理サーバに春のセキュリティのためのサポートを追加することにより、ログイン認証機能性を得ることができます。
管理者セキュリティ・サーバ・モジュールを作成します。
- pom.xmlにその依存関係を追加します。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
复制代码
- application.ymlに構成では、情報の管理・セキュリティ・サーバーを監視無視し、ログインユーザー名とパスワードを設定します。
spring:
application:
name: admin-security-server
security: # 配置登录用户名和密码
user:
name: macro
password: 123456
boot: # 不显示admin-security-server的监控信息
admin:
discovery:
ignored-services: ${spring.application.name}
server:
port: 9301
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8001/eureka/
复制代码
- SpringSecurityのためにあなたが管理者・クライアントを登録することができるように構成すること:
/**
* Created by macro on 2019/9/30.
*/
@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath;
public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");
http.authorizeRequests()
//1.配置所有静态资源和登录页可以公开访问
.antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login").permitAll()
.anyRequest().authenticated()
.and()
//2.配置登录和登出路径
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
//3.开启http basic支持,admin-client注册时需要使用
.httpBasic().and()
.csrf()
//4.开启基于cookie的csrf保护
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
//5.忽略这些路径的csrf保护以便admin-client注册
.ignoringAntMatchers(
adminContextPath + "/instances",
adminContextPath + "/actuator/**"
);
}
}
复制代码
- 起動クラス、オープンAdminServerの発見と登録を変更します。
@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class AdminSecurityServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminSecurityServerApplication.class, args);
}
}
复制代码
- 開始ユーレカ・サーバー、管理・セキュリティにサーバー、 春ブーツ管理者ログインが見つかったホームページにアクセスするために必要なアクセス:HTTP:// localhostを:9301
モジュールを使用するには
springcloud-learning
├── eureka-server -- eureka注册中心
├── admin-server -- admin监控中心服务
├── admin-client -- admin监控中心监控的应用服务
└── admin-security-server -- 带登录认证的admin监控中心服务
复制代码
プロジェクトのソースアドレス
いいえ公共ありません
モールプロジェクトは、完全なチュートリアルがで連載国民の関心番号取得する最初の時間を。