一、新建工程
新建一個jansens-monitor工程項目,作為服務監控服務端。
二、添加依賴
在pom.xml添加spring boot 和spring boot admin依賴
pom.xml
<!-- spring boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!--spring-boot-admin--> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>2.0.4</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>2.0.4</version> </dependency>
三、添加配置
application.yml
server: port: 8000 spring: application: name: jansens-monitor
四、自定義Bannser
在resources目錄下添加一個自定義banner.txt文件
//////////////////////////////////////////////////////////////////// // _ooOoo_ // // o8888888o // // 88" . "88 // // (| ^_^ |) // // O\ = /O // // ____/`---'\____ // // .' \\| |// `. // // / \\||| : |||// \ // // / _||||| -:- |||||- \ // // | | \\\ - /// | | // // | \_| ''\---/'' | | // // \ .-\__ `-` ___/-. / // // ___`. .' /--.--\ `. . ___ // // ."" '< `.___\_<|>_/___.' >'"". // // | | : `- \`.;`\ _ /`;.`/ - ` : | | // // \ \ `-. \_ __\ /__ _/ .-` / / // // ========`-.____`-.___\_____/___.-`____.-'======== // // `=---=' // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // // 佛祖保佑 上海研發 永無BUG // ////////////////////////////////////////////////////////////////////
五、修改啟動類
JansensMonitorApplication.java
@EnableAdminServer @EnableDiscoveryClient @SpringBootApplication public class JansensMonitorApplication { public static void main(String[] args) { SpringApplication.run(JansensMonitorApplication.class, args); } }
六、啟動服務端
編譯啟動JansensMonitorApplication 訪問http://localhost:8000
七、監控客戶端
分別在jansens-admin和jansens-backup的pom文件中添加監控客戶端依賴
<!--spring-boot-admin-client--> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.0.4</version> </dependency>
application.yml
spring: boot: admin: client: url: "http://localhost:8000" # 開放健康檢查接口 management: endpoints: web: exposure: include: "*"
八、啟動客戶端
分別啟動jansens-monitor、jansens-admin、jansens-backup