生产环境中的微服务
Microservices are a specific kind of JHipster applications. Please refer to our main Using JHipster in production documentation for more information on doing a production build, optimizing it and securing it.
微服务监控
Please refer to our JHipster Registry documentation for learning which runtime dashboards are available, and how to use them.
Our monitoring documentation is also very important, to learn specific information on using:
- JHipster 控制台来使用 ELK;
- Zipkin 来创建 HTTP 服务请求追踪;
- 当有错误发生时,Elastalert 获取告警
When using the Docker-Compose sub-generator, you will be asked if you want to add monitoring to your infrastructure. This option will add the JHipster Console to your docker-compose.yml
file. Once started, it will be available on http://localhost:5601 and start to gather your applications’ logs and metrics.
For gateways and microservices applications, additional features are provided to help you effectively monitor a microservices cluster. For example logs are enriched with each application’s name, host, port and Eureka/Consul ServiceId so that you can trace from which service instance they are originating from. The JHipster Console also comes with default dashboards that give you an overview of all your services metrics.
使用 Docker Compose 来开发和部署
使用微服务架构意味着你将会有好几个不同的服务和数据库,这种场景下使用 Docker Compose 将会是一个管理你开发、测试、生成环境的强大工具。
在我们的 Docker Compose 说明文档 有一个章节介绍微服务,我们强烈推荐使用微服务架构的你能熟悉这个文档。
Docker Swarm,使用和 Docker Machine 一致的 API,使得在云平台内开发微服务架构就和在你本机上开发一样。查阅我们的 Docker Compose 说明文档 来了解更多关于 Docker Compose 和 JHipster。
Going to production with Cloud Foundry
The Cloud Foundry sub-generator works the same with a microservices architecture, the main difference is that you have more applications to deploy:
- Use the Cloud Foundry sub-generator to deploy first the JHipster Registry (which is a normal JHipster application).
- Note the URL on which your JHipster Registry is deployed. Your applications must all point to that URL:
- In the
bootstrap-prod.yml
file, thespring.cloud.config.uri
must point tohttp(s)://<your_jhipster_registry_url>/config/
- In the
application-prod.yml
file, theeureka.client.serviceUrl.defaultZone
must point tohttp(s)://<your_jhipster_registry_url>/eureka/
- In the
- Deploy your gateway(s) and microservices
- Scale your applications as usual with Cloud Foundry
One important point to remember is that the JHipster Registry isn’t secured by default, and that the microservices are not supposed to be accessible from the outside world, as users are supposed to use the gateway(s) to access your application.
Two solutions are available to solve this issue:
- Secure your Cloud Foundry using specific routes.
- Keep everything public, but use HTTPS everywhere, and secure your JHipster Registry using Spring Security’s basic authentication support
使用 Heroku 生产环境
Heroku sub-generator works nearly the same with a microservices architecture, the main difference is that you have more applications to deploy:
Deploy a JHipster Registry directly with one click:
Please follow the Heroku sub-generator documentation in order to understand how to secure your JHipster Registry.
Note the URL on which your JHipster Registry is deployed. Your applications must all point to that URL in their application-prod.yml
file. Change that configuration to be:
eureka:
instance:
hostname: https://admin:[password]@[appname].herokuapp.com
prefer-ip-address: false
You can now deploy and scale the gateway(s) and microservices. The Heroku sub-generator will ask you a new question, to know the URL of your JHipster Registry: this will allow your applications to fetch their configuration on the Spring Cloud Config server.