2019-07-15

Springcloud分布式的简介与学习(一):


1,先来看看官网对spring cloud的定义:

Spring Cloud offers a simple and accessible programming model to the most common distributed system patterns, helping developers build resilient, reliable, and coordinated applications.

2,再来看看整个spring cloud的architecture 


2019-07-15_第1张图片
可以看出spring cloud的意义在于推出了一个基于spring的全链路方案,包括gateway,tracing,microservices,configCenter,service registry等等,中小型公司在基于spring cloud和springBoot的基础上进行搭建系统的话,只要稍作定制化便能很快的搭建起一个能支撑一定量qps和数据的系统 

3,基于Spring Cloud搭建分布式配置中心

(1)首先简单浏览一下我们要搭建的config center的architecture: 


2019-07-15_第2张图片
1.git repository作为配置的存储地 2.Config Server设置两台作为高可用 3.eureka server设置两台注册中心作为高可用 4.config client作为客户端获取配置

(2)下面看看关键代码:

1.配置eureka注册中心:

1,pom.xml:

4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE com.example demo_eureka 0.0.1-SNAPSHOT demo_eureka Demo project for Spring Boot 1.8 Greenwich.SR1 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-security org.springframework.cloud spring-cloud-starter-netflix-eureka-server org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import org.springframework.boot spring-boot-maven-plugin

2,application.yml:

server:

  port: 8888

spring: application:

name: eurka-server security: user: name: admin password: 123456eureka: client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@127.0.0.1:${server.port}/eureka/

3,DemoEurekaApplication启动器

package com.example.demo_eureka;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

import org.springframework.security.config.annotation.web.builders.HttpSecurity;

import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;

import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@SpringBootApplication

@EnableEurekaServer

public class DemoEurekaApplication {

    public static void main(String[] args) {

        SpringApplication.run(DemoEurekaApplication.class, args);

    }

    @EnableWebSecurity

    public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {

        @Override

        protected void configure(HttpSecurity http) throws Exception {

            http.csrf().disable();

            super.configure(http);

        }

    }

}

4,访问截图:


2019-07-15_第3张图片
2019-07-15_第4张图片
搭建完毕

你可能感兴趣的:(2019-07-15)