springcolud 的学习(四)服务治理. Eureka

什么是服务治理
在传统rpc远程调用中,服务与服务依赖关系,管理比较复杂,因此须要使用服务治理,管理服务与服务之间依赖关系,能够实现服务调用、负载均衡、容错等,实现服务发现与注册。
服务注册与发现
在服务注册与发现中,有一个注册中心,当服务器启动的时候,会把当前本身服务器的信息 好比 服务地址通信地址等以别名方式注册到注册中心上。
另外一方(消费者|服务提供者),以该别名的方式去注册中心上获取到实际的服务通信地址,让后在实现本地rpc调用远程。
搭建注册中心
经常使用注册中心框架
注册中心环境搭建
Maven依赖信息 spring

 

<parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>2.0.1.RELEASE</version>
     </parent>
     <!-- 管理依赖 -->
     <dependencyManagement>
          <dependencies>
               <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>Finchley.M7</version>
                    <type>pom</type>
                    <scope>import</scope>
               </dependency>
          </dependencies>
     </dependencyManagement>
     <dependencies>
          <!--SpringCloud eureka-server -->
          <dependency>
               <groupId>org.springframework.cloud</groupId>
               <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
          </dependency>
     </dependencies>
     <!-- 注意: 这里必需要添加, 否者各类依赖有问题 -->
     <repositories>
          <repository>
               <id>spring-milestones</id>
               <name>Spring Milestones</name>
               <url>https://repo.spring.io/libs-milestone</url>
               <snapshots>
                    <enabled>false</enabled>
               </snapshots>
          </repository>
     </repositories>
 

application.yml服务器

###服务端口号
server:
port: 8100
###eureka 基本信息配置
eureka:
instance:
###注册到eurekaip地址
hostname: 127.0.0.1
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
###由于本身是为注册中心,不须要本身注册本身
register-with-eureka: false
###由于本身是为注册中心,不须要检索服务
fetch-registry: falseapp

 
启动Eureka服务

@EnableEurekaServer
@SpringBootApplication
public class AppEureka {

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

}负载均衡

 

@EnableEurekaServer做用:开启eurekaServer框架

 

相关文章
相关标签/搜索