中文字幕精品亚洲无线码二区,国产黄a三级三级三级看三级,亚洲七七久久桃花影院,丰满少妇被猛烈进入,国产小视频在线观看网站

springcloud~Eureka實例(li)搭建

服務端

build.gradle配置

dependencies {
	compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
	testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

bootstrap.yml相關配置

server.port: 8761
management.port: 8762

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: //localhost:8761/eureka/

啟動代碼

package lind.sprindemo.eurekaServer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@EnableDiscoveryClient
@SpringBootApplication
public class EurekaServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(EurekaServerApplication.class, args);
	}
}

客戶端

向(xiang)我們配置(zhi)中(zhong)心的客戶端(duan)同時(shi)也是eureka的一(yi)個(ge)客戶端(duan),例如一(yi)個(ge)訂單(dan)服務,它的配置(zhi)存儲在(zai)配置(zhi)中(zhong)心,它如果希望公開自己,就需要是eureka的一(yi)個(ge)客戶端(duan)。

例子

graph TD A[訂單服務]-->B(注冊) B-->C(eureka) A-->D(獲取配置) D-->E(clientserver)

高可用的eureka集群

主要是在eureka里注冊另一(yi)個eureka,兩(liang)個eureka實(shi)例相互注冊,實(shi)現一(yi)個最高用的集群(qun)。

同(tong)一時刻,只有一個(ge)eureka里(li)有服(fu)務(wu),而當這個(ge)eureka掛了(le)之后,會把服(fu)務(wu)自動同(tong)步到另一個(ge)節點上,這就是(shi)高可(ke)用。

  1. 配置代碼
server:
  port: ${PORT:8761}
management:
  port: ${BG_PORT:8762}
application:
  name: ${NAME:eurekaserver}
spring:
  profiles:
    active: dev
---
eureka:
  profile: dev
  instance:
    hostname: ${application.name}
    perferIpAddress: true #基于IP地址注冊
  client:
    registerWithEureka: false #false表示不向注冊中心注冊自己。
    fetchRegistry: false #false表示自己端就是注冊中心,我的職責就是維護服務實例,并不需要去檢索服務
    serviceUrl:
      defaultZone: ${URL://${eureka.instance.hostname}:${server.port}/eureka/}

  1. Dockerfile內容

可以從(cong)遠程下載你的jar包(bao),如(ru)果你的網速(su)足夠好的話

FROM fabric8/java-jboss-openjdk8-jdk:1.4
ENV JAVA_APP_JAR="app.jar"
ENV JAVA_MAX_MEM_RATIO=40
ENV AB_OFF ""
ADD  --chown=jboss:jboss ./jar/eurekaServer-0.0.2.jar /deployments/app.jar
  1. docker-compose實現eureka集群
version: "3.3"
services:

  eurekaserver1:
    build: ./eureka-server
    restart: on-failure
    ports:
      - "6761:6761"
      - "6762:6762"
    networks:
      - dev
    environment:
      - PORT=6761
      - BG_PORT=6762
      - NAME=eureka1
      - URL=//eureka2:6761/eureka #集群地址配置

  eurekaserver2:
    build: ./eureka-server
    restart: on-failure
    ports:
      - "5761:5761"
      - "5762:5762"
    networks:
      - dev
    environment:
      - PORT=5761
      - BG_PORT=5762
      - NAME=eureka2
      - URL=//eureka1:6761/eureka #集群地址配置

運(yun)行docker-compose up -d 就會(hui)先構建eureka的鏡像,然后運(yun)行你(ni)的兩個(ge)eureka實例了(le)。

posted @ 2018-06-20 17:51  張占嶺  閱讀(1617)  評論(0)    收藏  舉報