我在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`
我想在Eureka发现注册表中注册此Kibana应用程序
这样我就可以使用API-gateway
来调用它以下示例是我在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-gateway是一个spring-boot应用程序,所以它很简单。
我正在使用docker(Image)运行kibana。我怎样才能实现这个目标
任何帮助都会很明显。
提前致谢
答案 0 :(得分:0)
在Eureka中注册Java应用程序并不是什么大问题,因为当使用spring-cloud-starter-netflix-eureka-client
依赖项时,Netflix提供了Java Eureka客户端,该客户端包含在您的类路径中。然后,Spring Boot将从您的应用程序属性中配置此客户端。
从应用程序代码外部注册和应用程序是不同的情况。您当然仍然可以这样做。
我将在这里仅提及一些理论,然后提出建议的解决方案。
执行此操作的基本方法是使用Eureka REST operations。这是一个API,您可以在其中手动注册/注销服务实例,并为Eureka提供常规的心跳信号,以考虑该服务实例可用。
这实际上不是一个很大的API,并且根据您目前对Eureka客户端配置的了解,您可能会很轻松。
Spring Cloud已经涵盖了您的用例!这里的方法是,您将为边车kibana创建一个配套容器。并且该容器中的应用程序将负责向Euerka注册您的服务。这种类型的应用程序很小,可以很快地用Java和Spring Cloud实施。
以下是Spring Cloud的文档:Polyglot support with Sidecar
这里是一个教程:Spring Cloud Netflix Sidecar Tutorial
这是一个以非常简单的方式执行此操作的存储库: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);
}
}
此配置:
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/}
还有一个非常简单的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/}
您还可以在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