Tuk*_*une 13 docker kibana microservices netflix-eureka docker-compose
我在Docker中使用Kibna.
我使用docker-compose运行Kibana
下面是我的docker-compose.yml
`version: '2'
services:
elasticsearch:
image: elasticsearch
expose:
- 9200
ports:
- "9200:9200"
networks:
- cloud
fluentd:
build: ./fluentd
volumes:
- ./fluentd/conf:/fluentd/etc
links:
- "elasticsearch"
ports:
- "24224:24224"
- "24224:24224/udp"
networks:
- cloud
kibana:
image: kibana
links:
- "elasticsearch"
ports:
- "9201:5601"
networks:
- cloud
networks:
cloud:
driver: bridge`
Run Code Online (Sandbox Code Playgroud)
我想在Eureka发现注册表上注册此Kibana应用程序
所以我可以使用API网关来调用它
以下示例是我在Eureka上注册My API-gateway的方式
eureka:
client:
serviceUrl:
defaultZone: http://eureka-server:8761/eureka/
registry-fetch-interval-seconds: 60
instance:
hostname: api-gateway
prefer-ip-address: false
lease-renewal-interval-in-seconds: 5000
lease-expiration-duration-in-seconds: 5000
API网关是一个spring-boot应用程序,所以它很简单.
我正在使用docker(图片)运行kibana.我怎样才能做到这一点
任何帮助都会很明显.
提前致谢
向 Eureka 注册 java 应用程序并不是什么大问题,因为 Netflix 提供了一个 java Eureka 客户端,在使用spring-cloud-starter-netflix-eureka-client依赖项时该客户端包含在您的类路径中。Spring Boot 将从您的应用程序属性中配置此客户端。
从应用程序代码之外注册和应用是不同的情况。您当然仍然可以这样做。
我在这里只提一点理论,然后给出建议的解决方案。
执行此操作的基本方法是使用Eureka REST 操作。这是一个 API,您可以在其中手动注册/取消注册服务实例,并为 Eureka 提供定期检测信号以考虑服务实例可用。
它实际上不是一个非常大的 API,根据您目前对 Eureka 客户端配置的了解,您可能会很轻松。
Spring Cloud 已经涵盖了您的用例!这里的方法是,您将为 kibana(一个 sidecar)创建一个伴随容器。这个容器中的应用程序将负责将您的服务注册到Euerka。这类应用程序很小,用Java和Spring Cloud实现很快。
以下是 Spring Cloud 的文档:Polyglot support with Sidecar
这是一个关于它的教程:Spring Cloud Netflix Sidecar 教程
这是一个以非常简单的方式执行此操作的存储库:Spring-Cloud-Sidecar_Tutorial
sidecar 应用程序中几乎没有代码,只有这个应用程序类(取自上面的存储库):
package com.craftcodecrew.lumen.service.sidecar;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.sidecar.EnableSidecar;
@SpringBootApplication
@EnableSidecar
public class LumenServiceSidecarApplication {
public static void main(String[] args) {
SpringApplication.run(LumenServiceSidecarApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
这个配置:
server:
port: 5678
spring:
application:
name: lumen-service
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
sidecar:
port: ${SIDECAR_PORT:8000}
health-uri: ${SIDECAR_HEALTH_URI:http://localhost:8000/health}
home-page-uri: ${SIDECAR_HOMEPAGE_URI:http://localhost:8000/}
Run Code Online (Sandbox Code Playgroud)
还有一个非常简单的pom.xml。
如您所见,sidecar 库需要一些您需要指向 kibana 实例的配置。因此,它们需要位于同一网络上。并且与 Eureka 位于同一网络上。
假设您的 kibana 容器名称为“kibana”,您的配置将如下所示:
server:
port: 5678
spring:
application:
name: kibana
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://eureka:8761/eureka}
instance:
preferIpAddress: true
sidecar:
port: ${SIDECAR_PORT:5601}
health-uri: ${SIDECAR_HEALTH_URI:http://kibana:5601/status}
home-page-uri: ${SIDECAR_HOMEPAGE_URI:http://kibana:5601/}
Run Code Online (Sandbox Code Playgroud)
您还可以控制 docker-compose 定义中配置的环境变量中的这些值。就像这样:
kibana-sidecar:
image: kibana-sidecar
links:
- "kibana"
ports:
- "5678:5678"
environment:
- EUREKA_URI=<your_eureka_instance_uri>
- SIDECAR_PORT=5601
- SIDECAR_HEALTH_URI=http://kibana:5601/status
- SIDECAR_HOMEPAGE_URI=http://kibana:5601/
networks:
- cloud
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
388 次 |
| 最近记录: |