zoukankan      html  css  js  c++  java
  • 微服务笔记(一) 搭建服务治理中心

    参考《SpringCloud 微服务和分布式系统实践》学习
    服务治理中心是微服务(分布式)架构中最基础和最核心的功能组件,它主要对各个服务实例进行管理,包括服务注册和服务发现等。

    搭建服务治理中心


    集成Eureka

    1. 首先新建一个module,并添加web和eureka依赖
    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            </dependency>
    
    1. 添加注解
    
    @SpringBootApplication
    //驱动服务治理中心
    @EnableEurekaServer
    public class EurekaApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaApplication.class, args);
        }
    
    
    1. 配置yml文件
    spring:
      application:
        name: eureka
    
    server:
      port: 8001
    
    eureka:
      client:
        # 取消注册自身,否则会一直报错
        register-with-eureka: false
        # 取消服务获取
        fetch-registry: false
        # 服务注册域地址
    #    service-url:
    #      defaultZone: http:192.168.1.100:8002/eureka
      instance:
        # 服务治理中心服务器IP
        hostname: 192.168.1.100
    
    
    
    1. 启动项目,打开localhost:8001

    2. 注意事项
      如果选择JDK 8(不含)以上的版本,可能会启动失败,这是因为SpringCloud的Netflix组件是依赖于JDK 8(含)之前的版本开发的,所以在新的JDK版本中会缺少一些包,因此我们需要引入新的依赖才能正常启动Eureka服务器,代码如下:

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>
    
  • 相关阅读:
    ajax收藏
    excel提取文本格式时分秒中数字的方法并计算成秒的公式
    vi编辑模式中按方向键变ABCD的解决方法
    IIS配置Url重写实现http自动跳转https的重定向方法
    IIS中启用目录浏览功能后不能下载未知扩展名文件的解决方法
    Nginx禁止IP访问,只允许域名访问
    nginx在Window平台http自动跳转https设置方法
    通过清理注册表方式清理window远程连接的历史记录
    DOS批处理添加IP域名,备份与恢复
    windows修改snmp端口号方法
  • 原文地址:https://www.cnblogs.com/charlottepl/p/15609632.html
Copyright © 2011-2022 走看看