springcloud 学习笔记(一) 之服务治理模块Spring Cloud Eureka

关于springboot的学习请参考前面的文章

接下来我们会开启一系列关于springcloud的学习文章。

一、概念

    首先我们看下官方的解释

Service Discovery is one of the key tenets of a microservice-based architecture. Trying to hand-configure each client or some form of convention can be difficult to do and can be brittle. Eureka is the Netflix Service Discovery Server and Client. The server can be configured and deployed to be highly available, with each server replicating state about the registered services to the others.

服务发现是基于微服务架构的关键原则之一。 尝试手动配置每个客户端或某种形式的约定可能很难做到,并且可能很脆弱。 Eureka是Netflix服务发现服务器和客户端。 服务器可以配置和部署为高可用性,每台服务器将注册服务的状态复制到其他服务器。

    Spring Cloud Eureka,Eureka是个什么呢,他主要是用来做服务治理的,我们知道,如果系统的服务少的情况下,通过静态配置就行了。如果服务数量特别多,静态配置如果修改维护起来就相当麻烦,Eureka就是解决这个事儿的。

二.首先从spring官网,下载一个关于springboot的项目

    1.访问 https://start.spring.io/

    2.按照截图中的内容进行操作

        

       3.将工程下载下来后,导入到idea,idea会根据pom中的配置自动构建项目的依赖

二、在src/main/resources目录中的application.properties文件中填写一些配置

扫描二维码关注公众号,回复: 946481 查看本文章

       

server.port=1111
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka

        1.配置解释

            server.port : 服务器的ip

            eureka.instance.hostname : eureka的主机名

            eureka.client.register-with-eureka : 这个项目是注册中心,这个配置代表不向注册中心注册自己

            eureka.client.fetch-registry : 注册中心的职务就是维护服务示例,他不需要去检索服务。所以设置成false

三、在  com/myspringboot/eurekaserver 包下的 EurekaServerApplication 上面加入

        @EnableEurekaServer ,代表启用eureka服务

       

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {

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

 四、启动项目,访问  http://localhost:1111/         ,我们看到这个界面,就等于配置成功了

    

猜你喜欢

转载自my.oschina.net/u/1178126/blog/1815493