2017-03-04 55 views
0

我正在微服務體系結構上使用Spring框架,並且我正在使用帶有自簽名證書的HTTPS(*.mydomainname.fr)。
作爲註冊表我使用尤里卡和作爲代理我使用Zuul。所以我的服務必須在名爲"service-name".mydomainname.fr的Eureka上註冊,因爲我的證書。此外,我暫時不使用DNS,我只是在/etc/hosts127.0.0.1 register.bec3.fr)中手動添加域名。 Here my micro service architecture.在Docker上的Eureka中獲得正確的域名

我想將我所有的服務都停泊在碼頭上。 我的碼頭工人,compose.yml是:

version: '3' 
services: 
    registration-service: 
     image: maven:alpine 
     container_name: register.bec3.fr 
     working_dir: /usr/src/spring-boot-app 
     volumes: 
     - ./scripts:/usr/src/spring-boot-app/scripts 
     - ./sslcert:/usr/src/spring-boot-app/ssl 
     - ./registration-service:/usr/src/spring-boot-app 
     - ./.m2:/root/.m2 
     expose: 
     - 8761 
     entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run" 
     #entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run" 
     ports: 
     - 8761:8761 
     networks: 
      back-net: 
      ipv4_address: 172.20.0.5 
      aliases: 
       - register.bec3.fr 
     depends_on: 
     - "maria" 

proxy-service: 
    image: maven:alpine 
    container_name: proxy.bec3.fr 
    working_dir: /usr/src/spring-boot-app 
    volumes: 
    - ./scripts:/usr/src/spring-boot-app/scripts 
    - ./sslcert:/usr/src/spring-boot-app/ssl 
    - ./proxy-service:/usr/src/spring-boot-app 
    - ./.m2:/root/.m2 
    expose: 
    - 8888 
    entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run" 
    #entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run" 
    ports: 
    - 8888:8888 
    networks: 
     back-net: 
     ipv4_address: 172.20.0.6 
     aliases: 
      - proxy.bec3.fr 
    depends_on: 
    - "registration-service" 

auth-service: 
    image: maven:alpine 
    container_name: auth.bec3.fr 
    working_dir: /usr/src/spring-boot-app 
    volumes: 
    - ./scripts:/usr/src/spring-boot-app/scripts 
    - ./sslcert:/usr/src/spring-boot-app/ssl 
    - ./auth-service:/usr/src/spring-boot-app 
    - ./.m2:/root/.m2 
    expose: 
    - 9999 
    entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run" 
    #entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run" 
    ports: 
    - 9999:9999 
    networks: 
     back-net: 
     ipv4_address: 172.20.0.7 
     aliases: 
      - auth.bec3.fr 
    depends_on: 
    - "maria" 
    - "registration-service" 

maria: 
    build: 
     context: ./ 
     dockerfile: maria-dev/Dockerfile 
    image: maria:latest 
    container_name: maria 
    environment: 
    - MYSQL_ROOT_PASSWORD=xxxxxx 
    networks: 
     back-net: 
     ipv4_address: 172.20.0.3 

networks: 
    back-net: 
    driver: bridge 
    ipam: 
    config: 
    - subnet: 172.20.0.0/24 

所以,我的服務可以註冊到我的註冊服務,因爲在我的application.propertise該參數:

eureka.client.service-url.defaultZone=https://register.bec3.fr:8761/eureka/ 

我的問題是,當我發起的服務有名字是我的尤里卡儀表盤泊塢窗ID:

  • 72959axxxxx:AUTH:9999
  • c0f1c4xxx XX:代理:8888

My eureka service

,我需要類似的東西:

  • auth.mydomainname.fr:auth:9999
  • proxy.mydomainname.fr:proxy:8888

由於我的證書。如果沒有,我不能用cURL達到我的服務:

curl -i -XPOST "https://web_app:@register.bec3.fr:8888/auth/oauth/token" -d "grant_type=password&username=toto&password=toto" --cacert my-cert.crt 

我該怎麼辦?我可以在Eureka中使用自定義主機名,還是應該更改Docker配置? 謝謝你的幫助。

回答

0

我有同樣的問題。這是爲了證明概念,所以我解決它的方式有點骯髒。

其實你在你的eureka儀表板上得到72959axxxxx:auth:9999,你需要auth.mydomainname.fr:auth:9999。

解決方案是在您的服務的docker中/ etc/hosts的頂部添加此服務的域名。試着用這個腳本來做:

#!/bin/bash 

HOSTS="/etc/hosts" 
TMP1="tmp1" 
TMP2="tmp2" 
IP="192.168.1.1" 
DN="domainenameservice" 

SERVICE="$IP\t$DN" 

echo -e $SERVICE > $TMP1 
cat $TMP1 $HOSTS > $TMP2 

echo "# test" > $HOSTS 
while IFS= read -r var 
do 
    echo "$var" >> $HOSTS 
done < $TMP2 
+0

謝謝:),它運行良好 –