zoukankan      html  css  js  c++  java
  • spring cloud: eureka搭建

    1. 添加pom 依赖:

       

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
    </parent>

    <dependencies>
    <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>


    <!-- 加密解密jar begin -->
    <dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot</artifactId>
    <version>1.14</version>
    </dependency>
    <dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>1.14</version>
    </dependency>
    <!-- 加密解密jar end -->
    </dependencies>

    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>Camden.SR7</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>

    </dependencies>
    </dependencyManagement>
    </project>

    2. 写启动类

    @SpringBootApplication
    @EnableEurekaServer
    public class EurekaApplication {

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

    3. 配置:

    server:
    port: 8759
    security:
    user:
    name: admin
    password: ENC(8tNuxZqCsf0G0sxRS+cc6g==)
    basic:
    enabled: true
    jasypt:
    encryptor:
    password: wp3Lcomaohuidongl4ym8ofoYAYA==
    eureka:
    instance:
    hostname: test
    server:
    #enable-self-preservation: false
    client:
    register-with-eureka: false
    fetch-registry: false
    serviceUrl:
    defaultZone: http://localhost:${server.port}/eureka

    4. 加密解密main

    public class SecretMain {
    private static final Logger LOG = LoggerFactory.getLogger(SecretMain.class);


    public static void main(String[] args) {

    //第一种方式加�? admin
    BasicTextEncryptor text1= new BasicTextEncryptor();
    text1.setPassword("wp3Lcomaohuidongl4ym8ofoYAYA==");
    String newPassword = text1.encrypt("admin");
    LOG.info("newPassword={}",newPassword);

    // //第一种方式解�? admin
    // BasicTextEncryptor text2 = new BasicTextEncryptor();
    // text2.setPassword("wp3Lcomaohuidongl4ym8ofoYAYA==");
    // String oldPassword = text2.decrypt("MrmNu24HSDHHnNYMnosl2g==");
    // LOG.info("oldPassword={}",oldPassword);
    //
    // LOG.info("--------------------------------------------");
    // //第二种方式加密admin
    // StandardPBEStringEncryptor standard = new StandardPBEStringEncryptor();
    // standard.setPassword("wwwwp3Lcomaohuidongl4ym8ofoYAYAAA==");
    // String standardNewPassword = standard.encrypt("admin12");
    // LOG.info("standardNewPassword={}",standardNewPassword);
    //
    // //第二种方式解�?
    // StandardPBEStringEncryptor oldStandard = new StandardPBEStringEncryptor();
    // oldStandard.setPassword("wwwwp3Lcomaohuidongl4ym8ofoYAYAAA==");
    // String old = oldStandard.decrypt("+yKjbX67r7BrfFRdtePcrQ==");
    // LOG.info("old={}",old);
    }

    }

    5. 多注册中心的配置

    spring:
    profiles:
    active: eureka3
    security:
    user:
    name: ENC(3WnMCLtpRE7IkTDsvYIUjQ==)
    password: ENC(3WnMCLtpRE7IkTDsvYIUjQ==)
    jasypt:
    encryptor:
    password: wp3Lcomaohuidongl4ym8ofoYAYA==
    ---
    spring:
    application:
    name: ym-eureka-server
    profiles: eureka1
    server:
    port: 8761
    eureka:
    instance:
    hostname: ym-eureka-server1
    client:
    #registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
    defaultZone: http://admin:admin@ym-eureka-server2:8762/eureka/,http://admin:admin@ym-eureka-server3:8763/eureka/
    ---
    spring:
    application:
    name: ym-eureka-server
    profiles: eureka2
    server:
    port: 8762
    eureka:
    instance:
    hostname: ym-eureka-server2
    client:
    #registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
    defaultZone: http://admin:admin@ym-eureka-server1:8761/eureka/,http://admin:admin@ym-eureka-server3:8763/eureka/
    ---
    spring:
    application:
    name: ym-eureka-server
    profiles: eureka3
    server:
    port: 8763
    eureka:
    instance:
    hostname: ym-eureka-server3
    client:
    #registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
    defaultZone: http://admin:admin@ym-eureka-server1:8761/eureka/,http://admin:admin@ym-eureka-server2:8762/eureka/

  • 相关阅读:
    Super
    多态
    方法覆盖 和toString方法的作用
    Static 静态+this
    构造方法 + 继承
    使用方法重载的优缺点
    Erlang 简介与样例分析
    Assassin's Creed 4: Black Flag --《刺客信条4; 黑旗》
    DEVIL MAY CRY V:《鬼泣5》
    Valiant Hearts: The Great War -- 《勇敢的心》
  • 原文地址:https://www.cnblogs.com/maohuidong/p/9881022.html
Copyright © 2011-2022 走看看