从零开始搭建SpringCloud(一) 服务中心Eureka搭建

一、 序

  最近在开始学习微服务相关知识,主要学习的语言是Java,所以就以SpringcCloud作为切入点。Springcloud的优点这里就不说了,度娘上到处都是。SpringCloud是基于Springboot的,因此需要提前了解一下Springboot相关知识,但是基本的开发都与传统开发没有多大的差异,可以很快上手。

二、整体框架

    本次搭建主要包括以下几个模块:注册中心(Eureka)、ConfigServer、Zipkin、ribbon、feign、Zuul、Hystrix Turbine、Springboot Admin、Spring Cloud Bus等几个部分,后期跟进实际情况可能会添加其他的模块。

    由于 阿里云在搞活动,买了三个服务器,两个Ubuntu16.04,一个Centos7,部署的方案如下:

ubuntu1 ubuntu2 centos
ZipKin-Server Eureka Server service-turbine
Zuul ConfigServer ribbon
SpringBoot Admin service-1

三、常用测试地址

(1)http://IP:端口/hystrix/ 查看断路器界面

(2)http://Ip:端口/turbine.stream 监控流地址

(3)http://IP:端口/api-a/hi 网关访问方式

四、服务注册中心搭建

    目前SpringCloud支持多种服务注册中心,如Netflix Eureka、Consul、Zookeeper,但是在Spring Cloud服务治理抽象层的作用下,可以无缝地实现切换服务治理,并且不影响任何其他的模块功能实现。各种服务注册中心的区别网上已经很多,可以自行百度,这里我采用的是Eureka作为服务注册中心。配置如下:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

   Springboot版本使用的是 1.5.9.RELEASE,Springcloud版本使用的是Dalston.SR3。yml文件如下:

server:
     port: 8761

spring:
    application:
        name: eureka
eureka:
  instance:
    hostname: localhost
    lease-expiration-duration-in-seconds: 10
    lease-renewal-interval-in-seconds: 3
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
       defaultZone: http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}/eureka/
  server:
    enable-self-preservation: false
    eviction-interval-timer-in-ms: 3000
security:
  basic:
    enabled: true
  user:
    name: eureka
    password: 123

    在Application上加上@EnableEurekaServer,然后启动程序,在浏览器中输入localhost:8761,输入账号与密码即可打开主界面。账号和密码是security中的配置的,其他服务若要注册到中心必须加上账号密码即http:// s e c u r i t y . u s e r . n a m e : {security.user.password}@${eureka.instance.hostname}/eureka/

猜你喜欢

转载自blog.csdn.net/u013305783/article/details/80301152
今日推荐